Solved PsExec to Run a remote Batch file

June 24, 2011 at 17:19:10
Specs: Windows XP SP3, 4000+ / 2gb DDR
Hi for some time now I have had a Batch file on a schedule running on my remote server this can be annoying sometimes as it pops up periodically and takes the focus away, I have just discovered Psexec but for the life of me can't get it to work, are their some system processes it depends on that I might have disabled ot is it a firewall issue, even though both my local machines are on the trusted access list so why is this happening?

Psexec.exe \\Garagepc "%PROGRAMFILES%\Atlasnet\Atlasnet.bat" -u Oleg -p password -i -v

I am currently testing it on a harmless Batch that is supposed to launch Atlas my flightgear on-screen mapping program rather than the usual file monitor and copy Batch as I would not want to experiment with that yet,

Here is the output from the batch window below minus the password:

C:\Program Files\Atlasnet>Psexec.exe \\Garagepc "C:\Program Files\Atlasnet\Atlas
net.bat" -u Oleg -p password -i -v

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Couldn't access Garagepc:
Access is denied.

Any idea's ?

Michelle xxx


See More: PsExec to Run a remote Batch file

Report •


#1
June 25, 2011 at 14:11:48
Please note I also just tried another program called Reexec.exe it says the Accounts I am trying to use on remote PC do not exist? I read somewhere that Windows XP Home Redirects to the Guest account if this is true how can we get around this.

Michelle


Report •

#2
June 26, 2011 at 03:47:23
✔ Best Answer
When I read your post I guess you are running Windows XP Home as you now confirm. There is no way to exec psexec or other remote execution tools under home edition since the account sharing is disabled. XP home allows printers and files sharing only via a simplified networking method. The same for Vista home Premium. On the web you may find tricks to work around this but they force to enable the Professional version facilities in way I don't suggest to follow.


Report •

#3
June 26, 2011 at 15:00:30
Dear IVO thanks for your response it is very much appreciated, I did recently find another program called Dshutdown this works OK but sadly it does not have the features of a remote program start.

Because of a lack of resources on my main PC I use the other as a slave for doing all those menial tasks that would otherwise slow down my Simulation software on the main pc so if anyone does have a solution I would very much appreciate it.

Michelle xxx


Report •

Related Solutions

#4
June 27, 2011 at 04:09:16

Take a look at the following

http://www.tightvnc.com/

It is free and should work to access Windows XP Home systems.

Just curious, what are you simulating to stress so much your systems?

Maybe plasma dynamics for controlled thermonuclear fusion?


Report •

#5
June 27, 2011 at 06:57:48
IVO (stressing) lol Thanks for that Information will take a look at it now, I run FLIGHTGEAR I use it as part of my Movie Stage for making my Animation's so often need a remote Atlas map on other pc to run as a second slave pc, flightgear sends real time tracking information to Atlas but does not have the ability to start a program on a second PC, also the second pc does the other menial tasks such as scheduled downloads data backup, Voice chat/ftp servers etc I have a few older computers I have restored but limited space for Monitors so having a remote function is handy sometimes my main computer is only an 8X Graphics so until I can afford to buy a better PC I have to spread resources flightgear btw uses a lot of resources when it is running.

Michelle xxx


Report •

#6
June 27, 2011 at 07:10:49
IVO: Oh that's VNC I have no use for another remote desktop app, as wanted to be able to launch things via a batch file the remote desktop defeats the object by filling up my screen with another screen but thanks for the suggestion.

Oh I just found this going to check it out :D

Michelle


Report •

#7
June 27, 2011 at 14:46:02
Hi OK This "App Runner" does give some success but is trialware, it can successfully launch
my program but the feature thats built in to STOP a program does not work, it does not appear to be
listening / or / hearing the replies from the server, and as I want more control over the remote
program
I am thinking perhaps something can be added to my recently written Local batch program that runs on my client PC.


I wrote this batch from a number of code tips from people here on Toms Guide and this post of my batch
file is quite old now so will post the new version on pastebin here!

----------------------------------------------------------------------------------------------------------------------

My other idea is this if someone could help me here, I need my batch file instead of it just exiting after
it completes to monitor the process name / id of the locally running fgrun.exe and as long as
fgrun.exe is running set a special flag such as ...

echo fgrun-running > "%USERPROFILE%\state"\running.txt
my
batch then goes into a 80 second loop using my sleep.com file and checks every 80 seconds if
fgrun.exe process has terminated ; if true it then deletes the "running.txt" from the shared network folder
of "STATE"

The other computer running my application can have a simpler batch that looks every 80 seconds to
see if the flag exists if not then uses Pskill
pskill -t \\192.168.1.10 atlas.exe

