Link to home
Start Free TrialLog in
Avatar of krakatoa
krakatoaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Windows Registry entry for USB stick presence.

How long - or on which terms - does Windows retain DiskID and other HKEY entry information for removable media such as a USB stick? Why is it not erased when the USB stick is removed and the display refreshed in RegEdit?
Avatar of Kimputer
Kimputer

To my knowledge, such entries are NEVER deleted. On old computers, you will see a HUGE list in the registry.
Windows probably thinks it doesn't matter, and the amount of USB devices inserted during its lifetime will be quite manageable, and doesn't delete it for future inserts (less time to detect and get the correct parameter, including past assigned drive letters)
It does not get deleted, which is necessary if you are allowing only known USB devices to connect.
The answer is never. They will get collected to some reason such as drive initialization record. If you delete them manually then they will be recreated each time you connect that usb drive.
Avatar of krakatoa

ASKER

@ everyone

I thought from what I was seeing of the behaviour, that they don't get deleted - which is understandable for fixed disks, but for USB drives . . . . ?

therefore :

If you delete them manually then they will be recreated each time you connect that usb drive.

this would then be my preferred route; so I tried to delete the entries, but try as I might, I cannot seem to get the user permissions to deleted these keys, although I have admin privileges and use the admin cmd prompt. Can anyone shed some light on how to do this, as I'm an OS greenhorn for the most part. ; )

And crucially, I don't see why 'Partmgr' (which contains the useful diskId key), keeps appearing and disappearing. Any thoughts ?
You should not be able to delete them when you have any USB device connected. It can be also USB keyboard or mouse.

As for the PartMgr - what do you mean it keeps disappearing? Each several seconds or how?
I want to delete the device only when it has been removed - not whilst it's inserted.

Partmgr (and its enclosing Device Parameters) was present at one point, then I rebooted and although the devices were still listed, their Device Parameters and Partmgr entries were gone. Then, after some considerable time, they reappeared.
OK, so I can now see how to delete the Partmgr entry, and can also witness it being automatically re-instated when the USB stick is re-inserted - both of which are the two things I was looking for.
PartMgr should not be deleted. It can cause really PITA once it gets out of control believe me. The entries inside - you can yet delete them.
Yes, I can't seem to find anything there that relates to the DiskId which is held under the Partmgr subkey on my machine. This is not mentioned afaics.
Hmmm, ok. He seems to have gone around the Sun to the Moon with that a bit.

So in real time I see Partmgr appear when a USB stick is introduced, and the DiskId (as given below) appear. If I want to delete the Partmgr key, I can do that, which is fine. and of course the DiskId goes too. That's fine. What remains in the Registry is a unique-looking key relating to the particular USB stick, of the format "4C530203030206111132".

So I would like to understand the "difference" between the existence and persistence of this key name (the as given above) :

4C530203030206111132&0

and

the DiskId given under the Partmgr subkey for the device, which is in this format :

{15ee1cf2-2a4a-11e9-834d-28d2445e132a}

Are these both unique? What is their relationship? How do they differ in terms ?
I don't think it's possible for me to determine whether the USB stick is inserted or not at any given time.
Ultimately, I am simply hoping to determine whether a certain USB stick is presently inserted into a slot or not. Can anyone help on this particular point at all ?
And what should happen once you detect the drive connect? There are a lot of script examples which let to detect the usb drive connected. By serial number or by name or even by drive letter. For example this
What should happen is that I know the stick is in, and that the code I’m using isn’t reading an entry that may be valid but does not indicate that the stick is presently inserted.
Two things (decreasing order of importance)

a. Your goal is unstated. The step is being discussed here. It's quite possible that this (clearly very problematic) step is not the right one in any case for your goal.
http://technojeeves.com/index.php/aliasjava1/15-smart-questions
b. If this is (highly doubtful) the right step, instead of trying to read a UID at a low (storage medium) level, why not arrange to read one at a higher level, e.g. a generated hidden file, the name of which is that UID?
I'm sadly not in agreement (and never have been) with the idea that a goal has to be stated in order for a question (here on EE) to be valid. A questioner can have his or her own reasons for asking something, and there need be no more to it than that. Simply because someone else might want to know the ultimate goal the questioner has in mind should be immaterial.

As for using a hidden file for the purpose, this is an approach that is not suitable for my purposes, and I don't intend on getting into the whys and wherefores around that. Let's just say it's business confidential, that should do it.

But in any case the answers so far to my question have all rejected the idea that the presence or absence of a drive / USB stick can be determined in 'real time', and that, if it's a goal that'd being sought here, is what the goal is - or was - since I've found another alternative that meets my requirements.
I'm sadly not in agreement (and never have been) with the idea that a goal has to be stated in order for a question (here on EE) to be valid.
That "idea" is certainly not an idea of mine. The point is that discussing steps instead of the goal is often inefficient, sometimes even misleading, in reaching the goal.

But in any case the answers so far to my question have all rejected the idea that the presence or absence of a drive / USB stick can be determined in 'real time'
Reading a file would  be able to detect it in real time, which is why i suggested it. If you can't use that, then i understand
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Get hold of the (Sysinternals?) app 'RegMon'. That should show you what writes are done when sticks are hot-plugged. That should point to a solution for one platform