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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy and delete files on client machines (remotely!)

Status
Not open for further replies.

mparter

Programmer
Apr 21, 2003
5
GB
What I need to be able to do is run a script from a
machine connected to the domain which will iterate through
all the machines on the domain and delete a file on the C
drive. I also need to be able to copy a file at the same
time to the same location.

I will be runing the script as a domain administrator so
permissions aren't a problem. I have run a command line
before to copy the original file to the domain clients
but when I modified it to delete instead of copy it
deleted all the files in the C root!
 
 
You could have a list of computer names in a db or text file then when the script runs it simply pulls it out then runs 2 shell commands like:

dim hold
Set WshShell = WScript.CreateObject("WScript.Shell")
Hold = "net use z: \\" & machine name & "\c$"
wshshell.run Hold

hold = "c:\script\candd.bat"
wshshell.run Hold
wscript.sleep 10000

The bat file will be setup to delete and copy to file to Z drive and then disconnect the drive.

Z:
cd\winnt
del bob.txt
copy c:\script\newbob.txt z:\winnt\bob.txt
c:
net use z: /delete

 
This part:

Code:
dim Hold
Set WshShell = WScript.CreateObject("WScript.Shell")
Hold = "net use z: \\" & machine name & "\c$"
wshshell.run Hold

won't work on Win9X machines.

if you want it to work on Win9X machines, it gets a bit tougher.

If just WinNT family, its ok.
 
Thanks for the replies guys. I solved my problem using the following steps;

Obtain a list of all machines on the domain using the following at a command prompt:

Code:
net view /domain:INTRANET > c:\machines.txt

I then used this to delete the file in question on each machine found using the following command line:

Code:
FOR /F " tokens=1 " %i in (machines.txt) do del "%i\C$\script.vbs"

I then used a similar command to copy an new file to the same location:

Code:
FOR /F " tokens=1 " %i in (machines.txt) do copy new_script.vbs "%i\C$\"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top