B
Bucky Pollard
I have a web service that needs to create a batch file and call it (since
there are no APIs for the functionality I am looking for). I am using the
Process and ProcessStartInfo objects. When I try to call the batch file, it
just returns with a return code of 1. When I call cmd.exe, and pass the
batch file as a parameter it hangs. After much frustration and aggrevation,
I found that CMD IS in fact running, but it is running under the context of
ASPNET user. My web service is running under a domain account, dicatated in
the web.config file.
<authentication mode="Windows" />
<!-- Impersonate: Run as the Build ID -->
<identity impersonate="true" userName="domain\myuser" password="mypassword"
/>
All the code in the web service is using this id, except when I create the
process using the Process.Start() function. Even something as simple as
calling Notepad runs the program as the ASPNET user and I cannot see it on
my screen. The program will hang until I kill it in task manager. (I am
calling WaitForExit() ).
Why won't this run under the context I've defined in the web.config? Is
there a way to run this under that ID without using Windows APIs such as
CreateProcessWithLogonW? I've tried many different options, this is what I
currently am trying.
// Now Execute the script
ProcessStartInfo startInfo = new ProcessStartInfo(strBatchFile);
startInfo.WorkingDirectory = m_strWorkFolder;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = false;
Process procIa = Process.Start(startInfo);
if ( null == procIa )
{
strError = "Failed to start process: " + strBatFile;
return false;
}
procIa.WaitForExit();
if ( procIa.ExitCode != 0 )
{
return false;
}
TIA.
Bucky Pollard.
there are no APIs for the functionality I am looking for). I am using the
Process and ProcessStartInfo objects. When I try to call the batch file, it
just returns with a return code of 1. When I call cmd.exe, and pass the
batch file as a parameter it hangs. After much frustration and aggrevation,
I found that CMD IS in fact running, but it is running under the context of
ASPNET user. My web service is running under a domain account, dicatated in
the web.config file.
<authentication mode="Windows" />
<!-- Impersonate: Run as the Build ID -->
<identity impersonate="true" userName="domain\myuser" password="mypassword"
/>
All the code in the web service is using this id, except when I create the
process using the Process.Start() function. Even something as simple as
calling Notepad runs the program as the ASPNET user and I cannot see it on
my screen. The program will hang until I kill it in task manager. (I am
calling WaitForExit() ).
Why won't this run under the context I've defined in the web.config? Is
there a way to run this under that ID without using Windows APIs such as
CreateProcessWithLogonW? I've tried many different options, this is what I
currently am trying.
// Now Execute the script
ProcessStartInfo startInfo = new ProcessStartInfo(strBatchFile);
startInfo.WorkingDirectory = m_strWorkFolder;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = false;
Process procIa = Process.Start(startInfo);
if ( null == procIa )
{
strError = "Failed to start process: " + strBatFile;
return false;
}
procIa.WaitForExit();
if ( procIa.ExitCode != 0 )
{
return false;
}
TIA.
Bucky Pollard.