Run an .exe

  • Thread starter Thread starter Guest
  • Start date Start date
mg said:
How can I run an .exe using C# from within the code behind of a WebForm app?

Where do you want to run the .exe? On the client, or the server? You
won't be able to do it on the client. To do it on the server, use
Process.Start.
 
I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?
 
When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the client
context, and allow you to run programs on that.

Hope this helps.
 
The code is run in Visual Studio .NET 2003 on my desktop, so I should see the
notepad ... I think ... ???

Nicholas Paldino said:
When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the client
context, and allow you to run programs on that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mg said:
I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?
 
mg,

If you are hosting a web project in VS.NET 2003, or it is your machine,
then yes, it will show up on your desktop, because the server is on your
machine. However, for anyone outside of your machine connecting, it will
not work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mg said:
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

Nicholas Paldino said:
When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the
client
context, and allow you to run programs on that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mg said:
I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?


:

How can I run an .exe using C# from within the code behind of a
WebForm
app?

Where do you want to run the .exe? On the client, or the server? You
won't be able to do it on the client. To do it on the server, use
Process.Start.
 
I'm sorry, I wasn't clear. The problem is that I don't see notepad when I run
this line of code in Visual Studio .NET on my desktop ....

Nicholas Paldino said:
mg,

If you are hosting a web project in VS.NET 2003, or it is your machine,
then yes, it will show up on your desktop, because the server is on your
machine. However, for anyone outside of your machine connecting, it will
not work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mg said:
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

Nicholas Paldino said:
When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the
client
context, and allow you to run programs on that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?


:

How can I run an .exe using C# from within the code behind of a
WebForm
app?

Where do you want to run the .exe? On the client, or the server? You
won't be able to do it on the client. To do it on the server, use
Process.Start.
 
Not unless the ASP.NET worker process is running under the same
account as the logged in user (which it doesn't by default), or the
ASPNET account has additional privileges beyond the default.

The desktop is a secured resource and has an access control list. This
prevents some other logon from throwing up applications on a desktop
someone else owns.

Notepad will start, but will run in a non-interactive (invisible)
winstation.
 
I've since formally deployed the simple one-line of code, which runs in the
Page_Load of a WebForm app, to IIS on Windows Server 2003.

The app runs without error but doesn't launch notepade. Anty thoughts?

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");


mg said:
I'm sorry, I wasn't clear. The problem is that I don't see notepad when I run
this line of code in Visual Studio .NET on my desktop ....

Nicholas Paldino said:
mg,

If you are hosting a web project in VS.NET 2003, or it is your machine,
then yes, it will show up on your desktop, because the server is on your
machine. However, for anyone outside of your machine connecting, it will
not work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mg said:
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

:

When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the
client
context, and allow you to run programs on that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?


:

How can I run an .exe using C# from within the code behind of a
WebForm
app?

Where do you want to run the .exe? On the client, or the server? You
won't be able to do it on the client. To do it on the server, use
Process.Start.
 
I should add that I can see "notepad.exe" under Processes in Task Manager on
the server. Just no visible notepad app ???

mg said:
I've since formally deployed the simple one-line of code, which runs in the
Page_Load of a WebForm app, to IIS on Windows Server 2003.

The app runs without error but doesn't launch notepade. Anty thoughts?

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");


mg said:
I'm sorry, I wasn't clear. The problem is that I don't see notepad when I run
this line of code in Visual Studio .NET on my desktop ....

Nicholas Paldino said:
mg,

If you are hosting a web project in VS.NET 2003, or it is your machine,
then yes, it will show up on your desktop, because the server is on your
machine. However, for anyone outside of your machine connecting, it will
not work.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

:

When you call the Start method on the Process class, it runs on the
server, so you now have an instance of notepad running on the server.

If you want this to run on the client, you will have to install an
ActiveX control, or a .NET control (with the appropriate security rights)
and then spawn the process from that. These controls will run in the
client
context, and allow you to run programs on that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I put

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");

in Page_Load but notepad did not run. What did I do wrong?


:

How can I run an .exe using C# from within the code behind of a
WebForm
app?

Where do you want to run the .exe? On the client, or the server? You
won't be able to do it on the client. To do it on the server, use
Process.Start.
 
Could you tell me how I can give the ASPNET account additional privileges
beyond the default so that I can make notepad visible on the server?
 
I should add that I can see "notepad.exe" under Processes in Task Manager
on
the server. Just no visible notepad app ???

Any application launched from a service will not have a UI because there is
no logical desktop to display it on. You are launching notepad from a
process that is authenticated as a windows (w3svc) service running in the
user account security context of IUSR_COMPUTERNAME. This user is not
"interactively logged on to a desktop" so nothing it launches has a place to
be displayed. The desktop that you are looking at on your screen is YOUR
user account security context, logged on interactively. They are two
totally different contexts.
 
Could you tell me how I can give the ASPNET account additional privileges
beyond the default so that I can make notepad visible on the server?

It's not an issue of privileges. The reason notepad is not visible on your
desktop is because the www service is a *service*, and therefore has no
access to the desktop. Therefore, anything it launches has no desktop.
 
About the safest way I can think to do this is to launch the process
from the service by PInvoking CreateProcessAsUser. This will allow you
to have the process run with your security credentials.

One of the many params to CreateProcessAsUser is a STARTUPINFO struct
which can tell the system what desktop to put the process on. By
specifying winsta0\default you can get the process to appear on the
desktop.

It just so happens I have some code to demonstate this:
http://odetocode.com/Blogs/scott/archive/2004/10/28/602.aspx
All you'd need to is change the line:

si.lpDesktop = String.Empty;

to
si.lpDesktop = @"winsta0\default";

Let me know if that helps.

P.S. I hope this is just for a local utility and not an actual
production web application.
 
Well, a service can have access to the desktop, for instance, services
running as LocalSystem can have access to the desktop if the "Allow
service to interact with desktop" option is selected, but that's
frowned upon because it's risky.

If the service is not LocalSystem it can still get to the desktop if
given access. This isn't something you can do with pure managed code,
it would take some pinvoking of stuff like SetSecurityDescriptorDacl
and SetUserObjectSecurity. An old technique in debugging least
privileged services was to temporarily give the desktop a null DACL,
essentially allowing anyone to throw something on the dekstop.
 
Back
Top