CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    1

    create process not working correctly from a service on windows xp

    I am trying to write a program which opens a notepad application on windows XP machine. I have used the createprocess() function to acheive this. If i open the command prompt and run my program, the note pad application opens up without any problem.

    I tried run the same application as a service it displays a part of the GUI for note pad. I have passed on "winsta0\default" as the desktop with the startup parameters to the createprocess application. The user who is running the service is same as the loggedon user.

    I tried to run the same executable on a win2k machine as a service, the notepad application opens without any problems. Can anyone help me out to solve this problem.

    The code looks like this and the input to this would be the application I would be launching ie notepad.exe.

    I would be thankful to anyone who would helpme out with this.
    ------------------------------------------------------------------------------------
    #include <windows.h>
    #include <iostream.h>
    void main (int argc , char * argv[])
    {
    void fnc_CreateProcess(char *);
    fnc_CreateProcess(argv[1]);
    }
    void fnc_CreateProcess(char * command)
    {
    STARTUPINFO si;
    HDESK hdesk;
    HWINSTA hwinsta;
    SECURITY_ATTRIBUTES saProcess, saThread;
    PROCESS_INFORMATION piProcess;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    si.lpDesktop = "winsta0\\Default";
    saProcess.nLength = sizeof(saProcess);
    saProcess.lpSecurityDescriptor = NULL;
    saProcess.bInheritHandle = TRUE;
    saThread.nLength = sizeof(saThread);
    saThread.lpSecurityDescriptor = NULL;
    saThread.bInheritHandle = FALSE;
    cout << "The command is " << command << "\n";
    // HANDLE hToken;
    //


    hwinsta = OpenWindowStation(
    "winsta0",
    TRUE,
    READ_CONTROL | WRITE_DAC | GENERIC_ALL
    );
    hdesk = OpenDesktop(
    "default",
    0,
    FALSE,
    READ_CONTROL | WRITE_DAC |
    DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |GENERIC_ALL
    );

    if (!SetProcessWindowStation(hwinsta))
    cout << "Error";

    CloseWindowStation(hwinsta);

    CloseDesktop(hdesk);


    BOOL bRetVal = CreateProcess(NULL, command, &saProcess, &saThread, FALSE,
    0, NULL, NULL,&si, &piProcess);*/

    PHANDLE phToken = NULL;


    if (bRetVal)
    cout<< "success";
    else

    cout << TEXT(GetLastError());
    }

    ------------------------------------------------------------------------------------

  2. #2
    Join Date
    Aug 2010
    Posts
    1

    Re: create process not working correctly from a service on windows xp

    Hi, I still have this problem.
    Did you resolve it ?
    Regards

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: create process not working correctly from a service on windows xp

    This might help.
    Best regards,
    Igor

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