Solved

CopyHere VBScript method working on Windows 2000, but not on XP...

Posted on 2003-11-30
5
3,218 Views
Last Modified: 2007-12-19
Hello,

I am trying to copy the contents of one folder to another using the following VBScript code:

set SA = CreateObject("Shell.Application")
set FolderObj = SA.NameSpace("C:\temp")
FolderObj.CopyHere "C:\HLCache\*.*" , 16+512

The thing is, in Windows 2000, this code works fine, the progress dialog appears and copies the files in the right place. I am running WSH 5.6 on that system. But in Windows XP, I receive this error message:

C:\DOCUME~1\Robert\LOCALS~1\Temp\~shlcpy.vbs(3, 1) Microsoft VBScript runtime er
ror: Object required: 'FolderObj'

I am also running WSH 5.6 on Windows XP. The same message appears for other Windows XP machines I have too. I need to use the CopyHere method as this is the only way I can have a progress indicator. But why would it work on Windows 2000 and not in XP?

Please can someone help me!
0
Comment
Question by:Crusher07
5 Comments
 
LVL 5

Expert Comment

by:sanjaykashyap19
ID: 9847249
try with FileSystemObject

Set FSO = CreateObject("Scripting.FileSystemObject")
set Folderobj = FSO.GetFolder(LogFileDir)


for delete file sample code look http://www.iisfaq.com/default.aspx?View=A65&P=141


0
 

Author Comment

by:Crusher07
ID: 9847263
Yes, but I need a progress dialog box. I am copying over 500mb of data, so this is a necessity.
0
 
LVL 44

Accepted Solution

by:
bruintje earned 500 total points
ID: 9848560
Title : Windows XP Shell.Application CopyHere bug
Source : http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=9uq81c%24gt3%241%40lust.ihug.co.nz

Description :
-----------

The object is a Folder it copies a folder
To copy files (inc *.*) you need to specify a object items

' script to demo shell.application (for IE4/5 in win98)

Option Explicit
Dim oSHApp, oSHFolder ' as object
Dim sSrc, sDest ' as string
Set oSHApp = CreateObject("Shell.Application")

sSrc = "C:\Scripts"
sDest = "C:\Temp\"

'If sSrc is a folder whose contents you want to copy
Set oSHFolder = oSHApp.Namespace(sSrc)
oSHApp.Namespace(sDest).CopyHere oSHFolder.Items

'If sSrc is one File or whole Folderyou want to place inside sDest
'oSHApp.Namespace(sDest).CopyHere sSrc, &H100

Set oSHFolder = Nothing
Set oSHApp = Nothing
WScript.Quit

-----------

from the rest of that google thread and several others it looks like a bug, copyfolder seems to work or without asteriks the method should work too

hope this helps a bit
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9849897
You could add your own progress indicator with the Copy or CopyFile methods however it wont look as neat as the one windows pops up for you. It will simply send a bunch of "." to the console to let you know that it is still in progress, however there wont be any indication of how far it has gone or how much is has left to do.  If this ounds like something you want to do let me know and I'll post the code.
0
 

Author Comment

by:Crusher07
ID: 9851207
Wow, this must one one of those oh-so-rare occasions where it is actually a bug!

Good work - The new code works great. I knew I couldn't have been the only one with this problem... lets just hope MS actually do something about it, i.e. fix it in SP2.

Thanks everyone for a speedy response.

Robert

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now