Solved

Batch file help with psexec from www.sysinternals.com

Posted on 2003-12-05
8
2,897 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
7-Zip Command Line Issues 12 91
Printing Folders, SubFolders, Files. 16 205
Network Opened Files : Script or Tool without Server access 4 72
network copying issue 4 66
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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