|
-
October 24th, 2008, 03:45 AM
#1
Turn off the hard disk through WMI
Dear all:
I want to turn off the hard disk through program.
Reference to the SetPowerState function of WMI CIM_DiskDrive Class and the following URL
http://msdn.microsoft.com/en-us/libr...21(VS.85).aspx ,
I write a VC6 programe,but encountered problem.
1.Can SetPowerState really realize turn off the hard disk?
Platform SDK says "Defines the desired power state for a logical device
and when a device should be put into that state. Not implemented by WMI."
What is "Not implemented by WMI" mean?
2.When called pClassInstance->Put(L"PowerState", ...),it failed,return value is "WBEM_E_TYPE_MISMATCH",but refer to Platform SDK,datatype of "PowerState" is VT_UI2.
I'm puzzled.
3. If SetPowerState can realize turn off the hard disk,
how can I realize control a single disk if I have two or more disk in my system?
Thanks
Best Regards
Frankzcj
Relevant code as below:
IWbemServices *pSvc;
HRESULT hres;
.....
BSTR MethodName = SysAllocString(L"SetPowerState");
BSTR ClassName = SysAllocString(L"CIM_DiskDrive");
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
IWbemClassObject* pInParamsDefinition = NULL;
hres = pClass->GetMethod(MethodName, 0, &pInParamsDefinition, NULL);
IWbemClassObject* pClassInstance = NULL;
hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);
// Create the values for the in parameters
VARIANT varPowerState;
varPowerState.vt = VT_UI2;
varPowerState.uiVal = 6;
// Store the value for the in parameters
hres = pClassInstance->Put(L"PowerState", 0,&varPowerState, 0);
VARIANT varDate;
varDate.vt = VT_DATE ;
varDate.uiVal = 0;
// Store the value for the in parameters
hres = pClassInstance->Put(L"Time", 0,&varDate, 0);
IWbemClassObject* pOutParams = NULL;
hres = pSvc->ExecMethod(ClassName, MethodName, 0,NULL, pClassInstance, &pOutParams, NULL);
......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|