Solved

Batch file help with psexec from www.sysinternals.com

Posted on 2003-12-05
8
2,882 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

20 Experts available now in Live!

Get 1:1 Help Now