a startup/login script that will search a key and replace the value

By cwong ·
does anyone know how i can do it? at the moment i'm trying to change a value in the registry however SSIDs are different, i must perform a search and then change value.

thanks in advance

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Be a little more specific

by neilb@uk In reply to a startup/login script th ...

if you want to change a key in HKCU you have to do it as the logged in user so a login script applied by a GPO is the answer. If it's HKLM then you can do it as the user if they have the necessary permissions to change the registry otherwise you can do it as a GPO applied startup script probably using vbscript although Powershell will do it.

With vbscript, you can do a recursive search of the Registry. Here's a bit of code that I use to check for Google Earth (which they aren't supposed to have). I've taken out the code that generates my report so I can rip the software out of their machines and replaced it with a simple print statement. If you can follow this it should get you going.

Two things: If you start the search, say, in HKLM\Software, it will take a lo-o-ong time. This finds ALL occurrences of the required key.
Option Explicit

' The full set

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

Dim oReg
Dim sComputer
dim bfound
dim sFoundPath
Dim sStartkey
Dim sKeyTofind

sComputer = "."
bFound = False

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

' Starting point and target key

sStartKey = "Software\Google"
sKeyTofind = "Google Earth"


' -----------------------

Function WalkRegistry(sKeyPath)

Dim cKeys, sSubKey, aSubKeys

' walk recursively up subkeys

cKeys = oReg.EnumKey (HKEY_LOCAL_MACHINE, sKeyPath, aSubKeys)
If IsArray(aSubKeys) Then
For Each sSubKey In aSubKeys
If lCase(ssubKey) = lCase(sKeyTofind) Then
bFound = True
sFoundPath = sKeyPath & "\" & sSubKey
wscript.echo sFoundPath
End If
WalkRegistry((sKeyPath & "\" & sSubKey))
Exit Function
End If

Exit Function

End Function

Related Discussions

Related Forums