top of page

Lit Painting Group

Public·4 members

PsExec Tips and Tricks: How to Run Commands on a List of Computers


What is psexec.exe and why use it?




If you are a Windows administrator or power user, you may have encountered situations where you need to run commands or programs on remote computers without installing any software or logging in to them. For example, you may want to check the status of a service, install a patch, reboot a system, or run a diagnostic tool on another machine.




Run psexec.exe for list of computers stored in text file


Download Zip: https://www.google.com/url?q=https%3A%2F%2Ftweeat.com%2F2tWMJz&sa=D&sntz=1&usg=AOvVaw1DFHVRFLlhrOB_Y_ZUerza



One way to do this is to use psexec.exe, a command-line utility that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec is part of PsTools, a suite of free utilities from Microsoft that can help you manage Windows systems.


Some of the benefits and use cases of psexec.exe are:


  • It can run any program or command on remote computers without requiring any installation or configuration.



  • It can run programs or commands as any user account, including system account or domain account.



  • It can run programs or commands with elevated privileges, bypassing User Account Control (UAC) prompts.



  • It can run programs or commands interactively, showing the output on your local console or redirecting it to a file.



  • It can run programs or commands on multiple computers at once, using a text file that contains the list of computer names or IP addresses.



In this article, you will learn how to set up and use psexec.exe for running processes remotely on other computers. You will also learn some tips and tricks for using psexec.exe effectively.


How to set up psexec.exe




Before you can use psexec.exe, you need to make sure that both your local computer and the remote computers meet some requirements. These are:


  • Both computers must be running Windows operating system.



  • Both computers must have file and printer sharing enabled in Windows Firewall settings.



  • You must have access to the $admin share on the remote computers, which provides access to their \\Windows\\ folder.



  • You must know the password of an administrator account on the remote computers.



  • Both computers must belong to the same workgroup or domain.



If you need help with any of these steps, you can refer to this tutorial that explains how to fix common issues with psexec.exe.


Once you have met these requirements, you can download psexec.exe from Microsoft Learn. It is part of PsTools suite, which contains other useful utilities for Windows management. You can download PsTools.zip file and extract it to any folder on your local computer.


The next step is to copy psexec.exe onto your executable path. This means that you can run it from any folder without typing its full path. One way to do this is to copy it to C:\\Windows\\System32 folder, which is usually part of your executable path by default. Alternatively, you can add the folder where you extracted PsTools.zip file to your executable path by following these instructions.


How to use psexec.exe




Basic syntax and parameters




To use psexec.exe, you need to open Command Prompt on your local computer and type the following syntax:


psexec [\\\\computer [,computer2 [,...] @file]] [-u user [-p psswd] [-n s] [-r servicename] [-h] [-l] [-s-e] [-x] [-i [session]] [-c executable [-f-v]] [-w directory] [-d] [-] [-a n,n,...] cmd [arguments]


The meaning of each parameter is explained below:



ParameterDescription


-aSeparate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: \"-a 2,4\"


-cCopy the specified executable to the remote system for execution. If you omit this option the application must be in the system path on the remote system.


-dDon't wait for process to terminate (non-interactive).


-eDoes not load the specified accounts profile.


-fCopy the specified program even if the file already exists on Continuing the article: the remote system.


-hIf the target system is Vista or higher, has the process run with the account's elevated token, if available.


-iRun the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session. This flag is required when attempting to run console applications interactively (with redirected standard IO).


-lRun process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.


-nSpecifies timeout in seconds connecting to remote computers.


-pSpecifies optional password for user name. If you omit this you will be prompted to enter a hidden password.


-rSpecifies the name of the remote service to create or interact with.


-sRun the remote process in the System account.


-uSpecifies optional user name for login to remote computer.


-vCopy the specified file only if it has a higher version number or is newer on than the one on the remote system.


-wSet the working directory of the process (relative to remote computer).


-xDisplay the UI on the Winlogon secure desktop (local system only).


-Specify a process priority for PsExec's service on the remote system. The valid values are: bg (background), low, belownormal, abovenormal, high, and realtime.


\\\\computerDirect PsExec to run the application on the remote computer or computers specified. If you omit the computer name, PsExec runs the application on the local system, and if you specify a wildcard (\\\\*), PsExec runs the command on all computers in the current domain.


@fileDirect PsExec to run the command on each computer listed in the text file specified.


cmdThe Windows command, program or batch file to be executed remotely.


For more details and examples of each parameter, you can refer to the official documentation of psexec.exe.


How to run psexec.exe for a list of computers stored in a text file




One of the most useful features of psexec.exe is that it can run commands or programs on multiple computers at once, using a text file that contains the list of computer names or IP addresses. This can save you a lot of time and effort when you need to perform the same task on many systems.


To use this feature, you need to create a text file that has one computer name or IP address per line. For example, you can create a file called computers.txt with the following content:


\\\\PC1 \\\\PC2 \\\\PC3 192.168.1.100 192.168.1.101


This file specifies five computers that you want to run commands on: three by name and two by IP address. You can use any text editor to create this file and save it in any location on your local computer.


Then, you need to use the @file parameter in your psexec.exe command and specify the path to the text file. For example, if you want to run ipconfig /all on all the computers listed in computers.txt, you can use this command:


psexec @C:\\Users\\Admin\\Desktop\\computers.txt ipconfig /all


This command will run ipconfig /all on each computer in the text file and show the output on your local console. You can also redirect the output to a file using > operator. For example:


psexec @C:\\Users\\Admin\\Desktop\\computers.txt ipconfig /all > C:\\Users\\Admin\\Desktop\\output.txt


This command will save the output of ipconfig /all on each computer in a file called output.txt on your desktop.


You can use any other command or program instead of ipconfig /all, as long as it is available on the remote systems or you use the -c parameter to copy it from your local system.


How to redirect output and handle errors




When you use psexec.exe to run commands or programs on remote computers, you may want to capture the output or handle any errors that may occur. PsExec provides some options for doing this.


By default, PsExec displays the output of the command or program on your local console. However, you can also redirect the output to a file using > operator. For example:


psexec \\\\PC1 netstat -a > C:\\Users\\Admin\\Desktop\\netstat.txt


This command will run netstat -a on PC1 and save the output in a file called netstat.txt on your desktop.


If you want to append the output to an existing file instead of overwriting it, you can use >> operator instead of >. For example:


psexec \\\\PC1 netstat -a >> C:\\Users\\Admin\\Desktop\\netstat.txt


This command will add the output of netstat -a on PC1 to the end of netstat.txt file on your desktop.


If you want to redirect both standard output and standard error to a file, you can use 2>&1 operator after > or >>. For example:


psexec \\\\PC1 netstat -a > C:\\Users\\Admin\\Desktop\\netstat.txt 2>&1


This command will redirect both standard output and standard error of netstat -a on PC1 to netstat.txt file on your desktop.


If you want to suppress any output from psexec.exe, you can use -n parameter with a value of 0. This will make psexec.exe exit immediately without waiting for any output from the remote process. For example:


psexec -n 0 \\\\PC1 netstat -a


This command will run netstat -a on PC1 and exit without showing any output.


If you want to check whether psexec.exe succeeded or failed in running the remote process, you can use %errorlevel% variable after running psexec.exe. This variable will contain an error code that indicates the status of psexec.exe execution. The possible error codes are:



Error codeDescription


0The operation completed successfully.


1The process exited with an error code.


2The system cannot find the file specified.


3The system cannot find the path specified.


4The system cannot open the file.


5Access is denied.


6The handle is invalid.


7The storage control blocks were destroyed.


8Not enough storage is available to process this command.


9


@fileDirect PsExec to run the command on each computer listed in the text file specified.


cmdThe Windows command, program or batch file to be executed remotely.


argumentsArguments to pass to the command or program.


For more details and examples of each parameter, you can refer to the official documentation of psexec.exe.


How to run psexec.exe for a list of computers stored in a text file




One of the most useful features of psexec.exe is that it can run commands or programs on multiple computers at once, using a text file that contains the list of computer names or IP addresses. This can save you a lot of time and effort when you need to perform the same task on many systems.


To use this feature, you need to create a text file that has one computer name or IP address per line. For example, you can create a file called computers.txt with the following content:


\\\\PC1 \\\\PC2 \\\\PC3 192.168.1.100 192.168.1.101


This file specifies five computers that you want to run commands on: three by name and two by IP address. You can use any text editor to create this file and save it in any location on your local computer.


Then, you need to use the @file parameter in your psexec.exe command and specify the path to the text file. For example, if you want to run ipconfig /all on all the computers listed in computers.txt, you can use this command:


psexec @C:\\Users\\Admin\\Desktop\\computers.txt ipconfig /all


This command will run ipconfig /all on each computer in the text file and show the output on your local console. You can also redirect the output to a file using > operator. For example:


psexec @C:\\Users\\Admin\\Desktop\\computers.txt ipconfig /all > C:\\Users\\Admin\\Desktop\\output.txt


This command will save the output of ipconfig /all on each computer in a file called output.txt on your desktop.


You can use any other command or program instead of ipconfig /all, as long as it is available on the remote systems or you use the -c parameter to copy it from your local system.


How to redirect output and handle errors




When you use psexec.exe to run commands or programs on remote computers, you may want to capture the output or handle any errors that may occur. PsExec provides some options for doing this.


By default, PsExec displays the output of the command or program on your local console. However, you can also redirect the output to a file using > operator. For example:


psexec \\\\PC1 netstat -a > C:\\Users\\Admin\\Desktop\\netstat.txt


This command will run netstat -a on PC1 and save the output in a file called netstat.txt on your desktop.


If you want to append the output to an existing file instead of overwriting it, you can use >> operator instead of >. For example:


psexec \\\\PC1 netstat -a >> C:\\Users\\Admin\\Desktop\\netstat.txt


This command will add the output of netstat -a on PC1 to the end of netstat.txt file on your desktop.


If you want to redirect both standard output and standard error to a file, you can use 2>&1 operator after > or >>. For example:


psexec \\\\PC1 netstat -a > C:\\Users\\Admin\\Desktop\\netstat.txt 2>&1


This command will redirect both standard output and standard error of netstat -a on PC1 to netstat.txt file on your desktop.


If you want to suppress any output from psexec.exe, you can use -n parameter with a value of 0. This will make psexec.exe exit immediately without waiting for any output from the remote process. For example:


psexec -n 0 \\\\PC1 netstat -a


This command will run netstat -a on PC1 and exit without showing any output.


If you want to check whether psexec.exe succeeded or failed in running the remote process, you can use %errorlevel% variable after running psexec.exe. This variable will contain an error code that indicates the status of psexec.exe execution. The possible error codes are:



Error codeDescription


0The operation completed successfully.


1The process exited with an error code.


2The system cannot find the file specified.


3The system cannot find the path specified.


4The system cannot open the file.


5Access is denied.


6The handle is invalid.


7The storage control blocks were destroyed.


8Not enough storage is available to process this command.


9


10The environment is incorrect.


11An attempt was made to load a program with an incorrect format.


12The access code is invalid.


13The data is invalid.


14Not enough storage is available to complete this operation.


15The system cannot find the drive specified.


16The directory cannot be removed.


17The system cannot move the file to a different disk drive.


18There are no more files.


19The media is write protected.


20The system cannot find the device specified.


21The device is not ready.


22The device does not recognize the command.


23Data error (cyclic redundancy check).


24The program issued a command but the command length is incorrect.


25The drive cannot locate a specific area or track on the disk.


26The specified disk or diskette cannot be accessed.


27The drive cannot find the sector requested.


28The printer is out of paper.


29The system cannot write to the specified device.


30The system cannot read from the specified device.


31A device attached to the system is not functioning.


32The process cannot access the file because it is being used by another process.


33The process cannot access the file because another process has locked a portion of the file.


34The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1.


You can use these error codes to troubleshoot any problems with psexec.exe or to create conditional statements in batch files or scripts. For example, you can use the IF command to check the value of %errorlevel% and perform different actions based on the result. For example:


psexec \\\\PC1 netstat -a IF %errorlevel% EQU 0 ( echo The command completed successfully. ) ELSE ( echo The command failed with error code %errorlevel%. )


This batch file will run netstat -a on PC1 and display a message depending on whether the command succeeded or failed.


Tips and tricks for using psexec.exe




Now that you know how to set up and use psexec.exe, here are some tips and tricks that can help you get the most out of this powerful tool.



  • If you want to run interactive commands on remote computers, such as ping, ipconfig, or netstat, you need to use the -i parameter to show the output on your local console. Otherwise, you will not see any output from these commands.



If you want to run commands as the system account on remote computers, you can use the -s parameter. This can be useful for performing tasks that require higher privileges than a regular user account. For example, you can use this command to run regedit as system account on PC1:


psexec -s -i \\\\PC1 rege


  • About

    Welcome to the group! You can connect with other members, ge...

    bottom of page