Solved

Issue with getting System.Diagnostics.Process to execute a command line with right arguments

Posted on 2010-09-02
6
566 Views
Last Modified: 2012-05-10
Hi all,
I have this very strange issue with a process that executes a command line (that talks to tumbleweed secure transport client) from a .NET Windows Service. This works fine from a windows forms application, strangely but not from a Windows Service. I am running as "Local System". Here's my code snippet from the service:
string batchFile = @"C:\temp\MyBat_TEMP.bat";

            System.Diagnostics.ProcessStartInfo procStartInfo =
            new System.Diagnostics.ProcessStartInfo(batchFile);
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            //procStartInfo.WorkingDirectory = @"C:\temp";
            System.Diagnostics.Process process1;
            process1 = new System.Diagnostics.Process();
            process1.StartInfo = procStartInfo;
            process1.Start();
            process1.close

Here's my batch file content (1 line):
stclient httpsu://<clienthostname>:443/BulkImport/to/ C:\ToSend\AMC_NT_6_201009021000.csv /prefNoAskSched /Remote-Site <RemoteSIteName>

It looks like the stclient is being called but with incorrect arguments WHEN i run from a windows service. Same code runs fine from an exe.
Does anyone know if anything needs to be done differently with the arguments to an exe when we run from a windows service vs an exe.
Any help is appreciated!
Thanks!
0
Comment
Question by:KimberleyY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 33593131
Does it work like this?
            System.Diagnostics.Process process1 = new System.Diagnostics.Process();
            process1.StartInfo.FileName = "stclient";
            process1.StartInfo.Arguments = @"httpsu://<clienthostname>:443/BulkImport/to/ C:\ToSend\AMC_NT_6_201009021000.csv /prefNoAskSched /Remote-Site <RemoteSIteName>";
            process1.StartInfo.UseShellExecute = false;
            process1.StartInfo.CreateNoWindow = true;
            process1.StartInfo.WorkingDirectory = @"C:\temp";
            process1.Start();

Open in new window

0
 
LVL 22

Accepted Solution

by:
cookre earned 300 total points
ID: 33593141
When a normal exe runs, it runs under the security of the logged on user.  A service, however, runs under the security of the configured account, in this case, systemlocal, which has full rights to the local box, but none to the network.

You may want to try a runas:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true

Note also that a service must be typed as interactive in order to see the window's message pump.
0
 
LVL 22

Expert Comment

by:cookre
ID: 33593144
cross posting is fun...
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

Author Comment

by:KimberleyY
ID: 33593456
Thanks for the responses.
IdleMind..I did try that as well, same result as the batch file. Seems to run the command line with some invalid options
Cookre..I tried doing:
procstartinfo.verb = "runas /user:<username>@domain
and that didn't help either.
I'll play with the runas option a little bit more.
I am also almost certain it's got something to do with running as localsystem vs user.
Thanks!
0
 

Author Comment

by:KimberleyY
ID: 33593462
cookre...also, i did turn on the "Allow service to interact with the desktop" option under the service proerties.
0
 

Author Comment

by:KimberleyY
ID: 33600432
This was interesting...there was a space in one of my command line options:
stclient httpsu://<clienthostname>:443/BulkImport/to/ C:\ToSend\AMC_NT_6_201009021000.csv /prefNoAskSched /Remote-Site <RemoteSIteName>
This worked from my windows forms exe but not from my windows service. I had to remove the space
/Remote-Site<RemoteSiteName> in order for the process to execute this command line correctly from the window service.
I thought the "@" at the beginning of the argument string would take care of that, but apparently it didnt.
Thanks for your time. I am closing this issue.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question