By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

Run an .exe

P: n/a
mg
How can I run an .exe using C# from within the code behind of a WebForm app?
Nov 16 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
mg <mg@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
mg
I put

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

in Page_Load but notepad did not run. What did I do wrong?
"Jon Skeet [C# MVP]" wrote:
mg <mg@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
I put

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

in Page_Load but notepad did not run. What did I do wrong?
"Jon Skeet [C# MVP]" wrote:
mg <mg@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

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

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
I put

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

in Page_Load but notepad did not run. What did I do wrong?
"Jon Skeet [C# MVP]" wrote:
mg <mg@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #5

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
>I put
>
> System.Diagnostics.Process.Start("C:\\WINDOWS\\sys tem32\\notepad.exe");
>
> in Page_Load but notepad did not run. What did I do wrong?
>
>
> "Jon Skeet [C# MVP]" wrote:
>
>> mg <mg@discussions.microsoft.com> wrote:
>> > 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.
>>
>> --
>> Jon Skeet - <sk***@pobox.com>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>>


Nov 16 '05 #6

P: n/a
mg
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
>I put
>
> System.Diagnostics.Process.Start("C:\\WINDOWS\\sys tem32\\notepad.exe");
>
> in Page_Load but notepad did not run. What did I do wrong?
>
>
> "Jon Skeet [C# MVP]" wrote:
>
>> mg <mg@discussions.microsoft.com> wrote:
>> > 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.
>>
>> --
>> Jon Skeet - <sk***@pobox.com>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>>


Nov 16 '05 #7

P: n/a
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.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 3 Nov 2004 14:36:00 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
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.


--
Scott
http://www.OdeToCode.com/
Nov 16 '05 #8

P: n/a
mg
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\\sys tem32\\notepad.exe");
"mg" wrote:
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
The code is run in Visual Studio .NET 2003 on my desktop, so I should see
the
notepad ... I think ... ???

"Nicholas Paldino [.NET/C# MVP]" wrote:

> 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]
> - mv*@spam.guard.caspershouse.com
>
> "mg" <mg@discussions.microsoft.com> wrote in message
> news:6B**********************************@microsof t.com...
> >I put
> >
> > System.Diagnostics.Process.Start("C:\\WINDOWS\\sys tem32\\notepad.exe");
> >
> > in Page_Load but notepad did not run. What did I do wrong?
> >
> >
> > "Jon Skeet [C# MVP]" wrote:
> >
> >> mg <mg@discussions.microsoft.com> wrote:
> >> > 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.
> >>
> >> --
> >> Jon Skeet - <sk***@pobox.com>
> >> http://www.pobox.com/~skeet
> >> If replying to the group, please do not mail me too
> >>
>
>
>


Nov 16 '05 #9

P: n/a
mg
I should add that I can see "notepad.exe" under Processes in Task Manager on
the server. Just no visible notepad app ???

"mg" wrote:
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\\sys tem32\\notepad.exe");
"mg" wrote:
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"mg" <mg@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
> The code is run in Visual Studio .NET 2003 on my desktop, so I should see
> the
> notepad ... I think ... ???
>
> "Nicholas Paldino [.NET/C# MVP]" wrote:
>
>> 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]
>> - mv*@spam.guard.caspershouse.com
>>
>> "mg" <mg@discussions.microsoft.com> wrote in message
>> news:6B**********************************@microsof t.com...
>> >I put
>> >
>> > System.Diagnostics.Process.Start("C:\\WINDOWS\\sys tem32\\notepad.exe");
>> >
>> > in Page_Load but notepad did not run. What did I do wrong?
>> >
>> >
>> > "Jon Skeet [C# MVP]" wrote:
>> >
>> >> mg <mg@discussions.microsoft.com> wrote:
>> >> > 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.
>> >>
>> >> --
>> >> Jon Skeet - <sk***@pobox.com>
>> >> http://www.pobox.com/~skeet
>> >> If replying to the group, please do not mail me too
>> >>
>>
>>
>>

Nov 16 '05 #10

P: n/a
mg
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?
"Scott Allen" wrote:
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.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 3 Nov 2004 14:36:00 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
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.


--
Scott
http://www.OdeToCode.com/

Nov 16 '05 #11

P: n/a
>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.
--
Peace & happy computing,

Mike Labosh, MCSD
"I have no choice but to believe in free will."
Nov 16 '05 #12

P: n/a
> 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.
--
Peace & happy computing,

Mike Labosh, MCSD
"I have no choice but to believe in free will."
Nov 16 '05 #13

P: n/a
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/arc...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.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Wed, 3 Nov 2004 12:49:12 -0800, "mg" <mg@discussions.microsoft.com>
wrote:
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?


Nov 16 '05 #14

P: n/a
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.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 3 Nov 2004 16:40:18 -0500, "Mike Labosh" <ml*****@hotmail.com>
wrote:
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.


Nov 16 '05 #15

P: n/a
Create a Process object and run the application with the Process object.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.