deployexpert created the topic: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Hi everyone,
Need an urgent help. Need a script to delete a registry value. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]
“AppInit_DLLs”=”SAMPLE”
I only want to delete the data value “SAMPlE”
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Seriously? Well, you asked for it! 🙂 www.lmgtfy.com/?q=vbscript+delete+registry+value
deployexpert replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
While using the Google hint Ian gave you; you want to set an entry to empty (“”) and not delete it
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Thanks for ur help.
I only want to delete the value data = “SAMPLE” if it exist in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]
“AppInit_DLLs”=”SAMPLE”
The AppInit_DLLs has different values in it. Just want to delete the value “SAMPLE” in the value data
deployexpert replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Again, using what Ian pointed to:
1) read the current value
2) If Value = “SAMPLE” then Write value = “”
3) (Else do nothing)
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
this is my script but it does not delete the strvalue.
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer
Dim objRegistry
Dim strKeyPath
Dim strValueName
Dim strValue
Dim arrValues
Dim intValue
strComputer = “.”
Set objRegistry=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
strComputer & “\root\default:StdRegProv”)
‘Get String value
strKeyPath = “Software\Microsoft\Windows NT\CurrentVersion\Windows”
strValueName = “AppInit_DLLs”
strValue = “PGPmapih.dll”
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
‘Delete String value
strKeyPath = “Software\Microsoft\Windows NT\CurrentVersion\Windows”
strValueName = “AppInit_DLLs”
objRegistry.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Hi,
Try the below code and let me know…
‘
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)
strKeyPath = “Software\Microsoft\Windows NT\CurrentVersion\Windows”
strStringValueName = “AppInit_DLLs”
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
TBH, you won’t get very far in packaging without some scripting skills.
I don’t normally spoon-feed, but what the hell…some array handling for you to pick the bones out of. It’s completely off the top of my head and untested:
Dim blnResult
Dim arrRegValue
Dim strTempRegValue
Dim strTemp
Dim intArrayIndex_RegValue
Dim blnMatchFound
Const strRegValueSeparator = “,” ‘// or whatever the values are separated with
Const strSearch = “SAMPLE” ‘// this is the text you want removed from strValue
arrRegValue = Split(strValue, strRegValueSeparator)
strTempValue = “”
For intArrayIndex_RegValue = 0 To UBound(arrRegValue)
strTemp = arrRegValue(intArrayIndex_RegValue)
blnResult = StringMatch(strTemp, strSearch, blnMatchFound)
If blnResult Then
If Not blnMatchFound Then
‘// The strings didn’t match the one we’re searching for so add it to the temporary variable
If Len(strTempValue) = 0 Then
strTempValue = strTemp
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Dim blnResult
Dim arrRegValue
Dim strTempRegValue
Dim strTemp
Dim intArrayIndex_RegValue
Dim blnMatchFound
Const strRegValueSeparator = “,” '// or whatever the values are separated with
Const strSearch = “SAMPLE” '// this is the text you want removed from strValue
arrRegValue = Split(strValue, strRegValueSeparator)
strTempValue = “”
For intArrayIndex_RegValue = 0 To UBound(arrRegValue)
strTemp = arrRegValue(intArrayIndex_RegValue)
blnResult = StringMatch(strTemp, strSearch, blnMatchFound)
If blnResult Then
If Not blnMatchFound Then
'// The strings didn't match the one we're searching for so add it to the temporary variable
If Len(strTempValue) = 0 Then
strTempValue = strTemp
Else
strTempValue = strTempValue & strRegValueSeparator & strTemp
End If
End If
End If
Next
'// Now write strTempValue to registry
'//=========================================================================================================
'// Name: StringMatch
'// Purpose: Checks if two strings match
'// Why not use 'If strFirst = strSecond', you're asking?
'// Well, the 'Equals' operator :
'// – is not very fast (at string comparison)!
'// – compares strings left to right and is smart enough to stop comparing when it spots the first difference, but
'// – is too dumb to first do the most obvious test: comparing the lengths of the strings!
'// Input: strFirst – the first string
'// strSecond – the second string
'// blnMatch – a Boolean indicating whether or not the strings matched
'// Output: None
'// Returns: True/False
'//
'//=========================================================================================================
Function StringMatch(ByVal strFirst, ByVal strSecond, ByRef blnMatch)
StringMatch = True
blnMatch = False
If LenB(strFirst) = LenB(strSecond) Then
blnMatch = (InStrB(1, strFirst, strSecond, vbBinaryCompare) <> 0)
End If
End Function
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
@VBScab. Tnx so much for ur help. here’s a simple one that works but it deletes the whole value instead of the said value mention in script.
Dim WSHShell
Set WSHShell = WScript.CreateObject(“WScript.Shell”)
Dim returnval
returnval= WSHShell.RegRead(“HKLM\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs”)
if instr(returnval, “PGPmapih.dll”) > 0 then
‘”PGPmapih.dll” exists so set it to nothing
WSHShell.Regwrite “HKLM\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs” , “”
end if
applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA
Hi Guys. Tnx all for ur help. Got a working script at the end of the day and sharing it. Script is pasted below.
‘**********************************************************************************************************************************************
‘ This Script performs the following tasks
‘ 1. Checks the Users Permissions to the registry
‘ 2. If the user has access to write to the registry searches to see if the
‘ following registry key exists and return the values: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\APPINIT_DLLS
‘ Searches to see if PGPmapih.dll is a value and strips it out
‘ Replaces the PGPmapih.dll with blanks
‘ 3. Writes all errors etc… to a log file c:\winnt\temp\pgpmapih_fix.log
‘***********************************************************************************************************************************************
‘**************
‘Start of Code
‘**************
On Error Resume Next
Const ForWriting = 2
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.CreateTextFile(“C:\WINNT\Temp\pgpmapih_fix.log”, ForWriting)
‘Declare and Set any variables
pgpvalue = “PGPmapih.dll”
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
strComputer & “\root\default:StdRegProv”)
‘ Check Permissions to see if current user can write to registry
Set StdOut = WScript.StdOut
strKeyPath = “SYSTEM\CurrentControlSet”
oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, _
bHasAccessRight
If bHasAccessRight = True Then
objFile.WriteLine (date & ” ” &Time &” User Has Query Value Access Rights”)
Else
objFile.WriteLine (date & ” ” &Time &” User Does Not Have Query Value Access Rights”)
End If
oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _
bHasAccessRight
If bHasAccessRight = True Then
objFile.WriteLine (date & ” ” &Time &” User Has Set Value Access Rights”)
Else
objFile.WriteLine (date & ” ” &Time &” User Does not have Set Value Access Rights”)
End If
oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_CREATE_SUB_KEY, _
bHasAccessRight
If bHasAccessRight = True Then
objFile.WriteLine (date & ” ” &Time &” User Has Create SubKey Access Rights”)
Else
objFile.WriteLine (date & ” ” &Time &” User Does Not Have Set Create Subkey Access Rights”)
End If
oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, DELETE, bHasAccessRight
If bHasAccessRight = True Then
objFile.WriteLine (date & ” ” &Time &” User Has Delete Access Rights”)
Else
objFile.WriteLine (date & ” ” &Time &” User Does Not have Delete Access Rights”)
End If
‘Change Path to PGP One
strKeyPath = “SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows”
strValueName = “AppInit_DLLs”
‘Search Registry to find the Key
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
objFile.WriteLine (date & ” ” &Time &” Value of Registry Key ” & strvalue)
if isnull(strKeyPath) then
objFile.WriteLine (date & ” ” &Time &” ERROR: Registry Key Path Not Found”)
objFile.Close
wscript.quit
else
If isNull(strvaluename) then
objFile.WriteLine (date & ” ” &Time &” ERROR: Registry Key Does Not Exist on PC”)
objFile.Close
wscript.quit
else
If strvalue = “” then
objFile.WriteLine (date & ” ” &Time &” Registry Key VALUE Is Blank”)
objFile.WriteLine (date & ” ” &Time &” No Need to Run Script, Now Quitting”)
objFile.Close
wscript.quit
else
objFile.WriteLine (date & ” ” &Time &” Registry Key Found”)
end if
end if
newstrvalue = instr(strvalue,pgpvalue)
if newstrvalue = 0 then
objFile.WriteLine (date & ” ” &Time &” PGP Value not found on machine”)
objFile.WriteLine (date & ” ” &Time &” No Need to Run Script, Now Quitting”)
objFile.Close
wscript.quit
else
End if
newstrvalue = Replace(strvalue,pgpvalue,””)
objFile.WriteLine (date & ” ” &Time &” Changing Registry key value to: ” & newstrvalue)
‘Write new Key
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,newstrValue
objFile.WriteLine (date & ” ” &Time &” SUCCESS: Values Written to Registry”)
objFile.WriteLine (date & ” ” &Time &” Closing Script… END…”)
End if
objFile.Close
Wscript.quit
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024