Hi,All
I used COM Port to communicate with a panel.
The real COM Port is COM6,properties “PNPDeviceID” corresponding Win32_SerialPort Class is “ACPI\PNP0501\6”.
First I used the hard disk with windows OS with a motherboard,
then I changed the hard disk to my motherboard,
The COM Port of the two motherboard is not the same.
And I found that the COM Port Number is not “COM6”,is “COM5”.
In order to adapt this,I must change the parameter “lpFileName” of CreateFile Function
from “COM6” to “COM5”.
Or I must change the COM Port Number in Device Manager/Ports(COM&LPT)/Port Settings.
I want to change the COM Port Number by programming.
I used WMI IWbemClassObject::Put Method.
First Enum CIM instance corresponding to Win32_SerialPort Class,
and found which COM Port’s property “PNPDeviceID” is “ACPI\PNP0501\6”,
then call IWbemClassObject::Put Method.
But this failed,the COM Port’s property “DeviceID” is not changed,it is still “COM5”.
Related to the code below[Simplify]:
//…
VARIANT vtProp;
V_VT(&vtProp) = VT_BSTR;
V_BSTR(&vtProp) = SysAllocString(L"COM6");
LPCWSTR strClassProp = L"DeviceID";
pclsObj->Put(strClassProp, 0, &vtProp, VT_BSTR);
VariantClear(&vtProp);
//…
My question is:
1 WMI method can not realize this or I called unsuccesfully?
2 Is there any other method to change the COM Port Number?
Any help is appreciated.Thanks.
Best Regards
Zhou ChengJun