Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2946
  • Last Modified:

Batch file help with psexec from www.sysinternals.com

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
Rob Stone
Asked:
Rob Stone
  • 5
  • 2
2 Solutions
 
pbarretteCommented:
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
 
K_2KCommented:
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
 
Rob StoneAuthor Commented:
I will try this now.

Cheers, didn't know about that utility program.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Rob StoneAuthor Commented:
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
 
Rob StoneAuthor Commented:
increased points
0
 
Rob StoneAuthor Commented:
Thank you both.
0
 
K_2KCommented:
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
 
Rob StoneAuthor Commented:
Cheers for that again.

:-)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now