PSExec How to.

Hi,

I would like to use psexec to run an agent on all machines on the network.
I am using Lansweeper to scan all machines and was going to use a logon script until it was pointed out that psexec was a better way of doing this.

Can anyone give me instructions on how to use this tool effectively.

Many thanks
PurplePenguinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
simple case

psexec \\acomputer -c filename.exe
cyberkiwiCommented:
The full reference is at http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
but if you have specific questions, please ask

If it is a console application and you want to copy it to the machine and you don't have to interact with it, you can run

psexec \\computer -c -d filename.exe

This will copy (the -c) filename.exe to the machine "computer" and run it without waiting for feedback (the -d)
Your batch file can just have many lines each line a different computer
PurplePenguinAuthor Commented:
I am assuming that I run the psexec from the computer that has Lansweeper on it and also where the Lansweeper agent is and then when the psexec runs all the computers in batch file will have the agent and will continue to work after that?
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Steve KnightIT ConsultancyCommented:
That is what I was suggesting.  Also you can run that against multiple machines by making a text file of all the computer names, say, e.g. computers.txt with one per line. Then you can run one batch file and a "FOR" loop:

@echo off
FOR /f "tokens=*" %%a in (computers.txt) do (
  REM working on computer %%a
  ping -n 1 -w 100 %%a
  if errorlevel 1 (
    echo Unable to PING %%a
  ) ELSE (
    echo Asking for scan of %%a
    PSEXEC \\%%a -c \\INEXNETMON\netlogon\lsclient.exe INEXNETMON
  )
)

That will read each computer name from the text file, and try to ping it by name.  If it can't ping it (it gets an error) then it shows a message on the screen, otherwise it carried on and runs the program on the remote computer for you.

Might need some tweaking but give it a go - means you can run it when you want rather than waiting for users to logon.

Steve

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cyberkiwiCommented:
Yes you are right. -d disconnects from it but it keeps running on the target computer
PurplePenguinAuthor Commented:
To Cyberkiwi, - Excellent I will give this a go.  This is very helpful.

To Steve,

The FOR loop bit does that go on the end of the batch file after the psexec and all the computers - sorry to ask so many questions but just want to be sure I understand exactly.  Or is the list of computers separate and then the batch file references it when it runs, as per the script you have posted above.
Steve KnightIT ConsultancyCommented:
If this is an agent that stays active (confused myself now) then it probably dosn't make much difference whether you run it remotely using psexec etc. or let the user run it on logon from logon script.  I don't know the app very well so you'll have to experiment to see what works best for you.
Steve
Steve KnightIT ConsultancyCommented:
sorry crossed posts there.  The whole bit between the @echo off and the last ) is one batch file which you coul run on a remote machine and it would run down a text file list of computers in a file called computers.txt and run the lsclient.exe command on each one.  It SHOULD have been -d instead of -c though sorry,my typo:

@echo off
FOR /f "tokens=*" %%a in (computers.txt) do (
  REM working on computer %%a
  ping -n 1 -w 100 %%a
  if errorlevel 1 (
    echo Unable to PING %%a
  ) ELSE (
    echo Asking for scan of %%a
    PSEXEC \\%%a -d \\INEXNETMON\netlogon\lsclient.exe INEXNETMON
  )
)

Save that as "runonall.cmd" or something.

Steve
PurplePenguinAuthor Commented:
OK many thanks for all your help and to Cyberkiwi as well and I will see how it goes.  I will close this for now but if needs be I will add another related question if that is possible.  It may be a while before I come back to the forum and so do not want this question to be viewed as abandoned.

Have great rest of the day to you both. Cheerio!!!!!
PurplePenguinAuthor Commented:
Excellent help from two brilliant experts - Many thanks.
Steve KnightIT ConsultancyCommented:
No problem, there are always lots of ways of doing things so give them a try and ask if you need any help.  If you ask a "related question" then we hear of it, though many people will see alerts for the Q's anyway.

Steve
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.