Click here to Skip to main content
15,916,091 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCrypt32.dll Pin
Tuscon24-May-05 17:42
Tuscon24-May-05 17:42 
GeneralRe: Crypt32.dll Pin
BlackDice25-May-05 6:30
BlackDice25-May-05 6:30 
Generalmaking packets Pin
_tasleem24-May-05 16:24
_tasleem24-May-05 16:24 
Questionhow to react when user click the same tree item Pin
Lido Paul24-May-05 14:35
Lido Paul24-May-05 14:35 
AnswerRe: how to react when user click the same tree item Pin
PJ Arends24-May-05 16:05
professionalPJ Arends24-May-05 16:05 
GeneralWin32_WindowsProductActivation with C++ Pin
24-May-05 12:38
suss24-May-05 12:38 
GeneralRe: Win32_WindowsProductActivation with C++ Pin
Aamir Butt24-May-05 23:49
Aamir Butt24-May-05 23:49 
GeneralRe: Win32_WindowsProductActivation with C++ Pin
25-May-05 12:51
suss25-May-05 12:51 
Hi Aamir,

Thanks for your reply. I don't have problems extracting informations from
Win32_WindowsProductActivation class properties. I have problem using the class methods. In this function i'm trying to pass new product key and change existing one. Can i do it with this SetProductKey method???? or need to use Put method?? Your help is very appreciated. Also well done on that article.

void CKeyFinder::SetWinKey(char * newkey)
{

CoInitialize(NULL);
//Security needs to be initialized
if(CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0
) != S_OK)
return;
IWbemLocator *pIWbemLocator = NULL;
IWbemServices *pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");

if(CoCreateInstance(
CLSID_WbemLocator,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) != S_OK)
return;

if(pIWbemLocator->ConnectServer(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
) != S_OK)
return;


HRESULT hRes;
//IWbemServices pointer to make requests of WMI
BSTR strQuery = (L"Select * from Win32_WindowsProductActivation");
BSTR strQL = (L"WQL");
hRes = pWbemServices->ExecQuery(strQL, strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
if(hRes != S_OK)
{
AfxMessageBox("Could not execute Query");
return;
}
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
IWbemClassObject * piObj = NULL;

hRes = pEnumObject->Reset();
if(hRes != S_OK)
{
AfxMessageBox("Could not Enumerate");
return;
}
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
if(hRes != S_OK)
{
AfxMessageBox("Could not Enumerate");
return;
}


CString csWin32Activation ("Win32_WindowsProductActivation");
CComBSTR bstrWin32Activation (csWin32Activation);
hRes = pWbemServices->GetObject(bstrWin32Activation,WBEM_FLAG_RETURN_WBEM_COMPLEATE,NULL,&piObj,NULL);

//get the input class for the SetProductKey method
CString csSetProductKey ("SetProductKey");
CComBSTR bstrSetProductKey (csSetProductKey);
hRes = pClassObject->GetMethod(bstrSetProductKey,0,&pClassObject,NULL);

hRes = pClassObject->SpawnInstance(0,&pClassObject);

//SetProductKey takes one argument uint32 SetProductKey(string ProductKey);
CComBSTR bstrNewKey (newkey);
VARIANT v;
VariantInit(&v);
v.vt = VT_BSTR;
v.bstrVal = (BSTR)bstrNewKey;

pClassObject->Put(L"SettingID",0,&v,0);

//Problem is here
//execute the method
// CString csObjName = bstrNamespace + csWin32Activation + "." + "
// CComBSTR bstrObjName(csObjName);
// hRes = pWbemServices->ExecMethod(bstrObjName,bstrSetProductKey,0,NULL,pClassObject,0,NULL);

//error check
if (FAILED(hRes)) {
AfxMessageBox("Could not exec SetProductKey method",hRes);
return;
}

//clean up
VariantClear( &v );
pIWbemLocator->Release();
pWbemServices->Release();
pEnumObject->Release();
pClassObject->Release();
CoUninitialize();
GeneralRe: Win32_WindowsProductActivation with C++ Pin
Aamir Butt25-May-05 19:25
Aamir Butt25-May-05 19:25 
GeneralRe: Win32_WindowsProductActivation with C++ Pin
David Crow25-May-05 4:06
David Crow25-May-05 4:06 
GeneralRe: Win32_WindowsProductActivation with C++ Pin
macakd25-May-05 13:02
macakd25-May-05 13:02 
GeneralRe: Win32_WindowsProductActivation with C++ Pin
David Crow26-May-05 2:25
David Crow26-May-05 2:25 
QuestionHow to get Horizontal Scroll on Property Page? Pin
theFrenchHornet24-May-05 11:58
theFrenchHornet24-May-05 11:58 
GeneralSingle-threaded versus Multithreaded Pin
Ramsus24-May-05 11:38
Ramsus24-May-05 11:38 
GeneralRe: Single-threaded versus Multithreaded Pin
Ryan Binns24-May-05 18:22
Ryan Binns24-May-05 18:22 
GeneralRe: Single-threaded versus Multithreaded Pin
Andrew Walker24-May-05 22:21
Andrew Walker24-May-05 22:21 
Generalclose initial blank window Pin
emagadmin24-May-05 10:50
emagadmin24-May-05 10:50 
GeneralRe: close initial blank window Pin
Ravi Bhavnani24-May-05 11:32
professionalRavi Bhavnani24-May-05 11:32 
GeneralRe: close initial blank window Pin
Priyank Bolia25-May-05 0:01
Priyank Bolia25-May-05 0:01 
QuestionWhy does my SetDIBColorTable fail ? Pin
ninck24-May-05 10:28
ninck24-May-05 10:28 
AnswerRe: Why does my SetDIBColorTable fail ? Pin
bmzhao24-May-05 15:00
bmzhao24-May-05 15:00 
GeneralRe: Why does my SetDIBColorTable fail ? Pin
ninck24-May-05 20:32
ninck24-May-05 20:32 
Generalfprint problem Pin
Andrew Admire24-May-05 8:21
Andrew Admire24-May-05 8:21 
GeneralRe: fprint problem Pin
David Crow24-May-05 8:34
David Crow24-May-05 8:34 
GeneralRe: fprint problem Pin
Andrew Admire24-May-05 8:39
Andrew Admire24-May-05 8:39 

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.