🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10104

CreateProcessAsUser and Privileges

#10104
From: Stefano Bonifazi
Date: Fri, 14 May 2004 17:43
76 lines
3557 bytes
Hello Everybody!:-)
 I have an external application (that is a exe without its code) that fails
to execute under a WinXP OS with accounts that do not have administrative
rights. Its problem is that it tries to access the HKEY_LOCAL_MACHINE key
with write rights (that it does not own!!)
I thought to write a my application that launches it with
CreateProcessAsUser cause I know both User and password of an
Administrator...
First I use the LogonUser API to get the Administrator token handle:

HANDLE hToken;              // handle to process token
if(! LogonUser(

    UserNameEdit->Text.c_str(), // string that specifies the user name
    NULL, // string that specifies the domain or server
    PasswordEdit->Text.c_str(), // string that specifies the password
    LOGON32_LOGON_BATCH , // specifies the type of logon operation
    LOGON32_PROVIDER_DEFAULT, // specifies the logon provider
    &hToken // pointer to variable to receive token handle
  ))
 {
   ...
  }

Then I actually call the CreateProcessAsUser API:

   STARTUPINFO SI;
   ZeroMemory(&SI,sizeof(STARTUPINFO));
   SI.lpReserved=NULL;
   SI.cb=sizeof(STARTUPINFO);

   PROCESS_INFORMATION PI;
   ZeroMemory(&PI,sizeof(PROCESS_INFORMATION));


   if(!CreateProcessAsUser( hToken,
                            ProgramFileNameEdit->Text.c_str(),
                            NULL,
                            NULL,
                            NULL,
                            FALSE,
                            NORMAL_PRIORITY_CLASS,
                            NULL,
                            NULL,
                            &SI,
                            &PI
                            ))
{
 ...
}

But it fails and with GetLastError I find it complains cause it does not
have the required privilege (but does not say which!!!!)

So I tried to set SE_ASSIGNPRIMARYTOKEN_NAME and SE_INCREASE_QUOTA_NAME
privileges before calling CreateProcessAsUser:

   TOKEN_PRIVILEGES tkp;       // pointer to token structure
   LookupPrivilegeValue(NULL,
SE_ASSIGNPRIMARYTOKEN_NAME,&tkp.Privileges[0].Luid);
   LookupPrivilegeValue(NULL,
SE_INCREASE_QUOTA_NAME,&tkp.Privileges[1].Luid);


   tkp.PrivilegeCount = 2;  // two privilege to set
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
   tkp.Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;

   AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);

But AdjustTokenPrivileges always fails!!!

May anybody help me?? Mr. Gambit it sounds like your domain :-)

Thank You very much in advance!!!!
Stefano B.
Technical Details
Message-ID: <40a5055b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,5fb91eec7fd7a1d9,start
X-Google-Attributes: gid10cc67,public
Reply-To: "Stefano Bonifazi" <stefboombastic@libero.it>
From: "Stefano Bonifazi" <stefboombastic@libero.it>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: CreateProcessAsUser and Privileges
Date: Fri, 14 May 2004 19:43:55 +0200
Lines: 78
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 212.141.200.11
Message-ID: <40a5055b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1084556635 212.141.200.11 (14 May 2004 10:43:55 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail