Welcome, Guest
Username Password: Remember me

VBSCRIPT TO DELETE REGISTRY VALUE DATA
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: VBSCRIPT TO DELETE REGISTRY VALUE DATA

VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #893

  • deployexpert
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"

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #894

  • applicationPackaging
Seriously? Well, you asked for it! :) www.lmgtfy.com/?q=vbscript+delete+registry+value 

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #895

  • deployexpert
While using the Google hint Ian gave you; you want to set an entry to empty ("") and not delete it

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #896

  • applicationPackaging
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

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #897

  • deployexpert
Again, using what Ian pointed to:

1) read the current value
2) If Value = "SAMPLE" then Write value = ""
3) (Else do nothing)

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #898

  • applicationPackaging
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

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #899

  • applicationPackaging
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

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

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #900

  • applicationPackaging
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

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #901

  • applicationPackaging
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

Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA 2 years, 5 months ago #902

  • applicationPackaging
@VBScab. Tnx so much for ur help. here&#039;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
&#039;"PGPmapih.dll" exists so set it to nothing
WSHShell.Regwrite "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs" , ""
end if
  • Page:
  • 1
  • 2
Time to create page: 1.04 seconds

     
    
Home Forum