Solved

Too many serial ports, need to remove them

Posted on 2009-04-12
8
1,659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Expert Comment

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

Author Comment

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

Expert Comment

by:nobus
ID: 24126026
then i can't help you
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 70

Expert Comment

by:garycase
ID: 24126406
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
 
LVL 15

Expert Comment

by:oobayly
ID: 24129698
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
ID: 24129806
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
ID: 24133373
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
ID: 31569308
Excellent. With a few minor modifications this worked perfectly.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

729 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