{"id":1392,"date":"2017-12-04T08:50:35","date_gmt":"2017-12-04T08:50:35","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=1392"},"modified":"2020-01-09T09:30:03","modified_gmt":"2020-01-09T09:30:03","slug":"vbscript-to-delete-registry-value-data","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/vbscript-to-delete-registry-value-data\/","title":{"rendered":"VbScript To Delete Registry Value Data"},"content":{"rendered":"<p><strong>deployexpert created the topic: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nHi everyone,<\/p>\n<p>Need an urgent help. Need a script to delete a registry value. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows]<br \/>\n&#8220;AppInit_DLLs&#8221;=&#8221;SAMPLE&#8221;<\/p>\n<p>I only want to delete the data value &#8220;SAMPlE&#8221;<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nSeriously? Well, you asked for it! \ud83d\ude42 <a href=\"http:\/\/www.lmgtfy.com\/?q=vbscript+delete+registry+value\" target=\"_blank\" rel=\"noopener\">www.lmgtfy.com\/?q=vbscript+delete+registry+value  <\/a><\/p>\n<p><strong>deployexpert replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nWhile using the Google hint Ian gave you; you want to set an entry to empty (&#8220;&#8221;) and not delete it<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nThanks for ur help.<br \/>\nI only want to delete the value data = &#8220;SAMPLE&#8221; if it exist in [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows]<br \/>\n&#8220;AppInit_DLLs&#8221;=&#8221;SAMPLE&#8221;<\/p>\n<p>The AppInit_DLLs has different values in it. Just want to delete the value &#8220;SAMPLE&#8221; in the value data<\/p>\n<p><strong>deployexpert replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nAgain, using what Ian pointed to:<\/p>\n<p>1) read the current value<br \/>\n2) If Value = &#8220;SAMPLE&#8221; then Write value = &#8220;&#8221;<br \/>\n3) (Else do nothing)<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nthis is my script but it does not delete the strvalue.<\/p>\n<p>Option Explicit<br \/>\nConst HKEY_LOCAL_MACHINE = &#038;H80000002<\/p>\n<p>Dim strComputer<br \/>\nDim objRegistry<br \/>\nDim strKeyPath<br \/>\nDim strValueName<br \/>\nDim strValue<br \/>\nDim arrValues<br \/>\nDim intValue<\/p>\n<p>strComputer = &#8220;.&#8221;<br \/>\nSet objRegistry=GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\\\&#8221; &#038;_<br \/>\nstrComputer &#038; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>&#8216;Get String value<br \/>\nstrKeyPath = &#8220;Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows&#8221;<br \/>\nstrValueName = &#8220;AppInit_DLLs&#8221;<br \/>\nstrValue = &#8220;PGPmapih.dll&#8221;<br \/>\nobjRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue<\/p>\n<p>&#8216;Delete String value<br \/>\nstrKeyPath = &#8220;Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows&#8221;<br \/>\nstrValueName = &#8220;AppInit_DLLs&#8221;<br \/>\nobjRegistry.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nHi,<\/p>\n<p>Try the below code and let me know&#8230;<\/p>\n<p>&#8216;<br \/>\nConst HKEY_LOCAL_MACHINE = &#038;H80000002<br \/>\nstrComputer = &#8220;.&#8221;<\/p>\n<p>Set oReg=GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\\\&#8221; &#038; _<br \/>\n  strComputer &#038; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>strKeyPath = &#8220;Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows&#8221;<br \/>\nstrStringValueName = &#8220;AppInit_DLLs&#8221;<\/p>\n<p>oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nTBH, you won&#8217;t get very far in packaging without some scripting skills.<\/p>\n<p>I don&#8217;t normally spoon-feed, but what the hell&#8230;some array handling for you to pick the bones out of. It&#8217;s completely off the top of my head and untested:<\/p>\n<p>Dim blnResult<br \/>\nDim arrRegValue<br \/>\nDim strTempRegValue<br \/>\nDim strTemp<br \/>\nDim intArrayIndex_RegValue<br \/>\nDim blnMatchFound<\/p>\n<p>Const strRegValueSeparator    = &#8220;,&#8221;        &#8216;\/\/ or whatever the values are separated with<br \/>\nConst strSearch            = &#8220;SAMPLE&#8221;    &#8216;\/\/ this is the text you want removed from strValue<\/p>\n<p>arrRegValue            = Split(strValue, strRegValueSeparator)<\/p>\n<p>strTempValue            = &#8220;&#8221;<\/p>\n<p>For intArrayIndex_RegValue = 0 To UBound(arrRegValue)<br \/>\n  strTemp            = arrRegValue(intArrayIndex_RegValue)<br \/>\n  blnResult        = StringMatch(strTemp, strSearch, blnMatchFound)<br \/>\n  If blnResult Then<br \/>\n      If Not blnMatchFound Then<br \/>\n          &#8216;\/\/ The strings didn&#8217;t match the one we&#8217;re searching for so add it to the temporary variable<br \/>\n          If Len(strTempValue) = 0 Then<br \/>\n              strTempValue = strTemp<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nDim blnResult<br \/>\nDim arrRegValue<br \/>\nDim strTempRegValue<br \/>\nDim strTemp<br \/>\nDim intArrayIndex_RegValue<br \/>\nDim blnMatchFound<\/p>\n<p>Const strRegValueSeparator     = &#8220;,&#8221;        &#039;\/\/ or whatever the values are separated with<br \/>\nConst strSearch            = &#8220;SAMPLE&#8221;    &#039;\/\/ this is the text you want removed from strValue<\/p>\n<p>arrRegValue            = Split(strValue, strRegValueSeparator)<\/p>\n<p>strTempValue            = &#8220;&#8221;<\/p>\n<p>For intArrayIndex_RegValue = 0 To UBound(arrRegValue)<br \/>\n   strTemp            = arrRegValue(intArrayIndex_RegValue)<br \/>\n   blnResult        = StringMatch(strTemp, strSearch, blnMatchFound)<br \/>\n   If blnResult Then<br \/>\n       If Not blnMatchFound Then<br \/>\n           &#039;\/\/ The strings didn&#039;t match the one we&#039;re searching for so add it to the temporary variable<br \/>\n           If Len(strTempValue) = 0 Then<br \/>\n               strTempValue = strTemp<br \/>\n           Else<br \/>\n               strTempValue =     strTempValue &#038; strRegValueSeparator &#038; strTemp<br \/>\n           End If<br \/>\n       End If<br \/>\n   End If<br \/>\nNext<\/p>\n<p>&#039;\/\/ Now write strTempValue to registry<\/p>\n<p>&#039;\/\/=========================================================================================================<br \/>\n&#039;\/\/    Name:    StringMatch<br \/>\n&#039;\/\/ Purpose:    Checks if two strings match<br \/>\n&#039;\/\/                Why not use &#039;If strFirst = strSecond&#039;, you&#039;re asking?<br \/>\n&#039;\/\/                Well, the &#039;Equals&#039; operator :<br \/>\n&#039;\/\/                   &#8211; is not very fast (at string comparison)!<br \/>\n&#039;\/\/                   &#8211; compares strings left to right and is smart enough to stop comparing when it spots the first difference, but<br \/>\n&#039;\/\/                   &#8211; is too dumb to first do the most obvious test: comparing the lengths of the strings!<br \/>\n&#039;\/\/   Input:    strFirst                &#8211; the first string<br \/>\n&#039;\/\/        strSecond                &#8211; the second string<br \/>\n&#039;\/\/        blnMatch                &#8211; a Boolean indicating whether or not the strings matched<br \/>\n&#039;\/\/  Output:    None<br \/>\n&#039;\/\/ Returns:    True\/False<br \/>\n&#039;\/\/<br \/>\n&#039;\/\/=========================================================================================================<br \/>\nFunction StringMatch(ByVal strFirst, ByVal strSecond, ByRef blnMatch)<\/p>\n<p>   StringMatch = True<\/p>\n<p>   blnMatch = False<\/p>\n<p>   If LenB(strFirst) = LenB(strSecond) Then<br \/>\n       blnMatch = (InStrB(1, strFirst, strSecond, vbBinaryCompare) <> 0)<br \/>\n   End If<\/p>\n<p>End Function<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\n@VBScab. Tnx so much for ur help. here&#8217;s a simple one that works but it deletes the whole value instead of the said value mention in script.<br \/>\nDim WSHShell<br \/>\nSet WSHShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\nDim returnval<br \/>\nreturnval= WSHShell.RegRead(&#8220;HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_DLLs&#8221;)<\/p>\n<p>if instr(returnval, &#8220;PGPmapih.dll&#8221;) > 0 then<br \/>\n&#8216;&#8221;PGPmapih.dll&#8221; exists so set it to nothing<br \/>\nWSHShell.Regwrite &#8220;HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\AppInit_DLLs&#8221; , &#8220;&#8221;<br \/>\nend if<\/p>\n<p><strong>applicationPackaging replied the topic: Re: VBSCRIPT TO DELETE REGISTRY VALUE DATA<\/strong><br \/>\nHi Guys. Tnx all for ur help. Got a working script at the end of the day and sharing it. Script is pasted below.<\/p>\n<p>&#8216;**********************************************************************************************************************************************<br \/>\n&#8216; This Script performs the following tasks<br \/>\n&#8216; 1. Checks the Users Permissions to the registry<br \/>\n&#8216; 2. If the user has access to write to the registry searches to see if the<br \/>\n&#8216;    following registry key exists and return the values: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\APPINIT_DLLS<br \/>\n&#8216;    Searches to see if PGPmapih.dll is a value and strips it out<br \/>\n&#8216;    Replaces the PGPmapih.dll with blanks<br \/>\n&#8216; 3. Writes all errors etc&#8230; to a log file c:\\winnt\\temp\\pgpmapih_fix.log<br \/>\n&#8216;***********************************************************************************************************************************************<\/p>\n<p>&#8216;**************<br \/>\n&#8216;Start of Code<br \/>\n&#8216;**************<\/p>\n<p>On Error Resume Next<\/p>\n<p>Const ForWriting = 2<br \/>\nSet objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet objFile = objFSO.CreateTextFile(&#8220;C:\\WINNT\\Temp\\pgpmapih_fix.log&#8221;, ForWriting)<\/p>\n<p>&#8216;Declare and Set any variables<br \/>\npgpvalue = &#8220;PGPmapih.dll&#8221;<br \/>\nconst HKEY_LOCAL_MACHINE = &#038;H80000002<br \/>\nstrComputer = &#8220;.&#8221;<br \/>\nSet oReg=GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\\\&#8221; &#038;_<br \/>\nstrComputer &#038; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>&#8216; Check Permissions to see if current user can write to registry<br \/>\nSet StdOut = WScript.StdOut<br \/>\nstrKeyPath = &#8220;SYSTEM\\CurrentControlSet&#8221;<\/p>\n<p>oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, _<br \/>\n  bHasAccessRight<br \/>\nIf bHasAccessRight = True Then<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Has Query Value Access Rights&#8221;)<br \/>\nElse<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Does Not Have Query Value Access Rights&#8221;)<br \/>\nEnd If <\/p>\n<p>oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _<br \/>\n  bHasAccessRight<br \/>\nIf bHasAccessRight = True Then<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Has Set Value Access Rights&#8221;)<br \/>\nElse<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Does not have Set Value Access Rights&#8221;)<br \/>\nEnd If <\/p>\n<p>oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_CREATE_SUB_KEY, _<br \/>\n  bHasAccessRight<br \/>\nIf bHasAccessRight = True Then<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Has Create SubKey Access Rights&#8221;)<br \/>\nElse<br \/>\n  objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Does Not Have Set Create Subkey Access Rights&#8221;)<br \/>\nEnd If<\/p>\n<p>oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, DELETE, bHasAccessRight<br \/>\nIf bHasAccessRight = True Then<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Has Delete Access Rights&#8221;)<br \/>\nElse<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; User Does Not have Delete Access Rights&#8221;)<br \/>\nEnd If<\/p>\n<p>&#8216;Change Path to PGP One<br \/>\nstrKeyPath = &#8220;SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows&#8221;<br \/>\nstrValueName = &#8220;AppInit_DLLs&#8221;<\/p>\n<p>&#8216;Search Registry to find the Key<br \/>\noReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; Value of Registry Key &#8221; &#038; strvalue)<\/p>\n<p>if isnull(strKeyPath) then<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; ERROR: Registry Key Path Not Found&#8221;)<br \/>\nobjFile.Close<br \/>\nwscript.quit<br \/>\nelse<\/p>\n<p>If isNull(strvaluename) then<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; ERROR: Registry Key Does Not Exist on PC&#8221;)<br \/>\nobjFile.Close<br \/>\nwscript.quit<br \/>\nelse<\/p>\n<p>If strvalue = &#8220;&#8221; then<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; Registry Key VALUE Is Blank&#8221;)<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; No Need to Run Script, Now Quitting&#8221;)<br \/>\nobjFile.Close<br \/>\nwscript.quit<br \/>\nelse<\/p>\n<p>objFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; Registry Key Found&#8221;)<\/p>\n<p>end if<br \/>\nend if<\/p>\n<p>newstrvalue = instr(strvalue,pgpvalue)<br \/>\nif newstrvalue = 0 then<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; PGP Value not found on machine&#8221;)<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; No Need to Run Script, Now Quitting&#8221;)<br \/>\nobjFile.Close<br \/>\nwscript.quit<\/p>\n<p>else<br \/>\nEnd if<br \/>\nnewstrvalue = Replace(strvalue,pgpvalue,&#8221;&#8221;)<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; Changing Registry key value to: &#8221; &#038; newstrvalue)<\/p>\n<p>&#8216;Write new Key<br \/>\noReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,newstrValue<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; SUCCESS: Values Written to Registry&#8221;)<br \/>\nobjFile.WriteLine (date &#038; &#8221; &#8221; &#038;Time  &#038;&#8221; Closing Script&#8230; END&#8230;&#8221;)<br \/>\nEnd if<br \/>\nobjFile.Close<br \/>\nWscript.quit<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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] &#8220;AppInit_DLLs&#8221;=&#8221;SAMPLE&#8221; I only want&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[49],"tags":[291],"class_list":["post-1392","post","type-post","status-publish","format-standard","hentry","category-general","tag-registry"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=1392"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1392\/revisions"}],"predecessor-version":[{"id":1393,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/1392\/revisions\/1393"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}