Re: CreateProcess fuctions

From: Vincent Finn (1_at_2.com)
Date: 08/18/04


Date: Wed, 18 Aug 2004 17:40:52 +0100

Can'r see anything wrong to be honest
The only thing you do differently to me is that I zero the
PROCESS_INFORMATION before use.
I'd be surprised if that is the problem though

I have never used the WindowStation\Desktop calls so at a guess I'd
say they are the problem rather than CreateProccess but that's only a
guess

Sorry I can't be of more help

         Vin

On Tue, 17 Aug 2004 12:19:03 -0700, swt_2k
<swt2k@discussions.microsoft.com> wrote:

># include <windows.h>
># include <iostream>
># include <fstream>
># include <string>
>using namespace std;
>
> BOOL ObtainSid(
>
> HANDLE hToken, // Handle to an process access token.
> PSID *psid // ptr to the buffer of the logon sid
> );
>
> void RemoveSid(
> PSID *psid // ptr to the buffer of the logon sid
> );
>
> BOOL AddTheAceWindowStation(
>
> HWINSTA hwinsta, // handle to a windowstation
> PSID psid // logon sid of the process
> );
>
> BOOL AddTheAceDesktop(
>
> HDESK hdesk, // handle to a desktop
> PSID psid // logon sid of the process
> );
>
> int main(void)
> {
> HANDLE hToken;
> HDESK hdesk;
> HWINSTA hwinsta;
> PROCESS_INFORMATION pi;
> PSID psid;
> STARTUPINFO si;
>
> //
> // obtain an access token for the user fester
> //
> if (!LogonUser(
> "RSPSAdmin",
> ".",
> "rsps4xp",
> LOGON32_LOGON_INTERACTIVE,
> LOGON32_PROVIDER_DEFAULT,
> &hToken
> ))
> return RTN_ERROR;
>
> //
> // obtain a handle to the interactive windowstation
> //
> hwinsta = OpenWindowStation(
> "winsta0",
> FALSE,
> READ_CONTROL | WRITE_DAC
> );
> if (hwinsta == NULL)
> return RTN_ERROR;
>
> HWINSTA hwinstaold = GetProcessWindowStation();
>
> //
> // set the windowstation to winsta0 so that you obtain the
> // correct default desktop
> //
> if (!SetProcessWindowStation(hwinsta))
> return RTN_ERROR;
>
> //
> // obtain a handle to the "default" desktop
> //
> hdesk = OpenDesktop(
> "default",
> 0,
> FALSE,
> READ_CONTROL | WRITE_DAC |
> DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS
> );
> if (hdesk == NULL)
> return RTN_ERROR;
>
> //
> // obtain the logon sid of the user fester
> //
> if (!ObtainSid(hToken, &psid))
> return RTN_ERROR;
>
> //
> // add the user to interactive windowstation
> //
> if (!AddTheAceWindowStation(hwinsta, psid))
> return RTN_ERROR;
>
> //
> // add user to "default" desktop
> //
> if (!AddTheAceDesktop(hdesk, psid))
> return RTN_ERROR;
>
> //
> // free the buffer for the logon sid
> //
> RemoveSid(&psid);
>
> //
> // close the handles to the interactive windowstation and desktop
> //
> CloseWindowStation(hwinsta);
>
> CloseDesktop(hdesk);
>
> //
> // initialize STARTUPINFO structure
> //
> ZeroMemory(&si, sizeof(STARTUPINFO));
> si.cb = sizeof(STARTUPINFO);
> si.lpDesktop = "winsta0\\default";
>
> //
> // start the process
> //
> if (!CreateProcessWithLogonW(
> "RSPSAdmin",
> ".",
> "rsps4xp",
> LOGON_WITH_PROFILE,
> NULL,
> TEXT("java
>com.txdot.isd.rts.services.util.refresh.RSPSRefreshUtility 3"),
> NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE,
> NULL,
> "C:\\rsps\\",
> &si,
> &pi
> ))
> return RTN_ERROR;
>
> SetProcessWindowStation(hwinstaold); //set it back
>
> //
> // close the handles
> //
> CloseHandle(pi.hProcess);
>
> CloseHandle(pi.hThread);
>
> return RTN_OK;
> }
>
>Thanks Vincent...
>
>"Vincent Finn" wrote:
>
>> On Tue, 17 Aug 2004 05:21:03 -0700, swt_2k
>> <swt_2k@discussions.microsoft.com> wrote:
>>
>> >System: XP Pro SP1 w/SDK’s: .NET FrameWork 1.1 & Core SDK
>> >CreateProcessWithLogonW & CreateProcessWithTokenW are undeclared when I
>> >compile .Net Visual C++.
>>
>> include Windows.h and they should be there
>>
>> >I’m trying to user CreatePrcessAsUser (logon on as local Administrator) with
>> >sample code combined from:
>> >http://support.microsoft.com/default.aspx?scid=kb;en-us;165194
>> >http://support.microsoft.com/default.aspx?scid=kb;en-us;131065
>> >
>> >However the process is failing error codes 1313 or 1314. I believe my issues
>> >stem from adjusting the token and or setting the desktop ACL or DACL.
>> >
>> >Thanks for your help…
>>
>> Can you post your actual code, just the relevant bits obviously
>>
>> Vin
>>



Relevant Pages

  • Re: CreateProcess fuctions
    ... I'll zero PROCESS_INFORMATION just to check... ... "Vincent Finn" wrote: ... >> BOOL AddTheAceWindowStation( ... >> int main ...
    (microsoft.public.platformsdk.security)
  • Re: CreateProcess fuctions
    ... BOOL ObtainSid( ... void RemoveSid( ... BOOL AddTheAceWindowStation( ... int main ...
    (microsoft.public.platformsdk.security)