?
Solved

Running One Script on a List of PC's

Posted on 2009-04-20
5
Medium Priority
?
376 Views
Last Modified: 2013-11-10
Hello Experts,
I would like to know a way to run a batch file on multiple pc's. For instance, for a particular task I need to delete 4 files on a pc and then copy a new file to the pc. If I wrote a standard batch file then I could accomplish that task if I were at each pc. But, I cannot run that same batch file on other pc's. I could also edit the batch file to include each pc but then it would turn into a huge file. Is there a way to run a simple batch file on multiple pc's? I've attached the code at the bottom.
del "C:\Summit\CommonCode\~Cache~\*.*" /Q
 
del "C:\Summit\Spectrum for Windows\Programs\~Cache~\*.*" /Q
 
del "C:\Summit\Spectrum For Windows\Programs\AdvantageConfig.mdb"
 
del "C:\Summit\Spectrum For Windows\Programs\AdvantageConfigOld.mdb"
 
xcopy "P:\ONS\Lender Upgrade\AdvantageConfig.mdb" "C:\Summit\Spectrum For Windows\Programs\"

Open in new window

0
Comment
Question by:eddo9696
5 Comments
 

Expert Comment

by:Osrd
ID: 24182989
Hi,
first of all save the commands you want to run in a bat file.
Then download psexec.exe from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx, and create a vbs file like the one attached.
If you created a folder called C:\psexec\, you will then need to create a text file called server-list.txt and in it write down the servers you need to operate one, one for line.
The script will execute your bat with the credentials you will give it in the inputbox (in the format DOMAIN\username) on all the listed server.


Dim objFileSystem, objInputFile, strInputFile, inputData, strServer, WshShell, userid, passwordid
 
Const OPEN_FILE_FOR_READING=1
stroutputfile="C:\psexec\server-list.txt"
 
Set objFileSystem=Create("SCripting.fileSystemObject")
Set objInputFile=objFileSystem.OpenTextFile(strOutputFile,OPEN_FILE_FOR_READING)
 
Set WshShell=CreateObject("Wscript.Shell")
 
InputData=Split(obInputFile.ReadAll,vbNewline)
 
userid=InputBox(Insert your username:")
passwordid=InputBox("Insert your password:")
 
 
For each strServer in InputData
 
WshShell.run "C:\psexec\psexec.exe \\" & strServer & " -u " & userid & " -p " & passwordid & " -c C:\psexec\your-script.bat",4,true
 
Next
 
objInputFile.Close
Set objFileSystem=Nothing
Wscript.Quit(0)

Open in new window

0
 
LVL 14

Accepted Solution

by:
igor-1965 earned 2000 total points
ID: 24183018
Check out for psexec utility from sysinternals. As the parameters you will submit the list of PCs and your batch file:
Psexec pclist.txt cmd \\servername\share\yourbatch.bat
Pslist.txt should contain list of PCs in a form
\\PCname1
\\PCname2
Etc.

Hope it helps.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24183046
The bare bones of your program would look something like the following code. Firstly though, you must prepare a text file named COMPUTERS.TXT (for example) with a list of computer names.

I'm not sure whether you're XCOPYing from the same pc or not so you may have to change the XCOPY path.

@echo off
for /f "tokens=*" %%a in (computers.txt) do (
   del "\\%%a\C\Summit\CommonCode\~Cache~\*.*" /q
   del "\\%%a\C\Summit\Spectrum for Windows\Programs\~Cache~\*.*" /q
   del "\\%%a\C\Summit\Spectrum For Windows\Programs\AdvantageConfig.mdb"
   del "\\%%a\C\Summit\Spectrum For Windows\Programs\AdvantageConfigOld.mdb"
   xcopy "\\%%a\P\ONS\Lender Upgrade\AdvantageConfig.mdb" "\\%%a\C\Summit\Spectrum For Windows\Programs\"
)
exit /b 0
0
 

Author Comment

by:eddo9696
ID: 24185051
This was the solution:

psexec @pclist.txt -u oshq\username -p password -c "\\server01\Is Dept\Batch Files\Upgrade\LenderExec.cmd"

@pclist - Has all the pc names
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24187922
Does this work?

And what about the XCOPY command, should it be:

   xcopy "P:\ONS\Lender Upgrade\AdvantageConfig.mdb" "\\%%a\C\Summit\Spectrum For Windows\Programs\"

or

   xcopy "\\%%a\P\ONS\Lender Upgrade\AdvantageConfig.mdb" "\\%%a\C\Summit\Spectrum For Windows\Programs\"



@echo off
for /f "tokens=*" %%a in (@pclist.txt) do (
   del "\\%%a\C\Summit\CommonCode\~Cache~\*.*" /q
   del "\\%%a\C\Summit\Spectrum for Windows\Programs\~Cache~\*.*" /q
   del "\\%%a\C\Summit\Spectrum For Windows\Programs\AdvantageConfig.mdb"
   del "\\%%a\C\Summit\Spectrum For Windows\Programs\AdvantageConfigOld.mdb"
   xcopy "\\%%a\P\ONS\Lender Upgrade\AdvantageConfig.mdb" "\\%%a\C\Summit\Spectrum For Windows\Programs\"
)
exit /b 0
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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