But I don't know how to monitor for process application activity, I do know that every time
Atlas.exe runs it has a different process ID so it only works with the Atlas.exe name but I suppose some
command could find the process ID if that matters ? in the batch each time it looks can someone help ?

Thanks Michelle xxxx


Report •

#8
June 28, 2011 at 03:07:04
Hello Michelle,

I read your post #7 and maybe I can help since I am a regular skilled (almost I suppose) scripter. I don't clearly understand your needs since what you posted seems so closer to your target. May you explain exactly your idea (and what is fgrun.exe)?

Anyway I wanted to contact you as I have outlined an in-house solution to your issue If you need to launch a program remotely and then stop it via command line:

- copy a text file (CMD.txt) of just one line holding the command to be executed to the target PC shared folder.
- on the target PC must run (at programmed intervals via sleep.exe) a batch monitoring the shared folder. When CMD.txt is found it is opened and the command line executed then deleted to be ready to catch the next incoming command.

Let me know if you are interested, I am glad to support coding YOUR solution or delivering MINE.


Report •

#9
June 28, 2011 at 07:21:13
Dear IVO, Thank you so much, was thinking I might be burdening you so was afraid to ask ;) I will first explain the basic workings of fgrun, this is basically an EXTENSION to flightgear / (fgfs.exe), what fgrun does is send configurable data to flightgear so it is also a sort of launcher and without fgrun it would not be able to start with user preferences such as scenery paths, ; AI (Artificial Aircraft planned routes) ; etc, so for now just know that fgrun must always be running when flightgear / fgfs is running they are joined at the hip so to speak. [with that explanation out of the way]

last Night I spent ages trying to figure this out was awake 20 hours and dead on my feet and still could not get this to check a variable I saw a post from a few years back this is the post HEREI found Post #6 very helpfull and this is what gave me the idea for the code below

:: THIS IS JUST A SMALL PORTION OF MY LARGE BATCH AND IS NEAR END!!!!
:scanning
EndLocal
SetLocal EnableDelayedExpansion
cls
if exist fgtmp1 del fgtmp1
if exist fgtmp1 echo.%fgtmp1%
:: Find PID of process which contains windowtitle "fgrun.exe"
Tasklist /FI "IMAGENAME eq fgrun.exe" /FO "CSV" /NH >>tmp
sleep 4
::Filtering out PID of the process list
:: ----------------------------------------------------------
For /F "tokens=1-5* delims=," %%A in (tmp) Do (
set Txt=%%B
Echo !Txt:^"=!>>fgtmp1)
)
:: ----------------------------------------------------------
:: Getting PID
set /p PID=<fgtmp1
echo fgrun process ID = %PID%> "%USERPROFILE%\state\FGFS-RUNNING.txt"
cls
echo.
if exist fgtmp1 echo FGRUN IS RUNNING THE process ID = %PID%
sleep 10
:: if %Txt%=>>10 goto scanning
if exist fgtmp1 goto scanning
if not exist fgtmp1 del "%USERPROFILE%\state\FGFS-RUNNING.txt"
:: *********************************************************** remote end
cls
echo.
:DONE
:: ------------------------------------------------------------------------------------------

Needless to say it does not work because I have not figured out a way to check if
these PID or FGRUN.EXE values exist or not from the Tasklist.exe output!

When FGRUN is running
Tasklist /FI "IMAGENAME eq fgrun.exe" /FO "CSV" /NH >>tmp

:: gives the output ok of: "fgrun.exe","3188","Console","0","42,376 K"
:: The actual value stored in tmp = PID 3524
:: but I have added some descriptive text to my echo
My batch keeps looping though even after fgrun is stopped so my checking
is not right somewhere, I am very new to this sort f code:

:: -------------------------------------------------------------------------
For /F "tokens=1-5* delims=," %%A in (tmp) Do (
set Txt=%%B
Echo !Txt:^"=!>>tmp1)
)
:: -------------------------------------------------------------------------

I am sure this is what needs changing to look for a numerical value
and do checking for if the PID exists and if not (and is only txt or null)
then the value stored in the variable needs to make my batch exit the loop!

So now I am interested in your Idea, their still needs to be the right checking
though to monitor if fgrun is actively running and the checking needs to either
set a new KNOWN / FIXED value we can check against when fgrun exits!
OR we need to use the actual: fgrun value in the output but as text is always zero in numerical terms HOW is he question?
so the output is: "fgrun.exe","3188","Console","0","42,376 K"

But the variables of PID & Mem Usage (change each time) only thing static is the first part "fgrun.exe"

I actually spent hours just trying to find the missing Tasklist.exe and Pkill.exe because they are not native to Windows XP (HOME) so fortunately I was able to extract the files from my old copy of Windows XP Pro, I do have XP Pro but stopped using it a couple of years ago when too many Infiltrations seem to be happening on my computer or perhaps Instability issues as I was not sure but thankfully I do have access too the files in the cabs.

So I am basically wondering where to go from here ? IDEA'S PLEASE ;o)

I take it you read my Very Large Batch file HERE MY BATCH Latest Version? (this is a launcher of my own to allow me to RUN one VER at a time, their are Multiple DEVELOPMENT versions) of flightgear, because I am very close to the Guys and Gals who work in CVS and GITORIOUS Development cutting edge versions of FLIGHTGEARHERE I need to test various versions without conflict so I am often swapping over and comparing versions in a fairly fast and frequent manner because I am looking for the best features / stability available for my needs which is in making Movie's. I do get tired of getting up and jumping between PC's to press one key and dash back and getting all muddled up so having the means to remote control my own server saves an awful lot of bouncing between chairs and wearing out the seat of my pants so to speak ;)

Michelle xxx


Report •

#10
June 28, 2011 at 07:53:07
AHHH I think I found out why I was stuck in a loop: tmp had to be deleted, so this works!!!

:scanning
EndLocal
SetLocal EnableDelayedExpansion
cls
if exist fgtmp1 del fgtmp1
if exist fgtmp1 echo.%fgtmp1%
:: Find PID of process which contains windowtitle "fgrun.exe"
del tmp
Tasklist /FI "IMAGENAME eq fgrun.exe" /FO "CSV" /NH >>tmp
sleep 4
::Filtering out PID of the process list
:: ----------------------------------------------------------
For /F "tokens=1-5* delims=," %%A in (tmp) Do (
set Txt=%%B
Echo !Txt:^"=!>>fgtmp1)
)
:: ----------------------------------------------------------
:: Getting PID
set /p PID=<fgtmp1
echo fgrun process ID = %PID%> "%USERPROFILE%\state\FGFS-RUNNING.txt"
cls
echo.
if exist fgtmp1 echo FGRUN IS RUNNING THE process ID = %PID%
sleep 10
:: if %Txt%=>>10 goto scanning
if exist fgtmp1 goto scanning
if not exist fgtmp1 del "%USERPROFILE%\state\FGFS-RUNNING.txt"
:: *********************************************************** remote end
cls
echo.
:DONE

going to have a little rest for a while will wait for you to reply IVO :o)

Michelle xxxx


Report •

#11
June 28, 2011 at 08:13:19
Hi Michelle,

I examined your code and at a first glance I found several mistakes in parsing and checking the PID value. I will send you the correct code, but I prefer to develop my proposed solution. That does not mean I am wiping out your effort, but I guess we can spend a bit of our time trying to follow my way.

Please contact me by a private message with your mail address since I prefer to continue by e-mail better suited to exchange support tools.


Report •

#12
June 28, 2011 at 09:42:33
Here a revised version of your code, but there are yet mysterious startements. Please read it carefully (with my notes on the right) and see my post #11 just above.

:scanning
EndLocal                                          Why?   
SetLocal EnableDelayedExpansion     To set on again
cls
if exist fgtmp1 del fgtmp1
if exist fgtmp1 echo.%fgtmp1%            is never executed see above line
:: Find PID of process which contains windowtitle "fgrun.exe"
del tmp
Tasklist /FI "IMAGENAME eq fgrun.exe" /FO CSV /NH 1>tmp 
sleep 4
::Filtering out PID of the process list
:: ----------------------------------------------------------
For /F "tokens=2 delims=," %%A in (tmp) Do  echo.%%~A> fgtmp1
:: ----------------------------------------------------------
:: Getting PID
set /p PID=<fgtmp1
echo fgrun process ID = %PID%> "%USERPROFILE%\state\FGFS-RUNNING.txt"
cls
echo.
if exist fgtmp1 echo FGRUN IS RUNNING THE process ID = %PID%
sleep 10
:: if %Txt%=>>10 goto scanning    ???????????????
if exist fgtmp1 goto scanning
if not exist fgtmp1 del "%USERPROFILE%\state\FGFS-RUNNING.txt"
:: *********************************************************** remote end
cls
echo.
:DONE


Report •

#13
June 28, 2011 at 16:23:24
Hi IVO, thanks for the work you did, yes their was some bugs that's because I was awake for 20 + hours and some of those were put it to try and I just forgot to take them out, I was stuck in a loop before and read elsewhere on this site that Endlocal would clear the cache so because this code is part of a much larger batch file and all the stuff above this section was finished with I used endlocal to basically wipe the drawing board,

The part were you put all the ??????? was because I was trying to remember how to do a variable and tried a few things out but before going to bed left it in a commented out state is all :)

BTW I got the batch working also on the Server PC but their was a draw back, it seems atlas.exe becomes a sub process within the batch so it prevents further commands from being executed once atlas loads into it, so I ended up making a separate batch to sniff if atlas was running to terminate it I will put the code below for your examination.

:: STARTING atlas.exe on server IF fgrun.exe active on client pc ----------------------
:: ATLAS START IF.BAT

@echo off
SetLocal EnableDelayedExpansion
:: if not exist G:\* goto skip
if exist G:\FGFS-RUNNING.txt goto starting-atlas
echo Flightgear on Client PC is not running
echo Nothing to map
sleep 8
goto skip
:: ------------------------------------------
:begin
del tmp
del tmp1
:: CHECKING FOR ACTIVE ATLAS AND STORING STATUS
::Find PID of process which contains "IMAGENAME eq atlas.exe"
Tasklist /FI "IMAGENAME eq atlas.exe" /FO "CSV" /NH >>tmp
:: ..........................................
if exist tmp1 goto repeat
::Filtering out PID of the process list
For /F "tokens=1-5* delims=," %%A in (tmp) Do (
set Txt=%%B
Echo !Txt:^"=!>>tmp1)
)

:: ..........................................
::Getting PID to kill
set /p PID=<tmp1
if not exist G:\FGFS-RUNNING.txt goto closing-atlas
:: ------------------------------------------
:starting-atlas
wizmo autoblank=0 quiet
"E:\Program Files\FlightGear\bin\Win32\atlas.exe" --fg-root=L:\data --geometry=1024x768 --udp=5500 --path=p:\Atlas
goto begin
:repeat
sleep 80
if exist G:\FGFS-RUNNING.txt goto skip
:: ------------------------------------------
goto closing-atlas
REM EDDF=FRANCFURT EGNY=BEVERLEY
echo.
:: pause
REM --airport=EDDF
REM --airport=EGNY
REM --airport=NZPP
:: ------------------------------------------
:closing-atlas
::Killing process
:: pskill -t \\10.10.2.10 %PID%
Taskkill /PID %PID%
autoblank=1 quiet
::Delete tmp files
del tmp
del tmp1
EndLocal

:skip
cls

:: STOPPING atlas.exe on server IF fgrun.exe NONE active on client pc ----------------
:: ATLAS-STOP IF .BAT

@echo off
SetLocal EnableDelayedExpansion
:: ------------------------------------------
:begin
if exist tmp del tmp
if exist tmp1 del tmp1
:: CHECKING FOR ACTIVE ATLAS AND STORING STATUS
:: Find PID of process which contains "IMAGENAME eq atlas.exe"
Tasklist /FI "IMAGENAME eq atlas.exe" /FO "CSV" /NH >>tmp
:: ..........................................
:: Filtering out PID of the process list
For /F "tokens=1-5* delims=," %%A in (tmp) Do (
set Txt=%%B
Echo !Txt:^"=!>>tmp1)
)

sleep 5
:: ..........................................
:: Getting PID to kill
if not exist tmp1 goto skip
set /p PID=<tmp1

:: ------------------------------------------
:repeat
sleep 40
if not exist G:\FGFS-RUNNING.txt goto closing-atlas
:: ------------------------------------------
goto skip

:closing-atlas
::Killing process
:: pskill -t \\10.10.2.10 %PID%
Taskkill /PID %PID%
autoblank=1 quiet
wizmo monoff quiet
::Delete tmp files
del tmp
del tmp1
EndLocal
:skip

cls

:: END BATCH CODE

This is were I am so far :o) But some tidying up to do with my code as just got them working so some of it might need cleaning up a bit.

Remember the START ATLAS BATCH FILE Becomes taken over by the atlas.exe process so once it executes it is locked into running the program this is after all a .16 bit program I believe

Michelle xxx


Report •

#14
June 29, 2011 at 12:03:29
Dear IVO,

I was also trying to Include a section in my batch to make the monitor stay / WAKE THE MONITOR / ON on during the triggering of Atlas but the WIZMO.EXE tool I was trying is not effective!!!! It blacks the screen or turns the screen blanking on ok but does not wake the monitor screen on triggering Atlas! perhaps you have a simple way to do this ?

Michelle


Report •

#15
July 4, 2011 at 08:29:49
Dear IVO, just a quickie, I need a command to check for two conditions but don't know how.

set variable1==variable2 then shutdown pc

so what I need is this:
(Var1=if cpu below 30% for 30 minutes AND var2=Total Network USE below 5 kbs for 5 mins then shutdown pc !!!)

Basically both the above must be true.

Can you help here ?

Michelle xxxx


Report •

Ask Question