Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easiest way to add local administrators

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
Sigh, now that I have the log file working... :)

I need to add a local administrator to about 400 machines. I want to do this with out adding a login script for the machines via GPO. PsTools immediately came to mind. I am reading the list of machines from a text file; Using my.computer.network.ping** to see if it is available; Then a shell() command to do the deed
Code:
shell(psexec \\" & strComputer & " -u administrator -p password -c " & Chr(34) & "c:\addAdmin.cmd" &  Chr(34))
The program runs, logs the machine names and apparently works. When I check nothing has changed. So I thought one huge friggin batch file.
Code:
:fixLocal.cmd:
psexec \\%1 -u administrator -p password -c addAdmin.cmd
calling fixlocal.cmd <machineName> from a cmd session error out with 'The specified application is not on the path'. Since the error comes from psexec I assume it means the batch file. Problem with that is all of it is in the path.

The exact same command manually entered into the same cmd window works perfectly.

Ideas?

** As a side note: It appears that my.computer.network.ping does not return false if a machine name is not resolved. It throws an exception instead.
 
You might try using
Code:
System.Diagnostics.Process.Start("psexec \\" & strComputer & " -u administrator -p password -c " & Chr(34) & "c:\addAdmin.cmd" &  Chr(34))
instead of shell. They are pretty much the same thing, but there may be enough difference between the two to work.

-I hate Microsoft!
-Forever and always forward.
 
Nope, nothing. Off to the Sysinternals support forums.
 
Question. These are actually totally different.
Code:
psexec \\" & strComputer & " -u administrator -p password -c " & Chr(34) & "c:\addAdmin.cmd" &  Chr(34)
Code:
psexec \\%1 -u administrator -p password -c addAdmin.cm
The first has it trying to copy addAdmin.cmd from the C drive of the computer you are running PsExec on and the other has it trying to run addAdmin.cmd from the system path of the computer named. For the first was addAdmin.cmd in your C:\ directory and the second was in on the remote machines system directory?

-I hate Microsoft!
-Forever and always forward.
 
Actually the second one copeis the file from the same directory that psexec is run from.

To clear up all questions of paths I put the addAddmin.cmd in the same directory as psTools and added it to the path.

Running
Code:
psexec \\machine1 -u administrator -p password -c addAdmin.cmd
from the command prompt works as expected, addAdmin.cmd is copied to machine1 then executed.
Creating a batch file test.cmd in the same directory with everything else
Code:
psexec \\%1 -u administrator -p password -c addAdmin.cmd
from the command prompt entering test.cmd machine1 and mashing the enter key results in the not on the path error.

I do not understand why manually typing it is any different than using a command line argument. Very baffling.

Ed
 
Actually the second one copeis the file from the same directory that psexec is run from.
I've never used it fully (while I have the rights to do it they get pissy sometimes about things so I rather not) so I wouldn't know for sure. All the documentation I found said that was the case (including the version they run here), but that doesn't mean it isn't some other version or something. Especially since it runs find when you do it from just the command line. I just don't get why then it would give you 'The specified application is not on the path'. Have you for grins force the full path in the test.cmd file just incase it is more picky because it is ran from a batch file?

There are a few other things I was just thinking I can try here.



-I hate Microsoft!
-Forever and always forward.
 
Try variations on this (ie. with/out full path):

Code:
System.Diagnostics.Process.Start("psexec",  "\\" & strComputer & " -u administrator -p password -c addAdmin.cmd")
I just found for some reason on some processes it doesn't like it to be all in one line. For this they setup were you can select the command and arguments separate. Again I couldn't fully test it, but it seemed to work fine. Also try with/out the quotes when using the full path as our version doesn't seem to want them.

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top