Running One Script on a List of PC's

Posted on 2009-04-20
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

Question by:eddo9696

    Expert Comment

    first of all save the commands you want to run in a bat file.
    Then download psexec.exe from, 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
    Set objFileSystem=Create("SCripting.fileSystemObject")
    Set objInputFile=objFileSystem.OpenTextFile(strOutputFile,OPEN_FILE_FOR_READING)
    Set WshShell=CreateObject("Wscript.Shell")
    userid=InputBox(Insert your username:")
    passwordid=InputBox("Insert your password:")
    For each strServer in InputData
      "C:\psexec\psexec.exe \\" & strServer & " -u " & userid & " -p " & passwordid & " -c C:\psexec\your-script.bat",4,true
    Set objFileSystem=Nothing

    Open in new window

    LVL 14

    Accepted Solution

    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

    Hope it helps.
    LVL 16

    Expert Comment

    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

    Author Comment

    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
    LVL 16

    Expert Comment

    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\"


       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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    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 …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now