Problem starting windows forms application from ASP.Net 2.0

Q

Quille

Hi !

I'm having trouble starting desktop windows forms application with gui.
So far i have managed to make it run when I access website on local
computer,
trying to start application from any other machine fails.

I have modified machine.config process model as follows:
<processModel autoConfig="true" userName="SYSTEM" password="AutoGenerate" />

Now aspnet worker process is running under SYSTEM account.

Im using Windows authentication and Im impersonating currently logged user
so my web config contains:
<authentication mode="Windows" />
<identity impersonate="true" />

Platform is Windows XP and User is automatically logged in to desktop.

Code for starting process is below...

Please tell me what am I doing wrong, point me in right direction, thank you
!

Goran


Code:
private bool NativeProcessStart()
{
string locError = string.Empty;
// Impersonation constants
const uint GENERIC_ALL = 0x10000000;
const int SecurityImpersonation = 2;
const int TokenType = 1;
IntPtr Token = new IntPtr(0);
IntPtr DupedToken = new IntPtr(0);
bool ret;

// Init sceurity attribures struct
SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
sa.bInheritHandle = false;
sa.Length = Marshal.SizeOf(sa);
sa.lpSecurityDescriptor = (IntPtr)0;

// Get Impersonated user token
Token = WindowsIdentity.GetCurrent().Token;
// Duplicate Impersonated user token
ret = DuplicateTokenEx(Token,GENERIC_ALL,ref
sa,SecurityImpersonation,TokenType,ref DupedToken);
if (false == ret)
{
return ret;
}

STARTUPINFO si = new STARTUPINFO();
si.cb = Marshal.SizeOf(si);
si.lpDesktop = "";
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

ret = CreateProcessAsUser(DupedToken, null,
this._playerPath + " " + this._playerParams, ref sa, ref sa, false, 0,
(IntPtr)0,
System.IO.Path.GetDirectoryName(this._playerPath),ref si,out pi);

if (false == ret)
{
return ret;
}

CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ret = CloseHandle(DupedToken);
return ret;
}
 
M

MikeS

So you are trying to run a windows forms application right there on the
web server for a user who is visiting your site?

Or is all that CreateProcessAsUser code supposed to go over the network
and start a process on their PC?

How is it that running your web app as SYSTEM and starting up programs
on other peoples PC's from a web server is a good idea?

I think one way to give them a windows forms app to run is to use
"click once deployment" and publish that app to the web server.

http://msdn2.microsoft.com/en-us/library/t71a733d.aspx
 
Q

Quille

Hi !
Thanks for fast response ...

MikeS said:
So you are trying to run a windows forms application right there on the
web server for a user who is visiting your site?

I'm trying to make web interface for windows forms application similar to
Mediaportal and it's web interface....

Or is all that CreateProcessAsUser code supposed to go over the network
and start a process on their PC?
No just on PC hosting web.
How is it that running your web app as SYSTEM and starting up programs
on other peoples PC's from a web server is a good idea?
No this is not good ides and it is not my intention ...
I think one way to give them a windows forms app to run is to use
"click once deployment" and publish that app to the web server.

http://msdn2.microsoft.com/en-us/library/t71a733d.aspx

I'm not trying to distribute application over web, im just traing to control
it over web :)

Thnaks for comments once again,

Goran
 
M

MikeS

OK, well if it is all going to run client side, then why not run it all
client side, controls and or code in the browser not on the server.

For example:

http://www.15seconds.com/issue/030610.htm

Then you might just use Process.Start without needing impersonation.
From a Full Trust site, this works for me...

<object id="UserControl1"
classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1"
height="0" width="0"> </object>

Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim psi As New ProcessStartInfo("calc.exe")
Process.Start(psi)
End Sub
 
Q

Quille

Hi again !

MikeS said:
OK, well if it is all going to run client side, then why not run it all
client side, controls and or code in the browser not on the server.

Actaully I'm trying to make folowing scenarios to work:
1.) Machine (Server) running program ("Player") similar to powerpoint that
uses managed directx for display that software is controled using asp.net
web site and remoting.
In this scenario user can open "Player" on one monitor and IE containig UI
on another monitor.
In this scenario I'm able to start player from web ui and everything works
fine

2.) Machine (Server) running "Player" and Machine(Client) running IE
containing UI for Player
In this scenario I can't start player from web UI and I would like to make
it possible...

Anyway thanks for comments...
For example:

http://www.15seconds.com/issue/030610.htm

Then you might just use Process.Start without needing impersonation.


<object id="UserControl1"
classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1"
height="0" width="0"> </object>

Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim psi As New ProcessStartInfo("calc.exe")
Process.Start(psi)
End Sub

Goran
 
M

MikeS

OK, I see, I am thick.

That's a good question.

So will someone be logged into the web server all the time, will there
be an interactive session open?
 
Q

Quille

Hi again!

MikeS said:
OK, I see, I am thick.

That's a good question.

So will someone be logged into the web server all the time, will there
be an interactive session open?

Yes "server" will perform automatic logon, this is acutally must, because I
don't think I can force start of
windows forms application before some one is logged to console.

Thanks,
Goran
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top