[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Too many serial ports, need to remove them

Posted on 2009-04-12
8
Medium Priority
?
1,680 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 93

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 93

Expert Comment

by:nobus
ID: 24126026
then i can't help you
0
Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

 
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 600 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

Reclaim your office - Try the MB 660 headset now!

High level of background noise often makes it difficult for employees to concentrate fully on their jobs – or to communicate clearly on calls. The MB 660 headset helps you create a disruption free workspace.  

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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