S
Saya
Hi,
I am trying to develop a WebService that needs to execute some
application commands on a server.
I am using System.Diagnostics.Process. The reason for trying to
impersonate a user is that the commands that needs to be run cannot be
run at NETWORK SERVICE but as a valid application user:
[WebMethod]
public string CreateTSUser(String UserName, String UserEmail) {
Process p = new Process();
p.StartInfo.UserName =
ConfigurationManager.AppSettings["TSMasterName"];
p.StartInfo.Password = GetSecurePass();
p.StartInfo.Domain = "??????????";
p.StartInfo.WorkingDirectory = "e:/temp";
p.StartInfo.FileName = "e:/temp/test.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.RedirectStandardOutput = true;
try
{
p.Start();
p.WaitForExit();
StreamReader srOutput = p.StandardOutput;
String CmdOutput = srOutput.ReadToEnd();
srOutput.Close();
return "Success: " + CmdOutput;
}
catch (Exception ex) {
return ex.Message;
}
}
Now the test.bat is very simple for the moment. "%system" ver and the
whole things works fine if I leave out the impersonization. Can
someone please point out what I am doing wrong here with the
impersonization ? Also what should the domain be set too ? The servers
name(=domain) or the domain of ther user that I am trying to
impersonate ?
Regards
Saya
I am trying to develop a WebService that needs to execute some
application commands on a server.
I am using System.Diagnostics.Process. The reason for trying to
impersonate a user is that the commands that needs to be run cannot be
run at NETWORK SERVICE but as a valid application user:
[WebMethod]
public string CreateTSUser(String UserName, String UserEmail) {
Process p = new Process();
p.StartInfo.UserName =
ConfigurationManager.AppSettings["TSMasterName"];
p.StartInfo.Password = GetSecurePass();
p.StartInfo.Domain = "??????????";
p.StartInfo.WorkingDirectory = "e:/temp";
p.StartInfo.FileName = "e:/temp/test.bat";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.RedirectStandardOutput = true;
try
{
p.Start();
p.WaitForExit();
StreamReader srOutput = p.StandardOutput;
String CmdOutput = srOutput.ReadToEnd();
srOutput.Close();
return "Success: " + CmdOutput;
}
catch (Exception ex) {
return ex.Message;
}
}
Now the test.bat is very simple for the moment. "%system" ver and the
whole things works fine if I leave out the impersonization. Can
someone please point out what I am doing wrong here with the
impersonization ? Also what should the domain be set too ? The servers
name(=domain) or the domain of ther user that I am trying to
impersonate ?
Regards
Saya