?
Solved

Batch file help with psexec from www.sysinternals.com

Posted on 2003-12-05
8
Medium Priority
?
2,941 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 10

Assisted Solution

by:pbarrette
pbarrette earned 1000 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 1000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

718 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