Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

Help on deletion of Registrykey with subkeys under it using vbscript

21 weergaven
Naar het eerste ongelezen bericht

Satish

ongelezen,
2 mei 2006, 01:25:5402-05-2006
aan
Hi All

I need help in deleting a registrykey using vbscript...The following
Vbscript deletes only if there are no subkeys under it.But fails when
there are subkeys.


const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\System Admin Scripting Guide"


oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath


Any help in this regards is highly appreciated.


Thanks,
Satish M

"Crash" Dummy

ongelezen,
2 mei 2006, 10:15:2502-05-2006
aan
> I need help in deleting a registrykey using vbscript...The following
> Vbscript deletes only if there are no subkeys under it.But fails when
> there are subkeys.

It may be possible using available native script functions, but I don't know how
without knowing all the subkeys in advance. Registry functions are sparse in
VBScript. I STRONGLY recommend installing this optional DLL available from
Microsoft. It expands registry handling capability immeasurably. The package
includes full documentation.
http://download.microsoft.com/download/vb60pro/Update/6.0/W9X2K/EN-US/RegObji.exe

With that installed, this script will do what you want:

'------------------KeyKill.vbs-------------------
strKeyPath = "\HKEY_LOCAL_MACHINE\SOFTWARE\System Admin Scripting Guide"

Set objRegistry = CreateObject("RegObj.Registry")
regClear strKeyPath
set objRegistry=nothing

sub regClear(root)
Set objRegKey = objRegistry.RegKeyFromString(root)
Set objRegRootKey = objRegKey.Parent
objRegRootKey.SubKeys.Remove (objRegKey)
Set objRegKey = nothing
Set objRegRootKey = nothing
end sub
'---------------------------------------------------
--
Crash

"History will be kind to me, for I intend to write it."
~ Winston Churchill ~

Satish

ongelezen,
3 mei 2006, 00:40:3803-05-2006
aan
Hi,
Thanks for your help and it works fine post installation of the
dll.However I'm not able to run this on a remote computer(Doing it from
my desk,I have the administrative access and I could also access
registry of test server).

The script that I'm using is :

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "TestSrv-1"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "\HKEY_LOCAL_MACHINE\SOFTWARE\System Admin Scripting
Guide"


Set objRegistry = CreateObject("RegObj.Registry")
regClear strKeyPath
set objRegistry=nothing


sub regClear(root)
Set objRegKey = objRegistry.RegKeyFromString(root)
Set objRegRootKey = objRegKey.Parent
objRegRootKey.SubKeys.Remove (objRegKey)
Set objRegKey = nothing
Set objRegRootKey = nothing
end sub

Your help in this regards is higly appreciated.

Thanks,
Satish M

Michael Harris (MVP)

ongelezen,
3 mei 2006, 00:49:4903-05-2006
aan
"Crash" Dummy wrote:
>> I need help in deleting a registrykey using vbscript...The following
>> Vbscript deletes only if there are no subkeys under it.But fails when
>> there are subkeys.
>
> It may be possible using available native script functions, but I
> don't know how without knowing all the subkeys in advance. Registry
> functions are sparse in VBScript. I STRONGLY recommend installing
> this optional DLL available from Microsoft. It expands registry
> handling capability immeasurably. The package includes full
> documentation.
> http://download.microsoft.com/download/vb60pro/Update/6.0/W9X2K/EN-US/RegObji.exe
>

--- snip ---

With the WMI StdRegProv class, the old VB Registry object is really
unnecessary...

StdRegProv class [WMI]
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/stdregprov.asp?frame=true

--
Michael Harris
Microsoft MVP Scripting


"Crash" Dummy

ongelezen,
3 mei 2006, 09:44:1003-05-2006
aan
> Thanks for your help and it works fine post installation of the
> dll.However I'm not able to run this on a remote computer(Doing it from
> my desk,I have the administrative access and I could also access
> registry of test server).

No, it has to be installed where the script runs. Try using WMI, as Michael
suggests. (I don't know anything about WMI)
--
Crash

"Dare to be naïve."
~ Buckminster Fuller ~


"Crash" Dummy

ongelezen,
3 mei 2006, 10:16:4103-05-2006
aan
> With the WMI StdRegProv class, the old VB Registry object is really
> unnecessary...

I am a total newbie at WMI, so cut me some slack, but I can't delete a key and
subkeys without enumerating the entire subtree and deleting the keys one at a
time. In other words, using the documented example, if I create
"Software\MyKey\MySubkey," trying to delete "Software\MyKey" fails. Is there a
way to delete the whole subtree, like there is with the Registry Object?
--
Crash

"Genius is one part inspiration, nine parts perspiration."
~ Alva Thomas Edison ~


Michael Harris (MVP)

ongelezen,
3 mei 2006, 19:20:2403-05-2006
aan
"Crash" Dummy wrote:
>> With the WMI StdRegProv class, the old VB Registry object is really
>> unnecessary...
>
> I am a total newbie at WMI, so cut me some slack, but I can't delete
> a key and subkeys without enumerating the entire subtree and deleting
> the keys one at a time. In other words, using the documented example,
> if I create "Software\MyKey\MySubkey," trying to delete
> "Software\MyKey" fails. Is there a way to delete the whole subtree,
> like there is with the Registry Object?

Deleting keys with subkeys is more a OS issue that the particular object
model. Earlier Win9x registry 'key with subkey' deletes was supported at
the API level and NT4 and later made you do recursive deletes. Some
registry object models may do the recursive part transparently for you.
RegObj may be one of those - I haven't used it in years, probably 1998/99...

Satish

ongelezen,
4 mei 2006, 06:11:2804-05-2006
aan
Hey Thanks It works well.

"Crash" Dummy

ongelezen,
4 mei 2006, 07:44:0004-05-2006
aan
>> Is there a way to delete the whole subtree,
>> like there is with the Registry Object?

> Deleting keys with subkeys is more a OS issue that the particular object
> model. Earlier Win9x registry 'key with subkey' deletes was supported at
> the API level and NT4 and later made you do recursive deletes. Some
> registry object models may do the recursive part transparently for you.
> RegObj may be one of those - I haven't used it in years, probably 1998/99...

Hey, ANY script does a lot of low level stuff transparently! That's what makes
it different from Assembly! :-)

The RegObj script I posted works with W2K Pro.

Anyway, I take it the answer is no, that I would have to build a recursive loop
to delete an entire subtree using native WMI methods.
--
Crash


Michael Harris (MVP)

ongelezen,
4 mei 2006, 23:08:1504-05-2006
aan
> Anyway, I take it the answer is no, that I would have to build a
> recursive loop to delete an entire subtree using native WMI methods.

Yes you would when using StdRegProv but it really isn't that hard...

Google Groups: microsoft.public.scripting.wsh
Deleting Registry KEY with Subkeys
http://groups.google.com/group/microsoft.public.scripting.wsh/msg/3091255b82fecfab

(I can't believe I posted that 5 years ago!)

0 nieuwe berichten