c# - Running PsExec From IIS: PsExecSVC hanging on remote host -


i trying run .bat file on remote host web page.

psexecsvc (on host) hang , not close after execution of batch causing server wait indefinitely.
when running exact same code (see @ bottom) in console application service closes , fine...

the weird part when batch file consists of 1 liner echo:

@echo off echo ------ start ----- exit 

psexecsvc close , "------ start -----" shown on page. (this want..)

on other hand,

@echo off echo ------ start ----- echo echo2  exit 

psexecsvc hang @ end of execution...

when manually killing psexecsvc, "------ start -----" shows , stderr prints:

psexec v1.98 - execute processes remotely

copyright (c) 2001-2010 mark russinovich

sysinternals - www.sysinternals.com

the handle invalid.

connecting novi2...

starting psexec service on novi2...

connecting psexec service on novi2...

starting c:/dbinfo.bat on novi2...

error communicating psexec service on novi2:

no matter run in batch file, first line of stdout redirected , psexecsvc hangs (but after whole batch executed :o ).

if running:

info.bat:

 @echo off  cscript /nologo test.vbs  exit 

test.vbs:

set objout = wscript.stdout objout.writeline "----------------------------------" objout.writeline "win32_operatingsystem instance" objout.writeline "----------------------------------" objout.close wscript.quit 666 

a consoleapplication print , return 666

iis "----------------------------------" in stdout , psexecsvc hangs...

here code used run psexec in c#...

process proc = new process();  processstartinfo procinfo = new processstartinfo(@"c:/psexec.exe", @"\\novi2 -u domain\usernameadmin -p password c:/info.bat"); procinfo.useshellexecute = false; procinfo.redirectstandardoutput = true; procinfo.redirectstandarderror = true;  proc.startinfo = procinfo;  proc.start();  string output = proc.standardoutput.readtoend(); string err = proc.standarderror.readtoend(); trace.writeline("out >> " + output); trace.writeline("err >> " + err);  proc.close(); 

i using iis 7, asp mvc3 , .net4.0 on server (sample projects vs2010) , winxp sp3 host. avoid problems applicationpool in iis using same admin account psexec.

the problem psexecsvc on remote host (novi2) did not clean after , needs deleted before can run successfully. add following @ end of each script starts psexec against remote host:

sc \\novi2 delete psexecsvc 

also, if you're instantiating psexec on, , not against, remote host, you'll need ensure add switch accepting eula so:

psexec \\host1 /accepteula -u userid -p password command 

hope helps, lizz


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -