Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-02
6
Medium Priority
?
576 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 800 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 1200 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
Technology Partners: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Simple Linear Regression

715 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