How rename COM Port Number

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

I don’t think com port renaming is available in wmi. IIRC the msports example in the wdk shows you how to rename a com port using COMDb

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com.cn
Sent: Wednesday, November 10, 2010 11:26 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How rename COM Port Number

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

3ks.

xxxxx@yahoo.com.cn wrote:

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 don’t understand your thinking here. Why on earth would you try to
solve the problem this way? What happens if you try to use this in
another computer where COM5 is already in use for some other purpose?

Your APPLICATION needs to be able to adapt itself to whatever name the
hardware was assigned. You should store the correct port name in the
registry somewhere and allow the user to customize it. THAT’S the
proper solution.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>>>>>>Your APPLICATION needs to be able to adapt itself to whatever name the
hardware was assigned. You should store the correct port name in the
registry somewhere and allow the user to customize it. THAT’S the
proper solution.

Thank you,Tim.
I forgot to say the situation that two COM Port own the same PortName.
And I found that rename can be done in the registry,
but need to restart the computer to take effect.

Best Regards
Zhou ChengJun