Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List comports and removing them (including hidden ones)

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
I am looking for some help to accomplish the following:

Get all the com ports on local computer (including the hidden one)
Remove a comport (or all of them if user wishes)

I have been looking and reading on wmi scripting, but, i can't figure out how to pull all hidden ports and how to remove.

any idea or if you can point me in the right direction.... thank you in advance.


this code is not getting me the hidden devices though.. i don't know what i am missing or if i need different script

also, deleting.
Code:
create cursor ComList (DeviceID c(10), DevName c(100), DevDesc c(100))

strComputer = "."
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")

colItems = objWMIService.ExecQuery("Select * from Win32_SerialPort")

For Each objItem in colItems
    *wait window   "Description: " + objItem.Description + objItem.DeviceID + 'Name: ' + objItem.Name
    sele comlist
	append blank
	REPLACE DeviceID WITH objItem.DeviceID,;
		DevName WITH objItem.Name,;
		DevDesc WITH objItem.Description
		

Next

SELECT ComList
BROWSE

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
I never removed a port, I don't know if you even could. And what exactly would you want to do? You can't physically remove it, you'd act on it's driver and either deactivate or remove the driver? This is of course needing administrative privileges and is a permanent change.

WMIs offers no implemented methods. While it inherits a Reset and a SetPowerState Method from CIM_SerialController, docs say, it does not implement these methods, so they do nothing:

I doubt you can do what you want with WMI. In my experience it also differs from QueryDosDevice, but I don't remember which was finding more COM devices. I switched to using a c# windows service started as LocalSystem to act on COM Ports (for reading electronical scales), because VFP in conjunction with CommTools lost ports, which were still showed from the Windows Device Manager.

Bye, Olaf.
 
>WMIs offers no implemented methods.
WMIs Win32_SerialPort offers no implemented methods.
 
Olaf, thank you for your response.

What i mean is removing the device:
if you go to the control panel / Device manager and you enable to show hidden devices,
you will notice alot of comports and usb devices that were once used and now they are no longer in use, as they are ghost devices.

if you used a usb drive and unpluged it, plugged in your mobile phone and other phones etc.., the device manager keeps those in registry and in device managers, though they are hidden devices.

In one of our application, in a recycling company, we flash/program many mobile devices, 100+ devices a day, and everytime we plug a device and finish flashing it, the comports/usb devices are still there and they are eating up resources.

We go to the device manager, and enable the hidden devices, and we have to delete/remove 1 device at a time.. sometimes, there are over 400 devices under comport, and usb and storage devices etc... that we do not need and we need to free them up.

reason for that is, certain flashing software uses comports (though it is thru usb), but the software from Samsung, LG, RIM, Blackberry etc.. will stop working unless we remove devices.

i hope that clarifies more.

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Thanks Ali,

that clarifies your need, but unfortunately I have never done that, neither via WMI nor any other way.
Googling I find an API function for uninstalling a device:

You may find more googling DiUninstallDevice, eg listing / enumerating devices.
You know news2news, where you also might find this declaration.

Bye, Olaf.
 
Wow, Ali, I never would have guessed that was your purpose from your original posting. I thought you wanted to remove rows from a listbox or cursor.

It's a unique need. Let us know what you come up with, eh?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top