Solved

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

Posted on 2003-11-30
5
3,228 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

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 74
DO Loop not working 4 72
Protecting vb6 & .Net code Obfuscation 18 94
Can we place a tooltip on the actual vb6 form 5 35
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now