Article View: borland.public.cppbuilder.nativeapi
Article #8682Getting admistrator priviliges temporarily
From: Fatih Ekinci
Date: Sun, 26 Sep 2004 06:44
Date: Sun, 26 Sep 2004 06:44
50 lines
2083 bytes
2083 bytes
Hi,
I need getting admistrator priviliges temporarily in order to change a
registry key value under HKEY_LOCAL_MACHINE,
after starting a computer in user mode. Using following code, I can manage
it in Windows XP, but it fails in Windows 2000.
What am I missing? Help please!
Thanks!
Fatih
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HANDLE MySecToken;
if (!IsAdmin()) {
if (LogonUser("Administrator", NULL, "AdminPass",
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &MySecToken)) {
ImpersonateLoggedOnUser(MySecToken);
}
else MessageBox (NULL, "Logon Admin problem!", "AdminReg", MB_OK);
}
TRegistry *MyReg;
MyReg = new TRegistry;
MyReg->RootKey = HKEY_LOCAL_MACHINE;
if (MyReg->OpenKey("\\Software\\aaa", true)){
try {
MyReg->WriteInteger ("ValueName", intValue);
}
catch (...){
;
}
}
else MessageBox (NULL, "Registry operation failure!", "Registry problem",
MB_OK);
if (!IsAdmin()) RevertToSelf();
CloseHandle(MySecToken);
delete MyReg;
}
//--------------------------------------------------------------------------
-
Technical Details
Message-ID:
<41566608@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f4e17b02ce5b6ff3,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Fatih Ekinci" <fekinci42@ttnet.net.tr> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Getting admistrator priviliges temporarily Date: Sun, 26 Sep 2004 09:44:11 +0300 Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 81.212.0.9 Message-ID: <41566608@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096181256 81.212.0.9 (25 Sep 2004 23:47:36 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail