CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Question How to change COM port number

    I need to write a program in VB6 to list all of the available COM ports on a
    computer and allow the operator to change the COM port number. I can get the list of available COM ports using the WMI but how to I change the COM port number?

    I have to support a legacy program that looks for connections to devices on
    specific com ports. Genius that this original programmer was, he hard coded
    those com port numbers.

    Currently we use a Digi edgeport with 4 serial ports. The Edgeport comes
    with a utility that allows you to change the COM port numbers. However we
    would like to move to single USB to serial devices (serialized of course),
    which do not provide the same type of utility. I would like to write a VB6
    program to help with setup by allowing the user to connect a terminator to a
    serial port, send a message out to each available com port, and look for the
    response. Once the user identifies the serial port I want to allow them to
    change the com port number to one of the hard coded ports.

    Of course they could use the device manager to change the com port numbers but I wanted to make an automated, easy to use utility, since the users will not be computer savy.

    Any ideas?

    Thanks,
    quantum1976

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to change COM port number

    Welcome to CodeGuru!

    If the port numbers are changable via system settings, then I'd guess the numbers would be in the registry. Doesn't the system require a restart when the numbers are changed though? Anyway perhaps you can locate the data in the registry and make the changes there. I don't know if there is any API for changing such port settings.

    Seems to me though that such changes could cause problems depending on the circumstances. Given the non-computer savviness of the target users, this sounds like trouble to me.

    Actually, the first thing that I was thinking was to locate the hard-coded values in the exe file, and write a little app to modify those instead.

    Don't you have the source code for the app?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Feb 2006
    Posts
    3

    Re: How to change COM port number

    I've given up on trying to do this through the registry, way too many keys to update.

    What I would like to do now is to programmatically bring up the Advanced Settings window under the Device Manager for the serial port. I can get to the COM Port Properties window by using:

    shell("rundll32.exe devmgr.dll,DeviceProperties_RunDLL /DeviceID acpi\pnp0501\1"

    But I still have to click on the Port Settings tab followed by the Advanced button. Does anyone know of another way to get to the Advanced Settings window automatically?


    Thanks,
    quantum1976

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to change COM port number

    Here's something that might help:
    http://vlaurie.com/computers2/Articles/control.htm
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Feb 2025
    Posts
    1

    Re: How to change COM port number

    I had a problem where DeviceManager assigned two COM3 ports which caused COM port contention when my applications tried
    to use COM3, in my research I found that the registry HKLM\HARDWARE\DEVICEMAP\SERIALCOMM is where DeviceManager registers
    all the COM ports. I programmatically in C# changed COM3 on one of the two designations to another unused COM port that I discovered
    in the DeviceManager COM Port - Properties/Advanced settings com listbox. After the COM port change in the registry of the COM3 value (do not change the name), rebooting the PC did not revert DeviceManager back to the old settings, the new setting remained. Testing again with my applications revealed no more COM port contention on COM3.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured