470,815 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Issue with System.Diagnostics.Process in a Web Service

I have an issue trying to execute commands in a web service. The command
starts under the specified user. However, it never completes its execution. I
can execute simple commands like "echo HELLO" and cmd.exe starts but never
terminates. I'm relatively new to .NET, so I may be forgetting some thing
obvious. Thanks! Here's the code:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Diagnostics;
using System.Security;
using System.Threading;

[WebService(Namespace = "http://urldotcomgoeshere")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Class1 : System.Web.Services.WebService
{

public Class1()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string generateWebAccount(string account)
{

string command = Environment.ExpandEnvironmentVariables("%comspec%" );
string args = "";
string returnInfo = "";

try
{
SecureString secPass = new SecureString();
foreach (char c in "password")
{
secPass.AppendChar(c);
}

//EXECUTE COMMANDS
//C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\50\bin\owsadm.exe
//NET
//cmd /c cacls
//cmd /c copy
//command = @"g:\webcreation.bat";
args = "/c echo \"hello\" > g:\\webcreation.log";

ProcessStartInfo startInfo = new ProcessStartInfo(command, args);
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UserName = "someuser";
startInfo.Password = secPass;
startInfo.Domain = "somedomain";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
Process proc = Process.Start(startInfo);
proc.WaitForExit();

if (proc.ExitCode != 0)
{
returnInfo = returnInfo + "unsuccessful " + command + args +
proc.StandardOutput.ReadToEnd() + "\n" +
proc.StandardError.ReadToEnd() + "\n";
}
else
{
returnInfo = returnInfo + "successful " + command + args +
proc.StandardOutput.ReadToEnd();

}
}
catch (Exception e)
{
return e.Message;
}
return returnInfo;
}
}
Mar 7 '06 #1
1 4647
I have an issue trying to execute commands in a web service. The command
starts under the specified user. However, it never completes its execution. I
can execute simple commands like "echo HELLO" and cmd.exe starts but never
terminates. I'm relatively new to .NET, so I may be forgetting some thing
obvious. Thanks! Here's the code:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Diagnostics;
using System.Security;
using System.Threading;

[WebService(Namespace = "http://urldotcomgoeshere")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Class1 : System.Web.Services.WebService
{

public Class1()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string generateWebAccount(string account)
{

string command = Environment.ExpandEnvironmentVariables("%comspec%" );
string args = "";
string returnInfo = "";

try
{
SecureString secPass = new SecureString();
foreach (char c in "password")
{
secPass.AppendChar(c);
}

//EXECUTE COMMANDS
//C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\50\bin\owsadm.exe
//NET
//cmd /c cacls
//cmd /c copy
//command = @"g:\webcreation.bat";
args = "/c echo \"hello\" g:\\webcreation.log";

ProcessStartInfo startInfo = new ProcessStartInfo(command, args);
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UserName = "someuser";
startInfo.Password = secPass;
startInfo.Domain = "somedomain";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
Process proc = Process.Start(startInfo);
proc.WaitForExit();

if (proc.ExitCode != 0)
{
returnInfo = returnInfo + "unsuccessful " + command + args +
proc.StandardOutput.ReadToEnd() + "\n" +
proc.StandardError.ReadToEnd() + "\n";
}
else
{
returnInfo = returnInfo + "successful " + command + args +
proc.StandardOutput.ReadToEnd();

}
}
catch (Exception e)
{
return e.Message;
}
return returnInfo;
}
}
Hi.

I am having a similar problem but, in my case I am trying to print a pdf using acrobat.exe.
The command:
acrord32.exe /p /h c:\teste1.Pdf
works if is run from the command line.
But when I execute it using a process from C# it is triggered and acrobat process starts (task bar) but it nerver ends and does nothing. In the event viewer I can see the following error: Application popup: Acrobat.exe - Application Error : The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.

Can you please say if you managed to solve your problem?
I also tried using a vbscript but the result is the same.

Thanks,
Andreia
Posted from http://www.topxml.com/renntp using reNNTP: the website based NNTP reader.
Aug 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sebastian Sosna | last post: by
5 posts views Thread by Paul Bergson | last post: by
3 posts views Thread by Bali | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.