Solved

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

Posted on 2010-09-02
6
557 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
  • 3
  • 2
6 Comments
 
LVL 85

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now