Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Using variables to copy files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2622
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using variables to copy files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Using variables to copy files - 4/8/2005 5:09:46 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
Folks,
I'm trying to run a remote copy of files using variables. The remote location is "c:\smsremove". Is my syntax correct?


'On error resume next

Dim Fso, Folder, Client, Dest, smsRemove

Set Fso = WScript.CreateObject("Scripting.FileSystemObject")

'Input Box allowing user to input client machine
Client = InputBox ("Enter a clients name requiring SMS maintenance")

smsRemove = smsRemove

Dest = "c:\"

If Fso.folderexists(""\\" + client + "\" + Dest + smsremove") then

Set Folder = Fso.getfolder(""\\" + client + "\" + Dest + smsremove")

else

Fso.CreateFolder(""\\" + client + "\" + Dest + smsremove")

Set Folder = fso.getfolder(""\\" + client + "\" + Dest + smsremove")

end if
 
 
Post #: 1
 
 Re: Using variables to copy files - 4/8/2005 5:18:30 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
change all the + to &.

Dest = "c:\smsremove" is easier


      

and im not sure if you can do fso stuff using UNCs. i assume you can though if the permissions are correct.

(in reply to holtitan)
 
 
Post #: 2
 
 Re: Using variables to copy files - 4/8/2005 5:25:50 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Would need a little bit more info first, but from what I can see, I would say no, it isn't. First, what do you anticipate getting from the inputbox? Second, you have extra " that are not needed, for instance, on each line you start with (""\\"..., you only need 1 set of " i.e. ("\\"... and you do not need the ending quote. Now to get the line encapsultated in quotes you can do a couple things, what I normally do is this, ("""" & "\\" & ..... & """") Third, from what I see, if the user typed in a server name, your check folder would not work. If you do a msgbox on any of the lines above this is what you would get.

msgbox "\\" + client + "\" + Dest + smsremove would return;

\\CLIENTINPUT\c:\SMSREMOVE to get to the remote PC, you would need C: to become C$

(in reply to holtitan)
 
 
Post #: 3
 
 Re: Using variables to copy files - 4/8/2005 5:28:24 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
I made the changes and am now getting a "path not found". Maybe UNC's are not supported in this context.

'On error resume next

Dim Fso, Folder, Message2, Client, Dest, smsRemove

Set Fso = WScript.CreateObject("Scripting.FileSystemObject")

'Input Box allowing user to input client machine
Client = InputBox ("Enter a clients name requiring SMS maintenance")

smsRemove = smsRemove

Dest = "c:\smsremove"

