Basically I have a script that will delete the specified keys that I want,
but if a user is logged on then the keys produced by that user will not
delete. But if I manually goto the key through regedit and right click and
delete it will delete even if the user is logged on. I would like this
functionality in my script without having to log the user off. Once the
script is done running then a reboot script will run so the user will be
logged off anyways, I am just trying to save alittle time and dont want to
reboot twice.
"Phyxious" <Phyx...@discussions.microsoft.com> wrote in message
news:801ED8D9-76C2-4177...@microsoft.com...
Const HKLM = &H80000002
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers\"
objReg.EnumKey HKLM, strKeyPath, arrSubKeys
For Each SubKey In arrSubKeys
If InStr(SubKey, "Client") OR InStr(SubKey, "session") > 0 Then
objReg.DeleteKey HKLM, strKeyPath & SubKey
End If
Next
Set objReg = Nothing
Did you try to delete using WSHShell.RegDelete?
If not, try this:
--
Set WSHShell = Wscript.CreateObject("Wscript.Shell")
On Error Resume Next
WSHShell.RegDelete("HKCU\Software\Microsoft\KeyToDelete")
On Error Goto 0
--
Regards,
Baard Schøyen
--
' SubinAcl.exe download:
'
http://www.microsoft.com/downloads/details.aspx?FamilyID=e8ba3e56-d8fe-4a91-93cf-ed6985e3927b&displaylang=en
'** Statements:
Dim oShell, WSHShell, oFSO
Dim SRC, KEY, QRY
'** Objects:
Set oShell = Wscript.CreateObject("Wscript.Shell")
Set oFSO = Wscript.CreateObject("Scripting.FileSystemObject")
'** Subinacl.exe location, must be located in the same directory as this
script:
SRC = oFSO.GetFolder(".") & "\subinacl.exe"
'** Type the registry key name here:
KEY = "hkey_current_user\software\keytodelete"
'-----------------------------------------------------------------------------------
'** Take ownership on all keys and values:
oShell.Run "cmd /c " & SRC & " /subkeyreg " & KEY & " /setowner=%username%",
0, True
'** Remove all permissions on all keys and values:
oShell.Run "cmd /c " & SRC & " /subkeyreg " & KEY & " /perm", 0, True
'** Apply current user FC permissions on all keys and values:
oShell.Run "cmd /c " & SRC & " /subkeyreg " & KEY & " /grant=%username%=f",
0, True
'** Delete the key with all subkeys and values:
oShell.Run "cmd /c reg delete " & KEY & " /f", 0, True
'** Check if the key still exist:
QRY = oShell.Run("cmd /c reg query " & KEY, 0, True)
If QRY = "0" Then msgbox KEY & " could not be deleted."
If QRY <> "0" Then msgbox KEY & " is deleted."
'-----------------------------------------------------------------------------------
Use WShell.Run to run
reg delete .. .. . .. .
to know about reg delete, Open Command Prompt and type :
reg delete /?
--
Ayush [ Good :-) Luck ]
-------------
Search - www.Google.com | Wikipedia -
http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------
Not necessarily. You can check permissions and ownerships on keys by
right-clicking a key and choose Permissions. In the Permissions dialog, you
can also click Advanced to display the user object who have ownership on the
key.
On a domain member computer, Domain Admins will normally be a member of the
local Administrators group. The domain user (by default member of the
RESTRICTED group) may also need to be a member of the local Administrators
group, if he needs to take ownership and get FC on keys and values. This will
apply if a registry script will be executed under the user's own credentials,
e.g. during login, where the user must have all necessary priveliges.