Solved

Batch file help with psexec from www.sysinternals.com

Posted on 2003-12-05
8
2,913 Views
Last Modified: 2008-01-09
Hi,

I have the following scenario.  I need to apply a registry update to a few hundred PC's without using a login script, or any server related tools (don't have access to the servers/scripts, etc).  Basically I have admin rights to all clients and want to apply the registry update using psexec from www.sysinternals.com (PSTOOLS).
I have got a IP range of x.x.x.50-x.x.x.200 for two sites and thought if I have the IP Address in one batch file, have another batch file call the IP Address with the PSEXEC command, ie:
PSEXEC \\[IP VAR] /u /p /c Program

I know its possible but don't know the correct code.

I am going home now so won't  be back until monday.

Cheers
0
Comment
Question by:Rob Stone
  • 5
  • 2
8 Comments
 
LVL 10

Assisted Solution

by:pbarrette
pbarrette earned 250 total points
ID: 9883417
Hi Stoner79,

If you have a list of IP's like this:
--------IPlist.txt-------
x.x.x.50
x.x.x.51
...
x.x.x.200
--------IPlist.txt-------

Then you can use a batch file like this on WinNT/2K/XP:
:: ------EXAMPLE.BAT-------
@ECHO OFF
FOR /F "DELIMS=" %%F IN (IPlist.txt) DO (
 PSEXEC \\%%F /u username /p password /c Program.exe
)
:: ------EXAMPLE.BAT-------

You could even do it as a 1 liner from the CMD prompt if you like..
FOR /F "DELIMS=" %F IN (IPlist.txt) DO (PSEXEC \\%F /u username /p password /c Program.exe)

But it will give you a lot better looking output if you use the batchfile.

Hope this helps,
pb
0
 
LVL 8

Accepted Solution

by:
K_2K earned 250 total points
ID: 9891810
This doesn't answer the original question, but may make your job a little easier.  Of course, if there's executables to run on each machine after the registry is changed, you're back to psexec.

REG.EXE from Microsoft can do it without needing uid and password, since you have admin rights on them all.  It will run faster and more simple and use less overhead.  REG.EXE only needs to be loaded on the machine you are at when you run it.

Something like this, with your keys, values, and data plugged in would fit nicely into your "program", removing need to call program from another script or command line loop, and eliminating program's need for external .reg file:

FOR /L %%K IN (50,1,200) DO (
     REG ADD \\x.x.x.%%K\HKLM\Software\MyNewProgram /f
     REG ADD \\x.x.x.%%K\HKLM\Software\MyNewProgram /v MyNewKeyValue /t REG_BINARY /d fe340e63 /f
     )

Good Luck,
2K
(\o/)
0
 
LVL 15

Author Comment

by:Rob Stone
ID: 9895563
I will try this now.

Cheers, didn't know about that utility program.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 15

Author Comment

by:Rob Stone
ID: 9895657
K_2K,

Just tried your suggestion and it works, although if a IP is not assigned to a client then it does take a while to go through the whole IP range (hence the seperate file with IP address's - should have made that more clear).

One questions, the 50,1,200 is the IP range, but what is the 1 for?  I presume I could call a seperate txt file with IP Address in if I set a variable like pb has suggested?

I have stopped it half way through and am going to try pb's suggestion now.  

I will give a grade A for this because both options are brilliant in the own way, and I needed to know pb's answer, but knowing about reg.exe will make life easier too.

Give me 30 mins or so and I'll be back.
0
 
LVL 15

Author Comment

by:Rob Stone
ID: 9895713
increased points
0
 
LVL 15

Author Comment

by:Rob Stone
ID: 9895716
Thank you both.
0
 
LVL 8

Expert Comment

by:K_2K
ID: 9900261
Thanks,  glad you could use it.  
I often use something like this when IP address is not known or DHCP makes them change often, to bypass the non-answering IP's after half a second (really long time in network speak, yet much faster than most normal time-outs):

:: Loop
FOR /L %%K IN (50,1,200) DO goto :Process %%K
:: done, don't loop after done
goto :EOF

:Process
:: bypass process if one ping not answered in half a second
ping x.x.x.%1 -n 1 -w 500 || goto :EOF
:: if ping answers, the rest of this works
REG ADD \\x.x.x.%1\HKLM\Software\MyNewProgram /f
REG ADD \\x.x.x.%1\HKLM\Software\MyNewProgram /v MyNewKeyValue /t REG_BINARY /d fe340e63 /f
goto :EOF

:: end of example



I also agree that pb's answer gives more flexibility as to what to do on each machine found.


In the FOR loop, the 1 is a step,  so you could use every third number or start at the top and go packwords.

From the DOS help screen  ( FOR /? )  :

FOR /L %variable IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)


Enjoy,
2K
(\o/)
0
 
LVL 15

Author Comment

by:Rob Stone
ID: 9902926
Cheers for that again.

:-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filter echo results from batch file output 7 80
find and replace 5 51
Populating a combobox from a text file 8 101
Batch: check service status 11 93
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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