Thursday, August 16, 2012

psexec.exe


psexec.exe is a sysinternals tool for remotely running commands.

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

For example

psexec.exe \\machine ipconfig /all

remotely runs the ipconfig /all command on \\machine but provides the output to the "host" machine where psexec.exe has been run. admin permissions are required of course.

psexec can also be used to run commands in the context of the local system account.  Using

psexec -s -d msiexec.exe /i "%~dp0xxFILENAMExx.MSI" TRANSFORMS="%~dp0xxPackageNamexx.mst" /L*V %temp%\xxPackageNamexx.log /qn

would run a Windows Installer installation in the context of the Local System account in the same way that SCCM does. -s Use System Account  -d Don't wait for process to terminate (Non Interactive)

A further option enables the current command window to run as it would on the remote machine.  For example, after issuing the command

psexec \\machinename cmd.exe -i

the current command window now acts as it would on the remote machine.  Typing HOSTNAME will return the remote machines hostname not the hostname of the machine the command window appears to be running on.

psexec \\machinename -s cmd.exe -i

the above command runs the session in system context.

PsExec cmds will not execute against a remote ip address/machine unless either a) that machines Firewall is disabled or b) File and Print Sharing is enabled - so it can access the Admin$ share.

-u <username> -p <password> can be used to supply the admin account credentials