Solved

Too many serial ports, need to remove them

Posted on 2009-04-12
8
1,641 Views
Last Modified: 2013-11-05
I work for a company that does mobile phone (cellphone) unloicking - i.e. unlock to all networks. As part of this, they use cables that connect from the various models of phone to the PC via USB. They register as COM devices in Windows. The problem is that because each phone has a different serial number (probably the IMEI of the phone), every phone appears as a new serial device. This means that his unlock machine has over 150 serial port devices that are just sitting around and will never be used again. The software he uses cannot access port 200+, so every unlock he does he has to remove an old unused COM device, plug in the new one, then switch the COM port number of the new device to whatever the one was that he removed. For example, if he removed COM142, he adds the new device and changes the port number to COM142. It's getting rediculous.

I know that Windows XP stores COM device information in the registry, and would like to know if there's anything I can do to remove them all. I can program in VB.NET and C#, so if it's a case of conditionally removing registry entries I'm happy to do so. I have a virtual machine set up to allow me to revert to a snapshot in case I mess up the registry.

Any ideas how I can remove the ports?
0
Comment
Question by:burningmace
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 91

Expert Comment

by:nobus
Comment Utility
go to device manager>view tab
click "show hidden devices" and delete them
that should do it
0
 
LVL 5

Author Comment

by:burningmace
Comment Utility
Yeah, I know you can do that. Problem is there's like 200 of them and I want to remove them programatically.
0
 
LVL 91

Expert Comment

by:nobus
Comment Utility
then i can't help you
0
 
LVL 70

Expert Comment

by:garycase
Comment Utility
My code-writing days are long over ... but if I was going to do this, here's the approach I'd take, which should let you do what you want to do:

=>  Install one of the applications that track registry changes, such as the free RegRunner:  http://www.downloadsquad.com/2008/05/05/detect-and-track-registry-changes-with-regrunner/

=>  With RegRunner running, go to Device Manager and delete one of the ports.   You'll now know exactly what keys are modified in the registry ... so it should be fairly simple to write a program to make the modifications you want programmatically.    ... you may need to do a couple of deletions to identify the exact pattern; but I suspect it will be fairly obvious.

=>  To make this question useful for any future EE members with a similar issue, please post your results here :-)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Expert Comment

by:oobayly
Comment Utility
You could download devcon, a command line tool for the Device Manager, and do the following:
  1. Create a process the calls devcon with the parameter as "findall =ports"
  2. Setup the process so that we can get the output of it
  3. Loop through each line of the output, and get the port DeviceID & Name
  4. For each port you want to remove, call devcon uninstall "@<Device ID>"
Devcon can be downloaded here:
http://support.microsoft.com/kb/311272

Also, I'll add some code on how to automate this, as it's something I'll find quite useful to have too.
0
 
LVL 15

Accepted Solution

by:
oobayly earned 150 total points
Comment Utility
Here we go, I copied the devcon executable to c:\windows\system32

Note, as the Device ID may contain &, which is a special character in the shell, the Device ID needs to wrapped in quotes. Also it needs to be prepended by @, I don't know why, but it's done this in the MS example. If it's not prepended with @, the Device ID won't be matched, and nothing will happen.
      string pathToDevCon = @"C:\windows\system32\devcon.exe";
 

      /* Create the Process to retrieve all the ports

       * StartInfo is modified so that we can capture StdOut

       */

      Process ps = new Process();

      ps.StartInfo = new ProcessStartInfo(

        pathToDevCon, "findall =ports");

      ps.StartInfo.RedirectStandardOutput = true;

      ps.StartInfo.UseShellExecute = false;

      ps.Start();

      ps.WaitForExit();
 

      /* Read all the ports into a dictionary object:

       * Output from devcon is in the format <Device ID>        : <Description>

       * Final line lists number of devices returned

       */

      Dictionary<string, string> ports = new Dictionary<string, string>();

      do {

        string line = ps.StandardOutput.ReadLine();

        if (line == null) break;
 

        string[] parts = line.Split(':');

        if (parts.Length == 2) {

          ports.Add(parts[0].Trim(), parts[1].Trim());

        }

      } while (true);

      ps.Dispose();
 

      // Action to take, can be {uninstall | disable | enable}

      string action = "disable";
 

      // Loop through each device, and 

      foreach (string devID in ports.Keys) {

        bool doAction = true; // Use your own logic here to decide whether to remove the device 

        if (!doAction) continue;
 

        // Execute the action on the Device ID, again capturing StdOut

        Process psAction = new Process();

        ps.StartInfo = new ProcessStartInfo(

          pathToDevCon,

          string.Format("{0} \"@{1}\"", action, devID));

        ps.StartInfo.RedirectStandardOutput = true;

        ps.StartInfo.UseShellExecute = false;

        ps.Start();

        ps.WaitForExit();
 

        /* Echo only the 1st line of StdOut from the Process as the 2nd line

         * returns the number of devices affected

         */

        Console.Out.WriteLine(ps.StandardOutput.ReadLine());
 

        ps.Dispose();

Open in new window

0
 
LVL 5

Author Comment

by:burningmace
Comment Utility
I've had to make a few alterations to your code. You defined psAction then use ps instead, which was probably a typo. I've also modified the code to only process COM ports by checking if the device name begins with the string "Communications Port (COM".

I'm going to the store tomorrow so I'll test it out in situe.
0
 
LVL 5

Author Closing Comment

by:burningmace
Comment Utility
Excellent. With a few minor modifications this worked perfectly.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In this article we have discussed the manual scenarios to recover data from Windows 10 through some backup and recovery tools which are offered by it.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now