Jump to content

Deleting A Reg Key


Recommended Posts

I am trying to delete this registry key through a batch file which will run through group policy. Is there going to be permission issues with this . this is what I have so far

@echo off

REG DELETE HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676 /f

cls

This is the name of the key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000003

What else I need in the batch file. Any other sugestions will help as isn't only HKLM,HKU available for running it on remote machine.

Edited by rockinsmartguy
Link to comment
Share on other sites


If you are worried about permissions you can use the GPO to elevate the privileges or use the 'RUNAS' function to elevate privileges while the batch file executes.

You could also write a registry file and place the minus(-) sign in front of the key you want to delete and then execute it with regedit /s

That should work no problem.

Link to comment
Share on other sites

This is the script I have

============================================================

Const HKEY_CURRENT_USER = &H80000001

strComputer = CreateObject("Wscript.Shell").Environment("Process")("ComputerName")

'strComputer = "."

Dim strKey

strKey = "HKEY_CURRENT_USER\Software"

If Not RegKeyExists(strKey) Then

'WScript.Echo "Key Is NOT Present!"

Else

'WScript.Echo "Key IS Present."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _

strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows NT"

oReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys

'Wscript.Echo strKeyPath & "\" & subkey

oReg.DeleteKey HKEY_CURRENT_USER, strKeyPath & "\" & subkey

Next

'Wscript.Echo strKeyPath

oReg.Deletekey HKEY_CURRENT_USER, strKeyPath

End If

Function RegKeyExists(strName)

Const NO_EXISTING_KEY = "HKEY_NO_EXISTING\Key\"

Dim objWsh

Dim strKeyPath

Dim strNoKeyError

Set objWsh = WScript.CreateObject("WScript.Shell")

strKeyPath = Trim(strName)

If Right(strKeyPath, 1) <> "\" Then strKeyPath = strKeyPath & "\"

On Error Resume Next

' Get the error description by trying to read a non-existent key

objWsh.RegRead NO_EXISTING_KEY

strNoKeyError = Err.Description

Err.Clear

objWsh.RegRead strKeyPath

' Compare the error description with the previous determined sample

If Replace(Err.Description, strKeyPath, NO_EXISTING_KEY) = strNoKeyError Then

RegKeyExists = False

Else

RegKeyExists = True

End If

Err.Clear

On Error Goto 0

Set objWsh = Nothing

End Function

===========================================================

The script runs on a single pc but its not working through login script, any examples on how to write a a reg file and run it through a batch file. is reg file going to delete all the subkeys below as they need to be empty before the main key gets deleted.

Link to comment
Share on other sites

It would help greatly if you could outline what you really want to achieve clearly and some details about the domain setup (assuming it's a domain). You started off with a command script and a casual mention of remote computer. Then you came up with a VB script but still asking about "how to write a a reg file and run it through a batch file".

Link to comment
Share on other sites

I am trying to delete a particular registry key(HKEY_CURRENT_USER\Software) in outlook for couple of hundred users in the domain. The script needs to run through group policy, I already wrote the script tested on a single pc but it's not running through login script.

Link to comment
Share on other sites

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...