RSS

Using PsExec to execute Serial Port commands

29 Aug

This is a small blog post about the basics of PsExec. Psexec is a strong utility that allows one to execute commands on a remote computer with out having to RDC. This is great utility for installing updates on computers without having to physically access the computer.

Notes and Resources

Notes

Prep work

  1. Create a folder at “C:\workingtemp\Psexec” and “C:\workingtemp\Psexec Commands”.
  2. Unzip the “PsTools.zip” file to the Psexec directory.
  3. Copy the “PsExec.exe” into your “C:\Windows” folder.

Configure your target computer

  1. My target computer is called “videoComp”.
  2. Note: this is the computer we are sending commands to.
  3. Navigate to “\\videoComp\c$”and make a folder there called “video”
  4. Place all the files from “C:\workingtemp\projector” into this folder.
    NOTE: If you did not read the last post <NAME AND LINK> , put your serial port commands for your projector in “\\videoComp\C$\video”.

Make your PsExec Commands

Note: Depending on if you are a super user on your network your psexec commands will vary. Make copy and paste the appropriate commands in to a text file, we will be using these shortly.

  • If you have Administrative privileges on your network use the following commands.
  • This command will be responsible for powering on the projector, by executing the “power_on.bat” we made earlier.
    psexec -i -s \\videoComp C:\video\power_on.bat
  • This command will be responsible for powering off the projector, by executing the “power_off.bat” we made earlier.
    psexec -i -s \\videoComp C:\video\power_off.bat
  • This command will be responsible for the switching input to input 1 on the projector, by executing the “Switch_To_Input_2.bat” we made earlier.
    psexec -i \\videoComp C:\video\Switch_To_Input_1.bat
  • This command will be responsible for the switching input to input 2 on the projector, by executing the “Switch_To_Input_2.bat” we made earlier.
    psexec -i \\videoComp C:\video\Switch_To_Input_2.bat
  • If you are not a super user, it will be neccessary to provide a Administrative username and password to the computer. Use the following commands
  • username = <DomainOfVideoComp>\User
  • password = User’s Password
  • Power On Projector
    psexec -i \\videoComp -u username -p password C:\video\power_on.bat
  • Power Off Projector
    psexec -i \\videoComp -u username -p password C:\video\power_off.bat
  • Switch to input 1 on the projector\
    psexec -i \\videoComp -u username -p password C:\video\Switch_Input_To_1.bat
  • Switch to input 2 on the projector\
    psexec -i \\videoComp -u username -p password C:\video\Switch_Input_To_2.bat

Make AutoIt .au3 files 

  1. Make another folder at “C:\workingtemp\Psexec Commands\autoit”, “C:\workingtemp\Psexec Commands\autoit\source” and “C:\workingtemp\Psexec Commands\autoit\compliled”.
  2. Make three files called “Power_On.au3”, “Power_Off.au3” and “Switch_To_Input_2.au3”.
  3. The Format of making these files are easy, it is as follows.
    RunWait ("<Your PsExec command>")
  4. In Power_On.au3, your command will look like this.
    RunWait("psexec -i -s \\videoComp C:\video\power_on.bat")
    or
    RunWait("psexec -i \\videoComp -u username -p password C:\video\power_on.bat")
  5. In Power_Off.au3, your command will look like this.
    RunWait("psexec -i -s \\videoComp C:\video\power_off.bat")
    or
    RunWait("psexec -i \\videoComp -u username -p password C:\video\power_off.bat")
  6. In Switch_To_Input_1.au3, your command will look like this.
    RunWait("psexec -i -s \\videoComp C:\video\Switch_To_Input_1.bat")
    or
    RunWait("psexec -i \\videoComp -u username -p password C:\video\Switch_To_Input_1.bat")
  7. In Switch_To_Input_2.au3, your command will look like this.
    RunWait("psexec -i -s \\videoComp C:\video\Switch_To_Input_2.bat")
    or
    RunWait("psexec -i \\videoComp -u username -p password C:\video\Switch_To_Input_2.bat")
  8. Drop these “.au3” files in “C:\workingtemp\Psexec Commands\autoit\source”

Make executables out of au3 files

  1. In “C:\workingtemp\…\autoit\source” right click on one of the files and select “Compile Script (x64)”.
  2. This will generate a executable of the .au3 file you clicked on. Do this for each file in this folder.
  3. Move these executables to “C:\workingtemp\Psexec Commands\autoit\compiled”
  4. When finished it should look something like this.

Make a batch file that will turn on the projector and switch to input2

  1. In “C:\workingtemp\…\autoit\compiled”
  2. Make a batch file called “Power_On_Projector.bat”.
  3. Place the following code inside this batch file.
    start /wait Power_On.exe
    start /wait Switch_To_Input_2.exe
  4. When this file is added the “C:\…\compiled” directory will look like this.

Testing the commands

  1. In “C:\workingtemp\…\autoit\compiled”, run the command “Power_On_Projector.bat”. Two command prompts should appear, the first is running the Power_On_Projector.bat and the second will run the first command in this batch file. It will look like this.
  2. Once the “power_on.exe” is ran, the “Switch_To_Input_2.exe” command will run. It will look like this.
  3. The projector should turn on and display your desktop screen. If your computer is connected to input two on the projector.
  4. Now test to see that  your Switch_To_Input_1.exe is working.

  5. Now test to see that your Power_Off.exe is working.

Advertisements
 
Leave a comment

Posted by on August 29, 2012 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: