Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy file from cd to local folder

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
I cant get this script to work...

I want to copy myfile.vbs from CD-Rom drive to Autostart in All users folder. i used a similar but it called cmd.exe to do the copy.

Code:
Dim value1, ws, strAstart, WSHshell
Set ws = WScript.CreateObject("WScript.Shell")

value1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\"

strAstart = ws.RegRead (value1 & "Common Startup")

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile ".\myfile.vbs" , " & Chr(34) & strAstart & Chr(34) & "\ , OverwriteExisting

This one works but i cant call for cmd in the enviroment that i'm using it, i have to convert it to vb only...

Code:
Call ws.Run("cmd.exe /c copy .\myfile.vbs " & Chr(34) & strAstart & Chr(34) & "\ /Y")


Pls help me!

 
by the way, i'm getting "Can't find the path specified" or "There is a dublicate name on the network, go to the control panel and change your computer name" It's only one comp on my test network and there is no conflict...
 
humm, found a solution to the prob...

Code:
Dim strAstart

Const ALL_USERS_STARTUP = &H18&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ALL_USERS_STARTUP)
Set objFolderItem = objFolder.Self

strAstart = objFolderItem.Path

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile ".\myfile.vbs" , strAstart&"\", OverwriteExisting
 
You might like to/need to also set the copied file(s) attributes to not be read-only. Something like:

Code:
Set objCopiedFile = objFSO.GetFile(strAstart&"\myfile.vbs")
objCopiedFile.Atributes = 0


[auto] The dumber they think you are, the more surprised they'll be when you kill them!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top