Process.Start() not working on server

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
 
G

Guest

Batchfiles need to be started by the command processor. Try this:

p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "e:/temp/test.bat";
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I thik you are using the incorrect path

p.StartInfo.WorkingDirectory = "e:/temp";


should be:

p.StartInfo.WorkingDirectory = @"e:\temp";


Also, what kind of error are youg etting?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top