• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

Starting a process from asp.net application

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
jhotcuff
Asked:
jhotcuff
  • 4
  • 2
  • 2
  • +2
1 Solution
 
Bob LearnedCommented:
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
 
jhotcuffAuthor Commented:
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
 
Bob LearnedCommented:
.NET version?

Bob
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
jvn222Commented:
you try set account asp.net to admin groups
0
 
RejojohnyCommented:
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
 
jhotcuffAuthor Commented:
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
 
RejojohnyCommented:
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
 
jhotcuffAuthor Commented:
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
 
jhotcuffAuthor Commented:
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
 
RomModCommented:
Question closed - 250 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now