Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot copy using Scripting.FileSystemObject on Windows Server 2003

Posted on 2007-03-23
9
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 800 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
 
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 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

661 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