?
Solved

Starting a process from asp.net application

Posted on 2006-05-29
11
Medium Priority
?
574 Views
Last Modified: 2012-06-21
Hi,

I have a problem with my asp.net web service application. What I need to do is call a command line application with arguments, or to execute a batch(.bat) file from my ws application. The command line application is used to transfer a file. I've tested these with a Windows Forms app, and it works nicely when using System.Diagnostics.Process class or CommandLineProcess class from http://www.codeguru.com/csharp/csharp/cs_misc/userinterface/article.php/c8503/.
When I try to use these classes from an asp.net application, a new process is created in task manager, but nothing really happens.

I'm aware that this has something to do with user privileges and the fact that this all happens server side. I also have the following entry in web.config <identity impersonate="true" userName="myUsername" password="myPassword" />, where myUsername has Administrator privileges. I also checked that the application is run under myUsername(System.Security.Principal.WindowsIdentity.GetCurrent().Name = myUsername).

This is the code I use, which works from a Windows Forms App,

  shellProcess.StartInfo.FileName := 'C:\somewhere\myApp.exe';
  shellProcess.StartInfo.Arguments := '-A -P 0 myFile.txt';
  shellProcess.StartInfo.CreateNoWindow := true;
  shellProcess.StartInfo.UseShellExecute := true;
  shellProcess.Start;

I've been struggling with this for quite long, so any help is greatly appreciated.
0
Comment
Question by:jhotcuff
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16785191
Could you explain some about what the external process is and does?  Can it be integrated into your web service without making an external call?

Bob
0
 

Author Comment

by:jhotcuff
ID: 16785812
The external process is a third party command line software for file transfer(scp) over ssh, and so it cannot be integrated into my ws project. I've also tried to make a batch file and put the command there, but it never gets executed. If I call the same batch file from a Windows Forms App with the code from my original post(shellProcess.StartInfo.FileName := <batchfile>), it works nicely.

I'm running out of options with this one. Is it even possible to do it this way or do I have to create another project(with tcp listener or something) to achieve this?

Markus
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16786567
.NET version?

Bob
0
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.

 
LVL 4

Expert Comment

by:jvn222
ID: 16787115
you try set account asp.net to admin groups
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16787491
can u give this a try

C#
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo("'C:\somewhere\myApp.exe'");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
System.Diagnostics.Process.Start(startInfo);
startInfo.Arguments = "-A -P 0 myFile.txt";
System.Diagnostics.Process.Start(startInfo);

if the above does not work .. can u pls post ur code that u r using in ur web applciation ... also try giving full access right to "everyone" for "'C:\somewhere\myApp.exe"

Rejo
0
 

Author Comment

by:jhotcuff
ID: 16788277
I'm using .NET version 1.1. I have set the aspnet account to admin group.

-Rejo, I tried the code you posted but it didn't help. I have given full access to "everyone" for myApp.exe.

In my application, an xml file is created when the web method gets requested. The filename is passed as a parameter to sendRequest -function, which has just the code from my original post(replacing "myFile.txt" with the actual parameter). The file is created, but it's never sent.

Delphi for .NET
----------------------------------------------------------------------------------------------------
requestFile := REQ_PATH +SOME_CUSTID +'_' +DateTime.Now.Year.ToString +sMonth
                   +sDay +sHour +sMinute +sSecond +'.REQ';

if CreateFile(requestFile,xmlContent) then
  SendRequest(requestFile);


function sendRequest(fileName:String):boolean;
begin
  shellProcess.StartInfo.FileName := 'C:\somewhere\myApp.exe';
  shellProcess.StartInfo.Arguments := '-A -P 0 '+fileName;
  shellProcess.StartInfo.CreateNoWindow := true;
  shellProcess.StartInfo.UseShellExecute := true;
  shellProcess.Start;
end;
----------------------------------------------------------------------------------------------------

Again, this works great from a windows forms application.
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16788917
try not to create a requestFile on runtime .. try the code for a physical file which is already present and "everyone" has full access to it .. if that works, we can nail down the problem as a security issue and work on that ..

Rejo
0
 

Author Comment

by:jhotcuff
ID: 16789551
Ok,

Now I finally got a trail on this. I turned on the IIS Admin service property "Allow IIS to interact with desktop". Then I simply make this call from my web service:

System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable('COMSPEC'),
      ' /k myApp.exe -A -P 0 '+fileName');

This opens the command prompt and executes the application, BUT the output is indicating that the application expects that a public key is sent to the server, since it uses ssh connection. If I run command prompt and type the same command, it all works nicely. So it is a security issue of some kind.

I don't what security risk it is to let IIS to interact with desktop, but at least it got me going.


Markus
0
 

Author Comment

by:jhotcuff
ID: 16797464
I found the problem. My web service was running under iis with the ASPNET account. However, when I added impersonation to my web service's web.config, it runs as the desired admin account but the process created from within the application is run with ASPNET account.

So, I configured my machine.config(processModel) to use the administrator account, and it works.

Hope this can be of help to anyone struggling with the same issue.

Thanks for helping me out!
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 16849026
Question closed - 250 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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