[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

win2k domain - delete registry key upon login

hello,

i want to delete a HKEY Current USer registry value with a login script, can anyone provide the syntax please?

thanks
0
acetate
Asked:
acetate
  • 3
2 Solutions
 
paraghsCommented:
Here is what I do :

1. Download ftp://ftp.mountpoint.ch/pub/users/flo/regdel.zip.
Extract file regdelw.exe from it, and put it under %windir% (Windows directory).
2. In the startup folder (%userprofile%\Start Menu\Programs\Startup), create a text file and put this line into the file :
regdelw "give_here_the_key_to_be_deleted" /q /n
3. Save this file with any name, and extension of either .bat or .cmd
0
 
TheMCSECommented:
As paraqhs points out, there are numerous ways to accomplish this task.  One of the easiest, in my opinion, is using the RegDelete method of the WScript.Shell object in VBScript.  The following 5 lines of code will work with nothing more than the WSH (no external requirements):

Set objWSHShell = WScript.CreateObject("WScript.Shell")
objWSHShell.RegWrite "HKCU\Software\Microsoft\Testing", 1, "REG_SZ"
MsgBox "Please confirm that the HKCU\Software\Microsoft\Testing value was created properly.", vbInformation, "Waiting to remove registry entry"
objWSHShell.RegDelete "HKCU\Software\Microsoft\Testing"
MsgBox  "Please confirm that the HKCU\Software\Microsoft\Testing value was deleted properly.", vbInformation, "Completed removing registry entry"

This actually creates a dummy value (using RegWrite), MsgBox's to pause execution and allow you to confirm it was created successfully, then removes this value and MsgBox's again.  In your scenario, you would only need two lines (similar to below, but with updated registry path, of course):

Set objWSHShell = WScript.CreateObject("WScript.Shell")
objWSHShell.RegDelete "HKCU\Software\Microsoft\Testing"

Save this file with a .vbs extension, and you can use it in your logon script.  Good luck!
0
 
Yancey LandrumTechnical Team LeadCommented:
I'm assuming you already know how to merge a reg file via login script. Here is the syntax to remove keys and values using a reg file.

Of course you know that to add a new value and data, you structure the file like this:

REGEDIT4

[HKEY_CURRENT_USER\DummyKey]
"NewValue"="NEWDATA"

If you want to delete a value, create a reg file with the value you're after and add a minus sign after the equals. In other words, replace the value data with a minus sign, like this:


REGEDIT4

[HKEY_CURRENT_USER\DummyKey]
"NewValue"=-

If on the other hand you want ot delete a entire key, add a minus sign before the key name [but inside the brackets] like this:

REGEDIT4

[-HKEY_CURRENT_USER\DummyKey]

Of course, if all you want to do is remove the data but not the key or the value, it would be:

[HKEY_CURRENT_USER\DummyKey]
"NewValue"=""

0
 
Yancey LandrumTechnical Team LeadCommented:
Oops! this is a Windows 2000 question! The proper header for the file should be:

     Windows Registry Editor Version 5.00

instead of

     REGEDIT4

(although both will work)

And also sorry for the spelling and grammar errors...
0
 
Yancey LandrumTechnical Team LeadCommented:
One more thing (I feel like Lt. Columbo).

If you don't want to merge a reg file to do it, you can also use REG.EXE which a native tool in Windows 2000; it's not installed by default but it is part of the Support Tools on the CD (x:\support\tools). You can either install the full tools or just extract reg.exe from SUPPORT.CAB. It runs in a cmd window; you can get all the command line parameters in the well-know fashion:

C:\>reg

Registry Console Tool For Windows 2000 - version 2.0
Copyright (C) Microsoft Corp. 1981-1999.  All rights reserved

REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT ]

Return Code: (Except of REG COMPARE)

  0 - Succussful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?

C:\>reg delete /?

Registry Console Tool For Windows 2000 - version 2.0
Copyright (C) Microsoft Corp. 1981-1999.  All rights reserved

REG DELETE KeyName [/v ValueName | /ve | /va] [/f]

  KeyName    [\\Machine\]FullKey
    Machine  Name of remote machine - omitting defaults to the current machine
             Only HKLM and HKU are available on remote machines
    FullKey  ROOTKEY\SubKey
    ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]
    SubKey   The full name of a registry key under the selected ROOTKEY
  ValueName  The value name, under the selected Key, to delete
             When omitted, all subkeys and values under the Key are deleted
  /ve        delete the value of empty value name <no name>
  /va        delete all values under this key
  /f         Forces the deletion without propmt

Examples:

  REG DELETE HKLM\Software\MyCo\MyApp\Timeout
    Deletes the registry key Timeout and its all subkeys and values

  REG DELETE \\ZODIAC\HKLM\Software\MyCo /v MTU
    Deletes the registry value MTU under MyCo on ZODIAC

OK: I'm finally done. Hope this helps.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now