aleph01 Posted October 23, 2017 Posted October 23, 2017 (edited) This script doesn't seem to be doing it: #RequireAdmin For $i = 1 To 100 $sVar = RegEnumVal("HKEY_LOCAL_MACHINE\System\MountedDevices", $i) If @error <> 0 Then ExitLoop RegDelete("HKEY_LOCAL_MACHINE\System\MountedDevices", $sVar) Sleep (101) Next The above script apparently has no affect. Setting is a library. When the MountedDevices list becomes large (due to patrons using thumb drives) it seemingly becomes corrupted and Windows stops recognizing USB drives. Clearing the list manually resolves the issue. Now I would like to automate the process. Does anyone see my error? I'm running this on my laptop where I am an administrator. The script runs, but no registry deletions occur. Thanks, Edited October 23, 2017 by aleph01 Meds. They're not just for breakfast anymore.
aleph01 Posted October 23, 2017 Author Posted October 23, 2017 Nevermind. Simple error. I had $i in my RegDelete line instead of &sVar. Code above is working fine. Meds. They're not just for breakfast anymore.
aleph01 Posted October 24, 2017 Author Posted October 24, 2017 For future reference: I was mistaken. The above code doesn't work as intended. It runs into the same problem as any For...Next loop with a line Delete function. If it counts forward from 1 to 500, deleting as it goes, the even numbered lines in the original list don't get deleted because the list scrolls up as items are deleted. Instead of reworking it to place the mounted devices in an array and using UBound to get the size of the array and then loop backward, I chose a much simpler route. I use a script run under my user's account to RunAs a script that does the registry manipulation. That script is RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices") Sleep (1001) RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices") After running, my MountedDevices list consists of the default entry only and Windows is able to recognize USB drives. Thanks Meds. They're not just for breakfast anymore.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now