CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2008
    Posts
    43

    Create Process doesn't show any window

    Hi there,
    i'm having problems creating a process inside a service, which runs as a user (not LocalSystem).
    The issue is that it creates the process, but without showing the dialog of the application or the tray icon. I can say that the application works fine, cause it is a kind of alerter that play a sound when an event occurs.

    The user is the default user, which it's constantly logged in.
    I've tried with both ShellExecute and CreateProcess obtaining the same results.

    Running the service as LocalSystem (with the SERVICE_INTERACTIVE_PROCESS flag) instead created the process and showed the dialog and the icon.

    I must run it as that specific user cause that executable reads some opts (ie:username) from an .ini which is used by other components.

    Have any idea?

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Create Process doesn't show any window

    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jun 2008
    Posts
    43

    Re: Create Process doesn't show any window

    HANDLE hToken;

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    LogonUser( _T("user"),
    _T("."),
    _T("password"),
    LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT,
    &hToken);


    CreateProcessAsUser( hToken,
    _T("C:\\the\\App.exe"),
    NULL,
    NULL,
    NULL,
    FALSE,
    CREATE_NEW_PROCESS_GROUP,
    NULL,
    _T("C:\\wp"),
    &si,
    &pi);

    CloseHandle(hToken);
    Where am I wrong? I get the app running, it shows the dialog, but it crashes instantly...
    Last edited by Enrorr; March 22nd, 2010 at 04:00 PM.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Create Process doesn't show any window

    Quote Originally Posted by Enrorr View Post
    Where am I wrong? I get the app running, it shows the dialog, but it crashes instantly...
    What happens when you step through the code in a debugger? Why aren't you checking the return values of the api calls?

    At any rate, even if you get this running are you aware that this approach won't work on Vista or Win7?

  5. #5
    Join Date
    Jan 2005
    Location
    germany
    Posts
    160

    Re: Create Process doesn't show any window

    Did you read the article, CILU pointed you to? Why not?

    Services do not have a desktop to interact with (unless they run as local system and are configured "interactive").
    However you can pass information about the desktop in the STARTUPINFO structure of CreateProcess (AsUser).

    See http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    and http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    regards
    HoM

  6. #6
    Join Date
    Jun 2008
    Posts
    43

    Re: Create Process doesn't show any window

    Quote Originally Posted by Arjay View Post
    What happens when you step through the code in a debugger? Why aren't you checking the return values of the api calls?

    At any rate, even if you get this running are you aware that this approach won't work on Vista or Win7?
    That was just a quick post. I checked the returns and everything's fine.

    I think that shouldn't work on vista/win 7. But I'm just helping a co-worker with some legacy monitoring software that just runs on win xp.

    Since it's a service and I have about no knowledge in programming, I couldn't figure out how to debug a running service.

    @HoM:
    Yeah i read it, indeed running it as SYSTEM and interactive works.
    So tell if I'm understanding the whole thing: a service running as the user who is currently logged in (or another user apart from SYSTEM) can't interact with the desktop, unless I specify the desktop, since "If the thread did not call SetThreadDesktop, it connects to the desktop inherited from the parent process" and since the parent process is a service my new process can't get the desktop the human user is currently using?

    By the way, I'm curious how the desktops are named? I've seen that OpenDesktop wants a string as input.

    Oh and thanks everybody for the hints and patience
    Last edited by Enrorr; March 23rd, 2010 at 02:23 PM.

  7. #7
    Join Date
    Jan 2005
    Location
    germany
    Posts
    160

    Re: Create Process doesn't show any window

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    is about EnumDesktops, which can give you the info about all Desktops of a Windowstation in a Callback function

    EnumWindowStations can be used to enumerate WindowStations. So with this you can get every information.

    BTW: The default Windowstation from an interactive login is "Winsta0", the default Desktop is named "default"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured