473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Process.Start() not working on server

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

Nov 2 '07 #1
2 2809
Batchfiles need to be started by the command processor. Try this:

p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "e:/temp/test.bat";
"Saya" wrote:
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

Nov 2 '07 #2
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?

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Saya" <va***@hotmail.comwrote in message
news:11**********************@o38g2000hse.googlegr oups.com...
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

Nov 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ryan Walker | last post by:
Hi, I'm getting started with python and have almost zero programming experience. I'm finding that there are tons of tutorials on the internet -- such as the standard tutorial at python.org -- that...
6
by: BCM | last post by:
In a simple console app the following few lines open up an Acrobat file without a hitch: Process p = new Process(); p.StartInfo.FileName = @"C:\test.pdf"; p.Start(); But the same code in an...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
3
by: dave | last post by:
Hi, Does anyone know how I could make an .exe launched server side from an aspx file run faster? When I use javascript client side it of couse is much faster. Here's my code This code does...
3
by: PMac | last post by:
I'm trying to execute a stand-alone console application from an aspx page when a use clicks a button on that page. On the aspx page is the following lines of pertinent code: private void...
5
by: Paul Bergson | last post by:
I have been trying to get a process to start up and run with arguments passed to it. I have gotten close (Thanks to help from this board) but I there is a failure while I'm running this because...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
3
by: Steve B. | last post by:
Hi, I'm written a Web Service that encapsulate the call to a command line application. The command line application is run using Process.Start, and I'd like to get both standard ouput and...
0
by: ivanov.andrei | last post by:
Working with Windows 2003 Server. Here's the weird behavior I see. Suppose I want to launch a new process that takes me to some website, http://127.0.0.1/ Now suppose that this website uses Java...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.