{"id":111,"date":"2009-03-11T22:18:30","date_gmt":"2009-03-12T03:18:30","guid":{"rendered":"http:\/\/nukeitmike.com\/blog\/?p=111"},"modified":"2009-03-11T22:18:30","modified_gmt":"2009-03-12T03:18:30","slug":"another-registry-script","status":"publish","type":"post","link":"https:\/\/blog.nukeitmike.com\/index.php\/2009\/03\/11\/another-registry-script\/","title":{"rendered":"Another Registry Script&#8230;"},"content":{"rendered":"<p>I have the unfortunate need to occasionally fix things in the registry, mostly related to applications running in a Citrix environment.\u00a0 I believe there are nice tools out there that are supposed to do this for you, if given the right information, but I haven&#8217;t bothered to figure out what those tools are or how to use them.\u00a0 Instead, I torture myself with trying to muddle through VBScript and make it do what I want.\u00a0<\/p>\n<p>In that spirit, I am going to show you one of my pitiful scripts (and this one is horrible, because I didn&#8217;t bother to clean it up after I worked out how to make it accomplish the desired goal.\u00a0 So&#8230; here you go:<\/p>\n<p>&#8216;==========================================================================<br \/>\n&#8216;<br \/>\n&#8216; VBScript Source File &#8212; Created with SAPIEN Technologies PrimalScript 2007<br \/>\n&#8216;<br \/>\n&#8216; NAME: BorlandDBPathFix.vbs<br \/>\n&#8216;<br \/>\n&#8216; AUTHOR: Michael Phillips , Brasfield &amp; Gorrie, LLC<br \/>\n&#8216; DATE : March 11, 2009<br \/>\n&#8216;<br \/>\n&#8216; COMMENT: This script is to change the value of 2 registry keys on a per<br \/>\n&#8216; user basis. It should set the value to be the correct system<br \/>\n&#8216; drive (c: or u:).<br \/>\n&#8216; It should also be noted that this script isn&#8217;t very pretty.<br \/>\n&#8216;==========================================================================<br \/>\n&#8216;Registry stuff<br \/>\nConst HKCU = &amp;H80000001 &#8216;This defines the Current User Hive<br \/>\nConst HKLM = &amp;H80000002 &#8216;This defines the Local Machine Hive<br \/>\nConst REG_SZ = 1<br \/>\nConst REG_EXPAND_SZ = 2<br \/>\nConst REG_BINARY = 3<br \/>\nConst REG_DWORD = 4<br \/>\nConst REG_MULTI_SZ = 7<br \/>\nvDebug = 1<br \/>\nDim strComputer<\/p>\n<p>strComputer = &#8220;.&#8221; &#8216;This computer is the &#8220;.&#8221;. If you want another computer, replace the .<\/p>\n<p>Set oReg=GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\\\&#8221; &amp; _<br \/>\nstrComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>sGetPath<br \/>\nSub sGetPath<br \/>\nSet oShell = CreateObject( &#8220;WScript.Shell&#8221; )<br \/>\nstrSystemDrive = oShell.ExpandEnvironmentStrings(&#8220;%systemdrive%&#8221;)<br \/>\n&#8216;* wscript.echo strSystemDrive<br \/>\nfGetRegistryValues strSystemDrive<br \/>\nEnd Sub<\/p>\n<p>&#8216;*<br \/>\n&#8216;* This is what we are looking for:<br \/>\n&#8216;* [HKCU\\Software\\Borland\\BDS\\4.0\\DBExpress]<br \/>\n&#8216;* @=&#8221;&#8221;<br \/>\n&#8216;* &#8220;Connection Registry File&#8221;=&#8221;C:\\\\Program Files\\\\Common Files\\\\Borland Shared\\\\DBExpress\\\\dbxconnections.ini&#8221;<br \/>\n&#8216;* &#8220;Driver Registry File&#8221;=&#8221;C:\\\\Program Files\\\\Common Files\\\\Borland Shared\\\\DBExpress\\\\dbxdrivers.ini&#8221;<br \/>\nFunction fGetRegistryValues (vSystemDrive)<br \/>\n&#8216;* wscript.echo vSystemDrive &amp; &#8221; is being passed as vSystemDrive&#8221;<br \/>\noReg.GetExpandedStringValue HKCU,&#8221;Software\\Borland\\BDS\\4.0\\DBExpress&#8221;,&#8221;Connection Registry File&#8221;,strValue1<br \/>\noReg.GetExpandedStringValue HKCU,&#8221;Software\\Borland\\BDS\\4.0\\DBExpress&#8221;,&#8221;Driver Registry File&#8221;,strValue2<br \/>\nstrDriveLetter1 = Left (strValue1,2)<br \/>\n&#8216;* wscript.echo strDriveLetter1 &amp; strValue1 &amp; strSystemDrive<br \/>\nstrDriveLetter2 = Left (strValue2,2)<br \/>\nIf strDriveLetter1 = vSystemDrive Then<br \/>\nIf strDriveLetter2 = vSystemDrive Then<br \/>\nElse<br \/>\nfSetRegistryValues strValue1,strValue2,vSystemDrive<\/p>\n<p>End If<br \/>\nElse<br \/>\nfSetRegistryValues strValue1,strValue2,vSystemDrive<br \/>\nEnd If<br \/>\nEnd Function<br \/>\nFunction fSetRegistryValues (fValue1,fValue2,fDriveLetter)<br \/>\n&#8216;* wscript.echo &#8220;Bad Letter is being passed &#8221; &amp; fValue1 &amp; fValue2 &amp; fDriveLetter<br \/>\nvLength1 = (Len (fValue1))-2<br \/>\nvLength2 = (Len (fValue2))-2<br \/>\n&#8216;* wscript.echo &#8220;&#8211;strValue1 &amp; vLength1&#8211; &gt;&#8221; &amp; fValue1 &amp; &#8221; &#8221; &amp; vLength1<br \/>\nstrPathNoLetter1 = Right (fValue1,vLength1)<br \/>\nstrNewKeyValue1 = fDriveLetter &amp; strPathNoLetter1<br \/>\nfWriteStringRegistryValues &#8220;Software\\Borland\\BDS\\4.0\\DBExpress&#8221;,&#8221;Connection Registry File&#8221;,strNewKeyValue1<br \/>\n&#8216;* wscript.echo strNewKeyValue1<\/p>\n<p>strPathNoLetter2 = Right (fValue2,vLength2)<br \/>\nstrNewKeyValue2 = fDriveLetter &amp; strPathNoLetter2<br \/>\nfWriteStringRegistryValues &#8220;Software\\Borland\\BDS\\4.0\\DBExpress&#8221;,&#8221;Driver Registry File&#8221;,strNewKeyValue2<br \/>\n&#8216;* wscript.echo (fDriveLetter &amp; (Right (fValue2,vLength2)))<br \/>\nEnd Function<\/p>\n<p>Function fWriteStringRegistryValues (fvRegistryKeyPath,fvRegistryKeyName,fvRegistryKeyValue)<br \/>\nIf vDebug = 1 Then<br \/>\n&#8216;* wscript.echo &#8220;Begining Function -fWriteStringRegistryValues-.&#8221;<br \/>\nEnd If<br \/>\n&#8216; This function takes input to write string values to the registry. Key must already exist.<br \/>\noReg.SetStringValue HKCU,fvRegistryKeyPath,fvRegistryKeyName,fvRegistryKeyValue<br \/>\nEnd Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have the unfortunate need to occasionally fix things in the registry, mostly related to applications running in a Citrix environment.\u00a0 I believe there are nice tools out there that are supposed to do this for you, if given the right information, but I haven&#8217;t bothered to figure out what those tools are or how&hellip; <a class=\"more-link\" href=\"https:\/\/blog.nukeitmike.com\/index.php\/2009\/03\/11\/another-registry-script\/\">Continue reading <span class=\"screen-reader-text\">Another Registry Script&#8230;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,25],"tags":[147,186],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-humor","category-scripting","tag-registry","tag-vbscript","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pcW544-1N","_links":{"self":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}