473,320 Members | 2,111 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,320 software developers and data experts.

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 4820
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Wyatt | last post by:
So I'll preface this with the fact that I'm a UNIX developer by training and have just recently gotten in to C# development on Windows. I'm basically running in to a problem whereby I suspect...
0
by: Daniel Reber | last post by:
I am trying to start a process from a windows service but when the process starts the command window that the process runs in never shows. Is this because I am calling it from a windows service? ...
2
by: Sebastian Sosna | last post by:
Hello NG, iam having a problem with the code block below. All what i do is to trace processes that exited. Iam using a 5 sec timer to call the following Method: (wich i think is causing the...
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...
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...
2
by: Kirk | last post by:
My web page needs to start a process on the server that runs as a domain user so it can access the network. I'm using web services and the new feature in .NET 2.0 that lets you start a process as...
1
by: Daniel | last post by:
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific...
0
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to...
3
by: Bali | last post by:
Hi I have an ASP.NET application. I am on the server side and trying to start an application which is on the server. The process gets started(can be seen in the Task Manager) but doesn't do...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.