If Fso.FolderExists("\\" & client & "\" & Dest) then

Set Folder = Fso.getfolder("\\" & client & "\" & Dest)

else

Fso.CreateFolder("\\" & client & "\" & Dest)

Set Folder = fso.getfolder("\\" & client & "\" & Dest)

end if

'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\hammer.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\kill.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\setevnt.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\20clicln.bat", "c:\smsremove\"

(in reply to holtitan)
 
 
Post #: 4
 
 Re: Using variables to copy files - 4/8/2005 5:36:32 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
That worked for the folder created. I type UNC's all day from the run command. THe "C$" share should have clicked. My bad. Anyway, could I just stick the folder variable on the file copy to copy those four files to the remote machines?

'On error resume next

Dim Fso, Folder, Message2, Client, Dest, smsRemove

Set Fso = WScript.CreateObject("Scripting.FileSystemObject")

'Input Box allowing user to input client machine
Client = InputBox ("Enter a clients name requiring SMS maintenance")

smsRemove = smsRemove

Dest = "c$\smsremove"

If Fso.FolderExists("\\" & client & "\" & Dest) then

Set Folder = Fso.getfolder("\\" & client & "\" & Dest)

else

Fso.CreateFolder("\\" & client & "\" & Dest)

Set Folder = fso.getfolder("\\" & client & "\" & Dest)

end if

'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\hammer.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\kill.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\setevnt.exe", "c:\smsremove\"
'fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\20clicln.bat", "c:\smsremove\"

(in reply to holtitan)
 
 
Post #: 5
 
 Re: Using variables to copy files - 4/8/2005 6:09:35 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
I made some edits and added comments in the code.

      

(in reply to holtitan)
 
 
Post #: 6
 
 Re: Using variables to copy files - 4/8/2005 6:19:42 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Replace:

Dest = "c$\smsremove"

with:

Dest = "c$\smsremove\"

and the following 4 lines of code should work.

fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\hammer.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\kill.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\setevnt.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\20clicln.bat", "\\" & client & "\" & Dest

(in reply to holtitan)
 
 
Post #: 7
 
 Re: Using variables to copy files - 4/8/2005 6:31:40 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
You guys rock. Works like a champ. Sorry for the ignorance. Thanks for the help. :-)

(in reply to holtitan)
 
 
Post #: 8
 
 Re: Using variables to copy files - 4/8/2005 6:34:28 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
No problem =)

(in reply to holtitan)
 
 
Post #: 9
 
 Re: Using variables to copy files - 4/8/2005 6:46:22 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Glad to help

(in reply to holtitan)
 
 
Post #: 10
 
 Re: Using variables to copy files - 4/8/2005 7:51:10 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
One more question. Everything is working up to the point where I'm trying to remotely execute a script called "ExecuteProgram.vbs" (This executes the 20clicln.bat to remove sms agent from a computer). When it gets to that point in the script I get a permission denied. Any clues??

'On error resume next

Dim Fso, Folder, File, Client, Dest, smsRemove, wshobject, Controller, RemoteScript

set wshobject=wscript.createobject("wscript.shell")
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Set Controller = WScript.CreateObject("WSHController")


'Input Box allowing user to input client machine
Client = InputBox ("Enter a clients name requiring SMS maintenance")

smsRemove = smsRemove

Dest = "c$\smsremove\"

If Fso.FolderExists("\\" & client & "\" & Dest) then

Set Folder = Fso.getfolder("\\" & client & "\" & Dest)

else

Fso.CreateFolder("\\" & client & "\" & Dest)

Set Folder = fso.getfolder("\\" & client & "\" & Dest)

end if

fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\hammer.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\kill.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\setevnt.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\20clicln.bat", "\\" & client & "\" & Dest



Set RemoteScript = Controller.CreateScript("ExecuteProgram.vbs", client)

RemoteScript.Execute

Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop

(in reply to holtitan)
 
 
Post #: 11
 
 Re: Using variables to copy files - 4/8/2005 8:20:35 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Can you post ExecuteProgram.vbs ?

(in reply to holtitan)
 
 
Post #: 12
 
 Re: Using variables to copy files - 4/8/2005 8:21:35 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
dim wshobject
set wshobject=wscript.createobject("wscript.shell")
wshobject.run ("C:\smsremove\20clicln.bat" /SCRUB)

(in reply to holtitan)
 
 
Post #: 13
 
 Re: Using variables to copy files - 4/8/2005 8:23:26 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I guess I should also ask for the exact error message and the at what line did the error occur ;)

(in reply to holtitan)
 
 
Post #: 14
 
 Re: Using variables to copy files - 4/8/2005 8:36:26 AM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
Staging.vbs
'On error resume next

Dim Fso, Folder, File, Client, Dest, smsRemove, wshobject, Controller, RemoteScript

set wshobject=wscript.createobject("wscript.shell")
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Set Controller = WScript.CreateObject("WSHController")


'Input Box allowing user to input client machine
Client = InputBox ("Enter a clients name requiring SMS maintenance")

smsRemove = smsRemove

Dest = "c$\smsremove\"

If Fso.FolderExists("\\" & client & "\" & Dest) then

Set Folder = Fso.getfolder("\\" & client & "\" & Dest)

else

Fso.CreateFolder("\\" & client & "\" & Dest)

Set Folder = fso.getfolder("\\" & client & "\" & Dest)

end if

fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\hammer.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\kill.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\setevnt.exe", "\\" & client & "\" & Dest
fso.Copyfile "\\shsms\smsrepo$\baseline\smsremove\20clicln.bat", "\\" & client & "\" & Dest



Set RemoteScript = Controller.CreateScript("ExecuteProgram.vbs", client)

RemoteScript.Execute

Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop

Execute.vbs

dim wshobject
set wshobject=wscript.createobject("wscript.shell")
wshobject.run ("C:\smsremove\20clicln.bat" /SCRUB)


I got passed the permission problem. However, now I don't get any indication of an error but it doesn't appear that the "C:\smsremove\20clicln.bat" /SCRUB is executing on the remote machine. If you have time...

(in reply to holtitan)
 
 
Post #: 15
 
 Re: Using variables to copy files - 4/8/2005 9:31:36 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Is it ExecuteProgram.vbs or Execute.vbs ?

(in reply to holtitan)
 
 
Post #: 16
 
 Re: Using variables to copy files - 4/8/2005 1:04:53 PM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
ExecuteProgram.vbs

(in reply to holtitan)
 
 
Post #: 17
 
 Re: Using variables to copy files - 4/8/2005 2:08:23 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Are you able to see a window pops up if you put something like msgbox() above the wshobject.run line ?

(in reply to holtitan)
 
 
Post #: 18
 
 Re: Using variables to copy files - 4/8/2005 2:35:32 PM   
  holtitan

 

Posts: 26
Score: 0
Joined: 3/28/2005
From:
Status: offline
If I run the ExecuteProgram.vbs locally with the MsgBox ("test") added the box with "test" pops up and the program executes locally. When I do that remotely will the box pop up on the remote machine? By the way, I hope the folks that run this site are paying you for this. You seem to be the most active/accurate helper on this site. :-)

(in reply to holtitan)
 
 
Post #: 19
 
 Re: Using variables to copy files - 4/8/2005 4:24:54 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Is the target machine running XP with WSH 5.6 ? If so, you might want to try the following 2 steps.

1. Run this from DOS prompt on the source machine: wscript -regserver
2. Add the following registry entry to the target machine:
HKEY_LOCAL_ MACHINE\SOFTWARE\Microsoft\Windows Script Host\Settings
Key: Remote
Type: REG_SZ
Value: 1

(in reply to holtitan)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using variables to copy files Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts