Jump to content

Recommended Posts

Posted

Hi,

 

Does anyone have a simple script that will delete all keys (folders) in the below registry location please?

 

HKEY_LOCAL_MACHINE\System\CurentControlSet\Control \Print\Connections\

 

Thank You :)

Posted (edited)

Sorry i missed some out :doh:

 

I would like a script that will delete all keys in the above area but only when a server replies to a ping.

 

Also i dont want the connections key deleting just the ones under that.

 

Sorry to mess you around

 

Thanks

Edited by FN-GM
Posted (edited)

As an alturnative to a ping, which I never got working properly in VB script for some reason, create a single hidden read only share on the server with just a txt file in it, then you can simply use an "if file exists" statement with the full UNC path to see if the script can see the share, and thus the server - I use this to determine whether a member of staffs laptop is on the school network or not when they logon, and thus change the proxy settings accordingly.

 

Mike.

Edited by maniac
Posted

Hi,

 

For now i am using the below script to delete the subkeys only. But it doesnt work. Can anyone see why please?

 

Thanks

 

On Error Resume Next 

Const HKEY_LOCAL_MACHINE = &H80000001 

strComputer = "."
strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Connections" 

Set objRegistry = GetObject("winmgmts:\\" & _
   strComputer & "\root\default:StdRegProv") 

DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath 

Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath) 
   objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys 

   If IsArray(arrSubkeys) Then 
       For Each strSubkey In arrSubkeys 
           DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey 
       Next 
   End If 

'    objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath 
End Sub

Posted

It doesn't work because you've commented out the line which makes it work ...

 

What it's doing is recursively calling the DeleteSubkeys routine and you need that last line otherwise it won't delete the low level keys.

 

I think you could do:

 

if strKeyPath<>"SYSTEM\CurrentControlSet\Control\Print\Connections" then 
   objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath 
end if

 

but try this on a sacrificial machine first!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...