Run .exe in C# .aspx.cs

  • Thread starter Thread starter Guest
  • Start date Start date
I put

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

in Page_Load but WordPad did not run. What did I do wrong?
 
Hi mg:


Let me try to explain what is happening.

ASP.NET is a server side process and by default runs under a different
Windows account (typically the ASPNET account) than a user would use.
When you start a process from an ASP.NET page it will launch for the
ASPNET user (you'll probably find Notepad in the list of running
processes in task manager), but ASPNET does not interact with the
desktop (the user interface), so notepad doesn't appear.

If you think about it, this makes sense. If I hit msn.com with a web
browser it doesn't make any sense for msn to launch notepad on thier
server. Even it showed up on the server's desktop I wouldn't be able
to see it from my computer. It's server side code and a server side
process.

If you want to launch notepad on the client machine, you'll need to
use client side script, but you'll need the client to trust you first
because noone wants websites to launch processes on thier machine
willy nilly.
 
Well, your answer is better than mine. I was going to say that executing
NotePad.exe would never launch WordPad...

;-)

--
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
I'm running the code in Visual Studio .NET on my desktop, so I should see the
notpad ... I think ... ???
 
No, you are logged in under a different account than the asp.net
worker process I'm sure. The worker process just can't throw up
windows on the desktop you own - there are security permissions and
access checks involved, just like the ones the system checks when you
try to read a file from an NTFS disk.
 
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 notepad. Any thoughts?

System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\notepad.exe");
 
I should add that I can see "notepad.exe" under Processes in Task Manager on
the server. Just no visible notepad app ???
 
I now understand that 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, notepad will be
invisible. How can I give the worker process the neccessary privileges (or do
something else) to make notepad visible?
 
It could be if you use notepad to open a very large file, then notepad will
suggest you to open it in wordpad instead. :P
 
Back
Top