Solved

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

Posted on 2010-09-02
6
564 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
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!

 

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

Suggested Solutions

Title # Comments Views Activity
LINQ Select all records by MAX data syntax help 1 28
Generate Unique ID in VB.NET 21 104
Programming Codes 2 42
parse string in c# 5 29
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

733 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