Problem starting windows forms application from ASP.Net 2.0

Discussion in 'ASP .Net Security' started by Quille, Aug 27, 2006.

  1. Quille

    Quille Guest

    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;
    }
    Quille, Aug 27, 2006
    #1
    1. Advertising

  2. Quille

    MikeS Guest

    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
    MikeS, Aug 27, 2006
    #2
    1. Advertising

  3. Quille

    Quille Guest

    Hi !
    Thanks for fast response ...

    "MikeS" <> wrote in message
    news:...
    > 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
    Quille, Aug 27, 2006
    #3
  4. Quille

    MikeS Guest

    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
    MikeS, Aug 27, 2006
    #4
  5. Quille

    Quille Guest

    Hi again !

    "MikeS" <> wrote in message
    news:...
    > 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.
    >
    >>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
    >


    Goran
    Quille, Aug 28, 2006
    #5
  6. Quille

    MikeS Guest

    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?
    MikeS, Aug 28, 2006
    #6
  7. Quille

    Quille Guest

    Hi again!

    "MikeS" <> wrote in message
    news:...
    > 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
    Quille, Aug 29, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. varun varun
    Replies:
    0
    Views:
    395
    varun varun
    Jul 3, 2003
  2. Lenny
    Replies:
    3
    Views:
    2,446
    Lenny
    Jul 8, 2003
  3. Raju
    Replies:
    1
    Views:
    1,816
    Rajesh.V
    Oct 29, 2003
  4. Fabian Steiner
    Replies:
    1
    Views:
    613
    faulkner
    Jul 17, 2006
  5. Eric
    Replies:
    2
    Views:
    482
Loading...

Share This Page