web app that can interact with other applications on the server

S

Steve

I want to make a web application that will run on my home server and would
like to be able to have the web application interact with another, winforms
application. For example, let's say I wanted to go to an aspx page, click a
button called "open notepad", then on ther server machine I would like to
have the web app interact with a service installed on my server that handles
the execution of different files.

Does that makes sense?
 
S

Steve

I tried executing a shell command, no luck

private void Button1_Click(object sender, System.EventArgs e)
{
// open notepad
try
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="notepad";
proc.Start();
Response.Write("Process started...");
}
catch(Exception exception)
{
Response.Write(exception.ToString());
}

}



Hmmm... there must be a way to do this somehow.. anyone have an idea?
 
S

Steve

I have it wrapped in a try block, there are no exceptions. The result of
Start() is true.
This is weird, it just does nothing....

I have change the Virtual Directory "Execute Permissions" to "Scripts and
Executables"
 
B

Bruce Barker

it works, notepad.exe just exits right away with an error because it cannot
create a window. only commandline apps can be run from a webserver

-- bruce (sqlwork.com)
 
S

Steve

wow, I have never tried so many different things and had so little effect.
I've given execute permissions to IUSR_<machine name>
I've tried all different kinds of code snips...

The process starts.. I can see it in task manager on the process tab.. but I
can't "see" it, the window never opens. I have tried:
proc.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Maximized;


This is nuts.. no error, no exception... nothing.
 
S

Steve

the process is still listed in the process list after I kill the asp
process. It seems to still be alive and well, eating memory and all.
I added: <identity impersonate="true" />
to my web config, and now an exception is being thrown:
System.ComponentModel.Win32Exception: Access is denied at
System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
startInfo) at System.Diagnostics.Process.Start()

I'm surprised that I can't configure the webserver to launch a new process,
any process I want and configure on the web server. I could see if I was
trying to launch a process on the client or something crazy like that, but
on the webserver?

Thanks for the response ;)
 
S

Scott Allen

Hi Steve:

Windows has the concept of a windows station. A windows station
contains a desktop. A desktop contains windows [lower case w], a
clipboard, and all those UI and infrastructure pieces we think of as
being a part of Windows.

You can have multiple active winstations. There are two types of win
stations - interactive and non-interacitive. When you log onto a
machine you get an interactive winstation that sends information to a
real display device and takes input from the mouse and keyboard.

Services like IIS and the ASP.NET worker process it spawns are
designed to not interact with a user. They typically start before
anyone is logged into a machine, and stay running after everyone logs
out. Windows gives services a non-interactive windows station. There
is no way to make a non-interactive station an interactive station.

When you start a program from a service, the program starts in the
same winstation that the service is in. When you start Notepad - it is
in an invisible, non-interactive winstation you'll never see.

You can PInvoke CreateProcess and ask windows to put the process into
the interactive winstation, but winstations are also security
boundaries and the ASP.NET worker process will need a lot of
priviledge to do this.

Launching visible GUI applications on a server from ASP.NET is not
something you want to do.
 
S

Steve

Wow Scott, that is an awesome explanation, thanks for taking the time!

Basically, I have a webcam at home so I can watch my dogs from work(they
aren't used to being left alone) and I thought it would be neat if I could
play different MP3s of mine or my girlfriends voice so that we could see
them move ;)

Silly? yes. Kinda weird? yes.

So my idea of executing mp3 files with Process.Start() isn't going to work.
It sounds like I will need to use the pInvoke (not sure what that is yet)
method. I imagine that any RPC or remoting stuff would suffer from the same
interactive/non-interactive domains you mention. The same with getting a
handle on say a winamp.exe process and passing it a filename.

I will read up on PInvoke. Thanks again for the post.


Scott Allen said:
Hi Steve:

Windows has the concept of a windows station. A windows station
contains a desktop. A desktop contains windows [lower case w], a
clipboard, and all those UI and infrastructure pieces we think of as
being a part of Windows.

You can have multiple active winstations. There are two types of win
stations - interactive and non-interacitive. When you log onto a
machine you get an interactive winstation that sends information to a
real display device and takes input from the mouse and keyboard.

Services like IIS and the ASP.NET worker process it spawns are
designed to not interact with a user. They typically start before
anyone is logged into a machine, and stay running after everyone logs
out. Windows gives services a non-interactive windows station. There
is no way to make a non-interactive station an interactive station.

When you start a program from a service, the program starts in the
same winstation that the service is in. When you start Notepad - it is
in an invisible, non-interactive winstation you'll never see.

You can PInvoke CreateProcess and ask windows to put the process into
the interactive winstation, but winstations are also security
boundaries and the ASP.NET worker process will need a lot of
priviledge to do this.

Launching visible GUI applications on a server from ASP.NET is not
something you want to do.

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


wow, I have never tried so many different things and had so little effect.
I've given execute permissions to IUSR_<machine name>
I've tried all different kinds of code snips...

The process starts.. I can see it in task manager on the process tab.. but I
can't "see" it, the window never opens. I have tried:
proc.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Maximized;


This is nuts.. no error, no exception... nothing.



click
a
 
S

Scott Allen

Wow Scott, that is an awesome explanation, thanks for taking the time!

Basically, I have a webcam at home so I can watch my dogs from work(they
aren't used to being left alone) and I thought it would be neat if I could
play different MP3s of mine or my girlfriends voice so that we could see
them move ;)

Silly? yes. Kinda weird? yes.

So my idea of executing mp3 files with Process.Start() isn't going to work.
It sounds like I will need to use the pInvoke (not sure what that is yet)
method. I imagine that any RPC or remoting stuff would suffer from the same
interactive/non-interactive domains you mention. The same with getting a
handle on say a winamp.exe process and passing it a filename.

I will read up on PInvoke. Thanks again for the post.

Ah, well, if this is for fun then let's find a solution!!

You could use remoting to communicate between ASP.NET and a program
running on your desktop - that's not a bad idea.

Another idea would be to have the Aspx page write a file into a
specific directory. Perhaps the file contains some parameters in XML.
Then have a program that runs on your home desktop and monitors the
directory for a new file (use System.IO.FileSystemWatcher). The
program could read the parameters from the file and execute whatever
command you need.

Just be very careful about taking input from the web and ultimately
sending it to another program that executes other programs. You
wouldn't want the unscrupulous type to find your web server and
somehow have it execute "format c:".
 
S

Steve

Your File system solution is clever, I like that!
However, remoting seems the cleanest and safest. I will look into this and
let you know what I find out. Thanks again for the response, I have renewed
hope ;)
 
S

Steve

Scott Allen said:
Ah, well, if this is for fun then let's find a solution!!

You could use remoting to communicate between ASP.NET and a program
running on your desktop - that's not a bad idea.

Another idea would be to have the Aspx page write a file into a
specific directory. Perhaps the file contains some parameters in XML.
Then have a program that runs on your home desktop and monitors the
directory for a new file (use System.IO.FileSystemWatcher). The
program could read the parameters from the file and execute whatever
command you need.

Just be very careful about taking input from the web and ultimately
sending it to another program that executes other programs. You
wouldn't want the unscrupulous type to find your web server and
somehow have it execute "format c:".


wow, this sounds perfect

" The Task Server can take any object that implements the simple ITask
interface, and run it within its own Application Domain. What's more, it can
accept tasks from multiple clients at one time. "
http://www.csharphelp.com/archives/archive187.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top