Click here to Skip to main content
13,096,399 members (52,511 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 24 Apr 2010

WMI Namespace Security with C/C++

, 6 Sep 2012
Rate this:
Please Sign up or sign in to vote.
A program to operate WMI Namespace Security with Windows Native APIs which are supported on Windows 2000/XP/2003/2008/7.


When I try to operate WMI namespace security, I find that there are several script solutions that depend on the APIs GetSecurityDescriptor and SetSecurityDescriptor . These two APIs are not available on Windows NT/2000/XP/2003.

And I found a C# solution at CodeProject, but it still depends on the .NET Framework, and cannot be used on a fresh XP environment.

So I decided to write a program to operate WMI Namespace Security with Windows Native APIs which are supported on Windows 2000/XP/2003/2008/7. Then I found there's lack of material about this topic, so I decided to write this article~~~

About the code

The code is easy to read and understand. It's a little tricky to invoke the methods of the system class of __SystemSecurity in the WMI namespace. We have to use GetMethod and ExecMethod to invoke the GetSD/SetSD APIs.

Here is the code sequence to invoke APIs in __SystemSecurity:

// Get system class of __SystemSecurity
hres = pSvc->GetObject(ClassPath, 0, NULL, &pClass, NULL);
// Get method GetSD
hres = pClass->GetMethod(methodGetSD, 0, &pGetSD_InClass, &pGetSD_OutClass);
// Execute method GetSD, to get original SD
hres = pSvc->ExecMethod(ClassPath, methodGetSD, 0, NULL, pGetSD_InClass, &pGetSD_OutInst, NULL);
hres = pGetSD_OutInst->Get(L"SD", 0, &varRes, NULL, 0);

And the usage of the program is takes reference from the C# sample, thanks to J_Madden.

C:\> WmiSecurity.exe -n ROOT\CIMv2 -u DOMAIN\My_Account -s REMOTEACCESS -r 

Currently I have only implemented the connector to the local machine, but a WMI remote connector is not a difficult task~~~


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionNot able to download the code Pin
Vishal D3-Sep-12 22:45
memberVishal D3-Sep-12 22:45 
GeneralMy vote of 1 Pin
SledgeHammer0125-Apr-10 7:53
memberSledgeHammer0125-Apr-10 7:53 
GeneralRe: My vote of 1 Pin
zoufeiyy25-Mar-12 2:48
memberzoufeiyy25-Mar-12 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 6 Sep 2012
Article Copyright 2010 by zoufeiyy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid