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"
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Seriously? Well, you asked for it! :) http://www.lmgtfy.com/?q=vbscript+delete+registry+value
Answered 11/30/2009 by: VBScab
Red Belt

Please log in to comment
0
While using the Google hint Ian gave you; you want to set an entry to empty ("") and not delete it
Answered 11/30/2009 by: AngelD
Red Belt

Please log in to comment
0
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
Answered 11/30/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
Again, using what Ian pointed to:

1) read the current value
2) If Value = "SAMPLE" then Write value = ""
3) (Else do nothing)
Answered 11/30/2009 by: pjgeutjens
Red Belt

Please log in to comment
0

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
It would have saved you a considerable amount of time if you had defined the problem more precisely at the outset.

Presumably the entries in the value are separated in some way? If the entry is a REG_MULTI_SZ, the separator will be a null string (Chr(0)). Whatever the separator is, get the value, then use Split (I'm presuming that your script will be VBS-driven) to create an array. Then, you simply loop through the array, looking for "SAMPLE". Everything except that string gets written to a temporary variable, and, when the loop completes, write the contents of the temporary string to the registry entry.
Answered 11/30/2009 by: VBScab
Red Belt

Please log in to comment
0
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
Answered 11/30/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
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

'-----------------------------------------------------------------
Answered 11/30/2009 by: WSPPackager
Senior Purple Belt

Please log in to comment
0
tnx. your script works but it deletes the StringValueName. All i want is the Strvalue "PGPmapih.dll" to be deleted not the all Strvaluename.
Answered 12/01/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
Continue to ignore my post, that'll be key to your success. I wonder why I bother sometimes...
Answered 12/01/2009 by: VBScab
Red Belt

Please log in to comment
0
@VBScab, am not trying to ignore ur post. The problem is am new to vbscripting and i don't know how to go about the logic you said. Would be glad if you can help with the script.
Answered 12/01/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
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
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
Answered 12/01/2009 by: VBScab
Red Belt

Please log in to comment
0
@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
Answered 12/01/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
it deletes the whole value instead of the said value It would.

You need to add the code I supplied. If you want me to do your job for you, do say and I'll provide a quote.

That may sound harsh but learning is mostly about following examples, getting it wrong, fixing it and so on.
Answered 12/01/2009 by: VBScab
Red Belt

Please log in to comment
0
nice one mate. wots ur quote
Answered 12/01/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
That's commercially sensitive information. PM me an email address and I'll send you a quote.
Answered 12/01/2009 by: VBScab
Red Belt

Please log in to comment
0
[email=gizmolala@yahoo.com]gizmolala@yahoo.com[/email] ASAP.
Answered 12/01/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
Hey gizmolala... first problem (in my opinion) was choosing VBScript for this. Registry manipulation is a built in function of AutoIT and SMS Installer and Wise InstallMaster and Wise Script Express... just to be more informative.
Answered 12/01/2009 by: AutomateIT
Senior Yellow Belt

Please log in to comment
0
Auto,

It would be the same problem with the other solutions if you don't know how to use them, don't you think?
Answered 12/01/2009 by: AngelD
Red Belt

Please log in to comment
0
Not at all... I'm seeing lines and lines of VBScript for what would be one line in tools that are designed for this type of scripting. Lets keep a focus on the processes and not get stuck on the tool.
Answered 12/01/2009 by: AutomateIT
Senior Yellow Belt

Please log in to comment
0
I would *love* to see a legible one-line script which reads a registry value, parses it for a string which needs to be removed, removes that string and then re-writes the edited string back to the registry...
Answered 12/02/2009 by: VBScab
Red Belt

Please log in to comment
0
ORIGINAL: AutomateIT

Not at all... I'm seeing lines and lines of VBScript for what would be one line in tools that are designed for this type of scripting. Lets keep a focus on the processes and not get stuck on the tool.


One line to instantiate the WMI registry provider. One line to read the value, One if/then block to determine if it's a value to be overwritten, one more line to write an empty string to the value.

Sounds like five whole lines to me, all the rest is error handling and abstraction that isn't strictly necessary. I realize tools with greater ease-of-use are appealing, but the readily available information and ridiculous flexibility of VBscript is what makes it the de facto tool of choice for a large number of people.
Answered 12/02/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
With the addition of the logic to verify the current contents of the registry key value, which I see was added after the original posting. We are at about 4 lines of SMS Installer script.

My point is simply that there are many tools available with a perhaps more suitable "place" for each of them. Just trying to provide some insight.

Sample
Answered 12/02/2009 by: AutomateIT
Senior Yellow Belt

Please log in to comment
0
Insight is all very well but, as is all too common, the script sample has ZERO error-trapping. Hardly surprising, since error handling in SMS Installer (an early version of WiseScript, of course) is on par with DOS batch, i.e. to all intents and purposes utterly useless.

What happens if the registry key being queried is permissioned such that the user can't read it? Failure. Any message presented to the user? Nah...why would the user be interested whether the script worked or not, eh?

Oh, and BTW, you have also failed to read the thread, since your example merely sets the value data to a null string. The OP wants to remove ONE ELEMENT from the data therein.
Answered 12/02/2009 by: VBScab
Red Belt

Please log in to comment
0
Perhaps you might differentiate opinion with fact, so those who know better disregard your posts.
Answered 12/02/2009 by: AutomateIT
Senior Yellow Belt

Please log in to comment
0
Down to ad hominem in twelve posts? Most impressive.

The various wrapper "languages" that have been developed out there can certainly be effective, they have technical limitations in what they can accomplish. They are certainly easy to use, but why learn a product with inherent limitations, when you could be using a language with direct access to other API's, WMI, etc..., as well as reporting and control that's as robust and flexible as you can imagine?

I guess it doesn't make sense to me to use kiddie blocks when you could build with something real instead.
Answered 12/02/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
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
Answered 12/04/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
0
There! Nice one. Wasn't so hard, was it? :)

Some notes...

- Please use the CODE tag when posting code or other lengthy text. Access that tag by clicking the button marked 'code' (or '<%' in older browsers/FireFox)
- The CheckAccess parameters can be added together so you can check "combined" permissions in one hit. See here for details.
- You need additional error-trapping. Check that object's got created (If IsObject...), even the common ones like FileSystemObject. You assume, for example, that strKeyPath exists. How does your current script behave if it doesn't exist? Remember: defensive programming. ALWAYS assume that a script WILL fail and code accordingly.
- Rather than continuously access an object, use the With...End With construct. For example, rather than: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
use:With objFile
If strvalue = "" Then
.WriteLine (date & " " &Time &" Registry Key VALUE Is Blank")
.WriteLine (date & " " &Time &" No Need to Run Script, Now Quitting")
.Close
wscript.quit
Else
.WriteLine (date & " " &Time &" Registry Key Found")
End If
End With

- You could build the log data as you go, only writing it to the log file at the end.
- Nice use of Replace. I hadn't thought of that.
Answered 12/04/2009 by: VBScab
Red Belt

Please log in to comment
0
tnx VBScab
Answered 12/09/2009 by: gizmolala
Third Degree Blue Belt

Please log in to comment
Answer this question or Comment on this question for clarity