Writing to Registry
-
Use BOOL IsUserAnAdmin(VOID); Perform writing to the registry only if this function returns true.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
CPallini wrote:
Nope. Go back home and get the telescope. [Poke tongue]
Sorry, but I see the question was not "very urgent", so I could ask the OP to take some time to let me know more of the error.
CPallini wrote:
BTW: Eventually MFC appeared in your profile [Big Grin]
:-O :-\
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
Rajesh R Subramanian wrote:
Sorry, but I see the question was not "very urgent", so I could ask the OP to take some time to let me know more of the error.
You're wrong:
"very urgent"
it's the default."Plz plz very urgent"
is the courtesy form. :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Rajesh R Subramanian wrote:
Sorry, but I see the question was not "very urgent", so I could ask the OP to take some time to let me know more of the error.
You're wrong:
"very urgent"
it's the default."Plz plz very urgent"
is the courtesy form. :-DIf the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]"Attack of the Urgent Monkeys" :laugh: BTW, we're dangerously close to hijack this thread. :suss:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
Here is the code for IsUserAdmin
BOOL IsUserAdmin(VOID) /*++ Routine Description: This routine returns TRUE if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyone and is expected to be able to open its own process and process token. Arguments: None. Return Value: TRUE - Caller has Administrators local group. FALSE - Caller does not have Administrators local group. -- */ { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) { b = FALSE; } FreeSid(AdministratorsGroup); }
-
"Attack of the Urgent Monkeys" :laugh: BTW, we're dangerously close to hijack this thread. :suss:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Here is the code for IsUserAdmin
BOOL IsUserAdmin(VOID) /*++ Routine Description: This routine returns TRUE if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyone and is expected to be able to open its own process and process token. Arguments: None. Return Value: TRUE - Caller has Administrators local group. FALSE - Caller does not have Administrators local group. -- */ { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid( &NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); if(b) { if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) { b = FALSE; } FreeSid(AdministratorsGroup); }
-
The function information of IsUserAnAdmin() says - "Shell32.DLL version 5.0 or higher will be required" to make use of this call, which means earlier versions won't have this function exported at all. See here[^]. You'll need the latest SDK (or the SDK which is latest enough and has version 5.0 or higher of Shell32.DLL) to use this call.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]
-
Thanks.. But I written a user define function and written the above code.. I am getting a compilation error at CheckTokenMembership...
You should do the following: Header: Declared in Winbase.h; include Windows.h. Library: Use Advapi32.lib And look for Advapi32.dll. Check out MSDN for more details
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Do you have the Feb 2003 version of the Platform SDK?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hi, My application writes into a particular location in Registry Eg. RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &h_Key); //Open a particular registry key //Write to that registry key. I need to restrict this activity to only Administrator.. Can I have a code snippet which allows this only for Administrator. Thanks. Venkat
If you can speak Chinese,you can go to"www.csdn.net" .He will help you ! :)