• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Scripting Question

Slap

Golden Member
Since I am clueless when it comes to writing scripts, can someone help? I need a script that will copy a file from my local c:\ drive out to several computers on the network. For example, I would need it to copy c:\file.txt to \\computername\c$\folder1\folder2 on multiple computers.

 
copy c:\file.txt \\computer1\c$\folder1\folder2
copy c:\file.txt \\computer2\c$\folder1\folder2
copy c:\file.txt \\computer3\c$\folder1\folder2
..
repeat
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
For intA = 0 to 2
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit

save it as a .vbs
 
Originally posted by: FoBoT
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
For intA = 0 to 2
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit

save it as a .vbs

I get a error when running the script. It is at line 7 char 1 and states permission denied.
 
that isn't a script error, you need to have permissions (ie be using the same account with the same credentials on all Pc's) to perform the action
 
Originally posted by: FoBoT
that isn't a script error, you need to have permissions (ie be using the same account with the same credentials on all Pc's) to perform the action

I have admin access to all pc's on the network. I can access each one by simply going to \\computername\c$
 
Originally posted by: Slap
Originally posted by: FoBoT
that isn't a script error, you need to have permissions (ie be using the same account with the same credentials on all Pc's) to perform the action

I have admin access to all pc's on the network. I can access each one by simply going to \\computername\c$

Are you on a domain or just normal workgroup type stuff?
 
Originally posted by: five40
Originally posted by: Slap
Originally posted by: FoBoT
that isn't a script error, you need to have permissions (ie be using the same account with the same credentials on all Pc's) to perform the action

I have admin access to all pc's on the network. I can access each one by simply going to \\computername\c$

Are you on a domain or just normal workgroup type stuff?

A domain.
 
i got some lines mixed up 😱 but that probably isn't the permission issue

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
For intA = 0 to 2
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit
 
Originally posted by: Slap
Originally posted by: five40
Originally posted by: Slap
Originally posted by: FoBoT
that isn't a script error, you need to have permissions (ie be using the same account with the same credentials on all Pc's) to perform the action

I have admin access to all pc's on the network. I can access each one by simply going to \\computername\c$

Are you on a domain or just normal workgroup type stuff?

A domain.

That's going to be your problem because I'm assuming you are the domain admin but your actual login is not a login for each machine. You have a domain account that lets you login to each machine but you don't have an account on each machine. In order for that .vbs to work you are going to have to have a actual account on the machine you want to copy to. The .vbs does not use your domain credentials.
 
Originally posted by: Slap
I know you like being a smartass, but just looking at the list on the left side I didn't see programming only software and apps. I stated above that I guess I couldn't find it.
You being too lazy to familiarize yourself with a forum you joined five and a half years ago makes him a smartass? 😕
 
Originally posted by: FoBoT
i got some lines mixed up 😱 but that probably isn't the permission issue

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
For intA = 0 to Ubound(strComputers)
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit

Fixed for ease of future use for more than three computers.
 
Originally posted by: Kyteland
Originally posted by: Slap
I know you like being a smartass, but just looking at the list on the left side I didn't see programming only software and apps. I stated above that I guess I couldn't find it.
You being too lazy to familiarize yourself with a forum you joined five and a half years ago makes him a smartass? 😕

Sure it does. If you look at my post count, you will see I am not here posting day in and day out like he is. I admittied that I didn't see it and he states "it's the one with programming in the title". That is being a smart ass.
 
Originally posted by: five40
Originally posted by: FoBoT
i got some lines mixed up 😱 but that probably isn't the permission issue

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
For intA = 0 to Ubound(strComputers)
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit

Fixed for ease of future use for more than three computers.

I am still getting the permission error for some reason. Like i said i can get to these remote dir using \\compname\c$.
 
Originally posted by: Slap
Originally posted by: five40
Originally posted by: FoBoT
i got some lines mixed up 😱 but that probably isn't the permission issue

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strComputers
strComputers = Array("computer1","computer2","computer3")
strlocalPath = "c:\file.txt"
For intA = 0 to Ubound(strComputers)
strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"
objFSO.CopyFile strlocalPath, strremotePath
Next
WScript.Echo "Ding! Flies are gone!"
WScript.Quit

Fixed for ease of future use for more than three computers.

I am still getting the permission error for some reason. Like i said i can get to these remote dir using \\compname\c$.

Read my post above about your account permissions.

Here it is in case you missed it:
That's going to be your problem because I'm assuming you are the domain admin but your actual login is not a login for each machine. You have a domain account that lets you login to each machine but you don't have an account on each machine. In order for that .vbs to work you are going to have to have a actual account on the machine you want to copy to. The .vbs does not use your domain credentials.
 
i do scripting in a workgroup environment where all the pc's have common local admin accounts, so that is what i am used to. so it works for me. i dunno how to do it when you have to deal with domain stuff
 
Is there a way to make the script use a specific account? Each machine has a standard local admin account, but I am not logged in under that account. Will I need to log into my pc under the standard local admin account?
 
Originally posted by: Slap
Is there a way to make the script use a specific account? Each machine has a standard local admin account, but I am not logged in under that account. Will I need to log into my pc under the standard local admin account?

That would work.
 
If you are just running the script by double-clicking it, then it WILL use your domain login account. There is another issue if this doesn't work... I do this all the time here and it works just fine.

I never tested this particular script (too lazy) so maybe there is something wrong with the script... although it looks okay.
 
Just tried the script... you need a \ at the end of the path.

strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2"

SHOULD BE

strremotePath = "\\" & strComputers(intA) & "\c$\folder1\folder2\"
 
If you are using AD, no need to set up an array with all of your machine names - which would be a real PITA to maintain IMHO. There is a very good book on scripting for admins that I picked up a couple of years ago. I haven't checked to see if it has been updated for Server 2003 yet, but I have found it to be an excellent reference for some of the tasks I have automated.

link

 
Back
Top