{"id":1641,"date":"2009-08-18T02:43:47","date_gmt":"2009-08-18T10:43:47","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=1641"},"modified":"2009-08-18T09:38:48","modified_gmt":"2009-08-18T17:38:48","slug":"registry-access-from-32-to-64-bit-and-back","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2009\/08\/18\/registry-access-from-32-to-64-bit-and-back\/","title":{"rendered":"Registry access from 32 to 64 bit and back"},"content":{"rendered":"<p>Just recently, I received an email asking how you can access the 64 bit registry from a 32 bit script, or vice versa. The task the individual was facing was to come up with a way to verify installed applications via checking the corresponding Windows Installer registry entries.<\/p>\n<p>For a C++ programmer with access to the API, that really is not a big issue. From VBScript, using only WshShell.RegRead that is a completely different story. A quick consult with some fellow script experts revealed that the only real way was using WMI and the StdRegProvider. The main complaint I heard though was that this was a rather slow and sluggish way of doing it.<\/p>\n<p>So I decided to pick up the slack and create a new COM component that makes accessing the registry a bit simpler than using WMI, all the while maintaining some of the native API&#8217;s speed.<\/p>\n<pre class=\"code\"><pre class=\"code\"><span style=\"color: blue\">&nbsp;<\/span><\/pre>\n<p><a href=\"http:\/\/11011.net\/software\/vspaste\"><\/a> <a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/08\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"149\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/08\/image_thumb.png\" width=\"244\" border=\"0\"><\/a><\/p>\n<p>The new component is available with PrimalScript builds 5.0.615 and higher. It is automatically installed and registered. Please check out the sample file RegistryAccess.vbs in the PrimalScript samples folder.<\/p>\n<p>Additionally, VBScript expert and all-around scripting guru Alex Angelopoulos was nice enough to help me design the interface and test it by providing two more sample scripts that use this control:<\/p>\n<p><strong>EnumerateControlsWithKillBits.vbs:<\/strong><\/p>\n<p><em>Enumerates GUIDs for controls that have been kill-bitted to not run in IE. (Note that these controls CAN still run in HTAs and other local applications). Shows the flags set for the control as a simple number, and &#8211; if the control is installed and it has a common name listed &#8211; shows the control name and the path to the control.<br \/>Elements are separated by commas. This will give odd-looking output in a console window, but is useful for redirection to a file and later opening in Excel.<\/em><\/p>\n<p><strong>AutoAddScriptRunAs.vbs:<\/strong><\/p>\n<p><em>Simplifies running scripts as privileged processes or with alternate<br \/>credentials.&nbsp; For our purposes, a &#8220;script&#8221; is any file type whose extension is in the environment&#8217;s %pathext% variable (except .com\/.exe\/.msc files since they are handled by Windows already), and ALSO files with the .hta extension.<br \/>This script has the following effects when run:<br \/>(1) On pre-Vista systems, the only apparent change will be a &#8220;Run As&#8221; entry on the context menu allowing you to specify alternate credentials for running a script.<br \/>(2) On Vista and newer, the context menu choice will be a localized variant of &#8220;Run as administrator&#8221; and will show an LUA shield icon next to the choice. Selecting this will cause the script host to request elevation at launch.<br \/>(3) On Windows 7 and newer systems, scripts containing the word<br \/>&#8220;admin&#8221; in their names will automatically attempt to run elevated if you double-click them or run them using the Run dialog. Note that the word admin must be a distinct word separated from other alphanumeric characters in the script name. The following are examples of names that will cause automatic elevation requests in HTA files:<br \/>admin.hta, &#8220;admin file.hta&#8221;, admin-test.hta<br \/>the following will NOT cause automatic elevation requests:<br \/>admintools.hta makemeadmin.hta<br \/>Also note that you can choose to right-click and Open the script without elevation explicitly.<\/em><\/p>\n<p><a href=\"http:\/\/www.sapien.com\/download.aspx?file=regsample\" target=\"_blank\">Click here to download the sample files.<\/a><\/p>\n<p>Below is a brief overview of the methods and properties in this new component:<\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"462\" border=\"1\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"210\"><strong>Property<\/strong><\/td>\n<td valign=\"top\" width=\"250\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">RegistryView<\/td>\n<td valign=\"top\" width=\"250\">Set or returns the current registry view,<br \/>(1 = 32 bit (default), 2 = 64 bit)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">ErrorCode<\/td>\n<td valign=\"top\" width=\"250\">Returns the error code of the last operation. 0 = no error, positive numbers are Windows error codes, negative numbers are internal error codes.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">ErrorDescription<\/td>\n<td valign=\"top\" width=\"250\">Returns the description of the last error indicated in the ErrorCode property<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">Handle<\/td>\n<td valign=\"top\" width=\"250\">Returns the actual HKEY handle value of the currently opened key.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">FullKeyPath<\/td>\n<td valign=\"top\" width=\"250\">Returns the full key path of the currently opened key. Does not operate on remote keys.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">RootKey<\/td>\n<td valign=\"top\" width=\"250\">Returns the root key (HKLM, HKCR, HKEY_CURRENT_USER etc.) of the currently opened key. Does not operate on remote keys.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">SubKeyPath<\/td>\n<td valign=\"top\" width=\"250\">Returns the key path of the currently opened key without the root node specifier. Does not operate on remote keys.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">ReadOnly<\/td>\n<td valign=\"top\" width=\"250\">Sets or returns the content of the read-only flag (default: FALSE), which determines if registry keys are opened with KEY_READ or KEY_ALL_ACCESS<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\"><strong>Methods<\/strong><\/td>\n<td valign=\"top\" width=\"250\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">OpenKey(BaseKey,SubKey,bCreate)<\/td>\n<td valign=\"top\" width=\"250\">Opens a registry key or optionally creates it if it does not exist<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">CloseKey()<\/td>\n<td valign=\"top\" width=\"250\">Closes the handle of the currently opened registry key<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">DeleteKey(BaseKey,SubKey)<\/td>\n<td valign=\"top\" width=\"250\">Deletes an existing registry key. No key must be opened at the time<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">DeleteValue(ValueName)<\/td>\n<td valign=\"top\" width=\"250\">Deletes the specified value in the opened key, use &#8220;&#8221; to delete the default value<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GetValue(ValueName)<\/td>\n<td valign=\"top\" width=\"250\">Returns the content of the specified value, use &#8220;&#8221; to retrieve a key&#8217;s default value<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GetValueType(ValueName)<\/td>\n<td valign=\"top\" width=\"250\">Returns the type of specified value, use &#8220;&#8221; to retrieve a key&#8217;s default value&#8217;s type<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GetValueList()<\/td>\n<td valign=\"top\" width=\"250\">Returns an array with the names of the values under the currently opened key. The default value (empty name) is not included in this list<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GetKeyList()<\/td>\n<td valign=\"top\" width=\"250\">Returns an array with names of the immediate child keys of the currently opened key<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GetSubKey(Key,bCreate)<\/td>\n<td valign=\"top\" width=\"250\">Returns a new object representing the opened handle of the specified subkey.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">SetValue(Name,Value,ValueType)<\/td>\n<td valign=\"top\" width=\"250\">Sets the content of the specified value. Use &#8220;&#8221; to set the content of the default value. Non-existent values will be created automatically.<br \/>Supported value types are: REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ and REG_DWORD<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">SaveKey(FileName)<\/td>\n<td valign=\"top\" width=\"250\">Saves the currently open key as binary data to the specified file. Existing files are overwritten<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">RestoreKey(FileName,bForce)<\/td>\n<td valign=\"top\" width=\"250\">Restores the content of the currently opened key from a binary file previously created with &#8220;SaveKey&#8221;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">ConnectRegistry(MachineName, BaseKey [,&nbsp; UserID][, Password]<\/td>\n<td valign=\"top\" width=\"250\">Opens a root registry handle of a remote machine. You must have administrative rights on the remote computer.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">OpenFromHandle(Handle)<\/td>\n<td valign=\"top\" width=\"250\">Opens the registry key as specified by the handle<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">HasSubKey(key)<\/td>\n<td valign=\"top\" width=\"250\">Indicates if the currently opened key has a child key with the specified name<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">HasValue(Name)<\/td>\n<td valign=\"top\" width=\"250\">Indicates if the currently opened key has the specified value<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">IsKey(BaseKey,SubKey)<\/td>\n<td valign=\"top\" width=\"250\">Returns if the provided key exists. This does not depend on the currently opened key. Does not operate on remote keys<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">IsValue(Basekey,SubKey, ValueName)<\/td>\n<td valign=\"top\" width=\"250\">Returns if the specified value exists. This does not depend on the currently opened key. Does not operate on remote keys<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GotoSubKey(SubKey)<\/td>\n<td valign=\"top\" width=\"250\">Navigates the current key to a child key. Multiple levels can be specified separated by a &#8216;\\&#8217; character. The specified key must exist.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"210\">GotoParentKey()<\/td>\n<td valign=\"top\" width=\"250\">Navigates to the immediate parent key of the currently opened key<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Unless otherwise noted, functions return vbTrue or vbFalse to indicate success or an error.<\/p>\n<p>For feedback, feature requests or error reports please use our <a href=\"http:\/\/support.sapien.com\/forum\/forum_topics.asp?FID=10\" target=\"_blank\">free tools support forum<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just recently, I received an email asking how you can access the 64 bit registry from a 32 bit script, or vice versa. The task the individual was facing was to come up with a way to verify installed applications via checking the corresponding Windows Installer registry entries. For a C++ programmer with access to [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[283,410,21,24,389,26],"tags":[526,525,61,37,31,36,996],"class_list":["post-1641","post","type-post","status-publish","format-standard","hentry","category-howto","category-primalscript-software-news","category-software-news","category-vbscript","category-vbscript-scripts","category-windows-scripting-news","tag-32-bit","tag-64-bit","tag-com","tag-primalscript","tag-registry","tag-remote","tag-vbscript"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=1641"}],"version-history":[{"count":3,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1641\/revisions"}],"predecessor-version":[{"id":1644,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1641\/revisions\/1644"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=1641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=1641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=1641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}