Problem solve Get help with specific problems with your technologies, process and projects.

WMI script to clean up worms and virus registry keys

This handy WMI script can be called from your login scripts to clean up viruses that write to the windows registry

This tip was submitted to the tip exchange by member Joel Johnson. Please let other users know how useful it is by rating it below.

This handy WMI script can be called from your login scripts to clean up the viruses that write to the windows registry Run key. Of course, you may want to add a Reg backup line to backup the registry first. This is an example with the most recent Netsky.D worm which was a recent category 4.

You can run this within netlogon and save yourself valuable cleanup time.

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_Local_Machine  = &H80000002
Const HKEY_Users   = &H80000003
Const HKEY_Current_Config  = &H80000005

sComputer  = "."
sMethod  = "DeleteValue"
hTree   = HKEY_Local_Machine
sKey   = "SoftwareMicrosoftWindowsCurrentVersionRun"
sValueName  = "ICQ Net" = "%Windir%winlogon.exe -stealth"

Set oRegistry  = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
   sComputer & "/root/default:StdRegProv")

Set oMethod  = oRegistry.Methods_(sMethod)
Set oInParam  = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValueName

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)

The basics behind this script are pretty simple. The first five lines lay out the standard Windows registry tree. The next five lines define what we are looking for.

The "." stands for local computer. If you want to target a single computer you can add that computer name instead of the ".".

The "SMethod" means we are using the "Delete Value" command. The next two lines lay out the location of the value we are looking for. And, finally, the "SValue" is the value that nasty virus added to user registries. You can adjust the SValue to meet your particular cleanup needs.

The rest of the script calls the variables we just defined.

Dig Deeper on Windows legacy operating systems

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.