Solved

Cannot copy using Scripting.FileSystemObject on Windows Server 2003

Posted on 2007-03-23
9
283 Views
Last Modified: 2013-12-26
I have an app which works as it should in Windows XP pro but when i run it on a sever running Windows Server 2003, it does not work, nor does it give an error. The piece of code that does not work is as follows:

    Dim fso As Object

    Dim strFromFile As String
    Dim strToFile As String
    ...

'   strProcessPath is passed to function after it is tested as valid

'   Copy file to Dir
    strFromFile = Trim(App.Path) & "\SystemConfig.zip"
    strToFile = Trim(strProcessPath) & "\SystemConfig.zip"

    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile Trim(strFromFile), Trim(strToFile)
    Set fso = Nothing
'///////////////////////////////////////////////////////////////

Thanks for your help
0
Comment
Question by:Vincent_Monaghan
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:Louis01
ID: 18778059
What does
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
do?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18778716
What about using this method?

    Set fso = CreateObject("Scripting.FileSystemObject")
    set objFile=fso.GetFile(strFromFile)
    fso.Copy Trim(strToFile)
0
 

Author Comment

by:Vincent_Monaghan
ID: 18783744
Hi Louise01
    fso.CopyFile Trim(strFromFile), Trim(strToFile), True
This method is used to copy a file from source to destination, just like the DOS copy command.

A useful MS site is : http://support.microsoft.com/kb/q186118/

I have used it many times and it works well but for some reason it did not work running on the MS Windows Server 2003. I have since tried a different method, ie shell out to the CMD environment and run the DOS command copy
Check out on the MS KBase: HOWTO: 32-Bit App Can Determine When a Shelled Process Ends
                                              Q129796
Remember to use the the short names generated for files on NTFS and FAT volumes. for eg
c:\Program Files        -> C:\PROGRA~1

Hi sirbounty
I will give this a try, but it will be several days before I get to it. Thanks



0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 200 total points
ID: 18784168
...even your shelled copy will work with long names, as long as you place quotes on the outside of the paths...chr(34) is the character code...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:JohnBPrice
ID: 18792554
>>nor does it give an error
Do you have an "On Error resume next" or "on error goto xxxx" anywhere in the procedure or calling procedures that might be supressing an error?

Can you copy the file manually without errors?

Have you checked that strProcessPath is indeed set to what you believe it is?  Maybe it IS copying, but to an unexpected location.
0
 

Author Comment

by:Vincent_Monaghan
ID: 18799129

Hi  JohnBPrice

There is error trapping code in the procedure :

Dim fso As Object

    Dim strFromFile As String
    Dim strToFile As String
    ...


' Error trapping code
    Dim Err_Desc As String
    Dim Err_Source As String
    Dim Err_Msg As String

    On Local Error GoTo ErrorProcessRows



'   strProcessPath is passed to function after it is tested as valid

'   Copy file to Dir
    strFromFile = Trim(App.Path) & "\SystemConfig.zip"
    strToFile = Trim(strProcessPath) & "\SystemConfig.zip"

    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile Trim(strFromFile), Trim(strToFile)
    Set fso = Nothing


    ...

    Exit Sub

ErrorProcessRows:
    Err_Number = Err.Number
    Err_Desc = Err.Description
    Err_Source = Err.Source

    WriteAppLog ("Error Processing Rows; Err : " & str(Err_Number) & ";" & Err_Desc & "; Source :" & Err_Source)
End Sub


Public Function WriteAppLog(ByVal strLogText As String)
    Dim objFileSystem As Object
    Dim objFile As Object
    Dim strFilePath As String
    Dim msg As String
   
    On Error GoTo LogErr
   
    msg = Format(Date, "yyyy-mm-dd") & " " & Format(Time(), "hh:mm:ss") & ";" & Trim(strLogText) & vbCrLf
   
    strFilePath = gstrLogsPath
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFileSystem.OpenTextfile(strFilePath, 8, -1)
    objFile.Write msg
    objFile.Close
    Set objFile = Nothing
    Set objFileSystem = Nothing
    Exit Function
   
LogErr:
End Function

'///////////////////////////////////////////////////////////////
Sorry for repeating the same code as above again. I also include the writelog routine I use. Interestingly it uses the "Scripting.FileSystemObject", but it always works no problem

As to your other points. Yes I can copy manually. The same path works when I shell out and use the DOS copy command in  BATCH file :

copy /y %1 %2

Thanks for your comments


0
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 300 total points
ID: 18800454
With that code, if there is an error with the FileSystemObject, you will get the behavior you see.  The first error flips to ErrorProcessRows, which again tries to use FileSystemObject, and if it still has an error it flips to LogErr: which does nothing, e.g. an error with the FileSystemObject just terminates with no error reporting.

I presume there is nothing in your application log.

I'd try commenting out ALL the "On error" and run it again to see if that is the issue.
0
 

Author Comment

by:Vincent_Monaghan
ID: 18802008
Hi JohnBPrice

Well spotted. I'll stick a few msgboxes in to see what happens
0
 

Author Comment

by:Vincent_Monaghan
ID: 18868983
Thanks all fo your contributions. I have not had time to test the suggestions and give feedback, but wanted to award points before the question was deleted.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now