i'm running batch file asp.net/c# code on web server. batch file performs test automation tasks on vm using tools psloggedon , pexec.
if run batch file manually when i'm logged server under administrative account, works fine.
my problem comes when run code (below), seems run under 'system' account, , psloggedon etc. don't seem work correctly.
code
process p = new process(); p.startinfo.filename = "c:\setupvm.bat"; p.start(); p.waitforexit(); i've got in web.config, doesn't seem make differance?
<identity impersonate="true" username="administrator" password="myadminpassword"/> is there anyway can ensure batch file runs under 'administrator' account?
updated code
process p = new process(); p.startinfo.filename = "c:\\setupvm.bat"; p.startinfo.username = "administrator"; p.startinfo.useshellexecute = false; p.startinfo.workingdirectory = "c:\\"; string prepassword = "myadminpassword"; securestring passwordsecure = new securestring(); char[] passwordchars = prepassword.tochararray(); foreach (char c in passwordchars) { passwordsecure.appendchar(c); } p.startinfo.password = passwordsecure; p.start(); p.waitforexit(); from msdn:
when useshellexecute false, can start executables process component.
maybe issue i'm trying run .bat file?
thanks.
you can provide username , password startinfo:
process p = new process(); p.startinfo.filename = "c:\setupvm.bat"; p.startinfo.username = "administrator"; p.startinfo.password = "adminpassword"; p.start(); p.waitforexit(); see documentation processstartinfo.
Comments
Post a Comment