{"id":2372,"date":"2016-07-03T23:41:16","date_gmt":"2016-07-04T06:41:16","guid":{"rendered":"http:\/\/www.coretechnologies.com\/blog\/?p=2372"},"modified":"2022-05-01T22:27:08","modified_gmt":"2022-05-02T05:27:08","slug":"trouble-reading-registry","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trouble-reading-registry\/","title":{"rendered":"Why does my Application have Trouble Reading the Registry?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/windows-registry.webp\" width=\"256\" height=\"256\" border=\"0\" title=\"Registry trouble with windows service\" alt=\"Registry trouble with windows service\" \/><\/div>\n<h2><b>The Problem<\/b><\/h2>\n<p>Tod Daniels of <a href=\"http:\/\/www.dinnovative.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">d&#8217;innovative<\/a> reported a strange problem. His <a href=\"https:\/\/en.wikipedia.org\/wiki\/JScript\" target=\"_blank\" rel=\"noopener noreferrer\">JScript<\/a> file (run with <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/bb490887.aspx?f=255&#038;MSPPError=-2147217396\" target=\"_blank\" rel=\"noopener noreferrer\">Microsoft&#8217;s CSCRIPT.EXE<\/a>) started fine from his desktop but failed when run as a windows service with AlwaysUp.<\/p>\n<p>By <a href=\"http:\/\/www.coretechnologies.com\/blog\/alwaysup\/troubleshoot-alwaysup-command-prompt\/\">troubleshooting the situation from the command line<\/a>, Tod was able to narrow the problem down to a problem when reading from the registry. Specifically:<\/p>\n<ul>\n<li>\n<b>regedit \/e F:\\test1.reg &#8220;HKEY_LOCAL_MACHINE\\Software\\<wbr\/>Broadcom\\<wbr\/>BACS&#8221;<\/b> run outside AlwaysUp produces a file containing the registry export.\n<\/li>\n<li>\n<b>regedit \/e F:\\test2.reg &#8220;HKEY_LOCAL_MACHINE\\Software\\<wbr\/>Broadcom\\<wbr\/>BACS&#8221;<\/b> run inside an AlwaysUp CMD session does not produce a file.\n<\/li>\n<\/ul>\n<p>Both commands were run in the same user account, so why the different results?<\/p>\n<h2><b>The Solution<\/b><\/h2>\n<p>The discrepancy is due to the different views of the registry presented to 32-bit and 64-bit applications.<\/p>\n<p>Most modern versions of Windows are 64-bit. All the major applications and supporting DLLs distributed with the OS are 64-bit. To ensure that older 32-bit applications continue to run fine on these new operating systems, Microsoft engages in some &#8220;creative trickery&#8221;:<\/p>\n<ul>\n<li>\n<h3>32-bit applications see a 32-bit version of the System32 Folder<\/h3>\n<p>\nEven though the Windows System32 folder (typically, C:\\Windows\\System32) is stocked with 64-bit applications, a 32-bit application has that folder &#8220;mapped&#8221; to a counterpart (C:\\Windows\\System32\\Wow64) filled with 32-bit versions instead. So when a 32-bit application runs the &#8220;DIR&#8221; or &#8220;REGEDIT&#8221; commands, it is actually invoking the 32-bit version in the Wow64 folder. This silent mapping ensures compatibility when a 32-bit application invokes one of those standard Windows utilities.\n<\/p>\n<p>\nAlwaysUp is a 32-bit application and is constrained by this behavior. When we&#8217;re troubleshooting, the command prompt is launching the 32-bit version of regedit.\n<\/p>\n<\/li>\n<li>\n<h3>64-bit applications work with a (slightly) different view of the Registry<\/h3>\n<p>In the 64-bit operating systems, some registry keys actually have a 32-bit version and a 64-bit version! One such key is HKLM\\Software. 32-bit applications can write to this key normally, however the changes show up under HKLM\\Software\\Wow64 instead. A 64-bit application can see both versions of the keys and can choose which version to access.<\/p>\n<\/li>\n<\/ul>\n<p>\nNow Tod is using Windows Server 2012 R2 which is 64-bit. Our &#8220;a-ha&#8221; moment came when we noticed that this key exists:<\/p>\n<blockquote><p><b>HKEY_LOCAL_MACHINE\\Software\\<wbr\/>Broadcom\\<wbr\/>BACS<\/b><\/p><\/blockquote>\n<p>but the corresponding 32-bit key does not:<\/p>\n<blockquote><p><b>HKEY_LOCAL_MACHINE\\Software\\<wbr\/>WOW6432Node\\<wbr\/>Broadcom\\<wbr\/>BACS<\/b><\/p><\/blockquote>\n<p>This discrepancy means that 64-bit applications can access <span class=\"break-long-words\">HKEY_LOCAL_MACHINE\\Software\\Broadcom\\BACS<\/span> while 32-bit applications cannot see a registry entry with that same name.\n<\/p>\n<p>Tod was able to start the 64-bit version of regedit from AlwaysUp by exploiting another bit of Microsoft trickery &#8212; the <a href=\"http:\/\/www.samlogic.net\/articles\/sysnative-folder-64-bit-windows.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Sysnative folder<\/a>. This is the full path that enabled regedit to find the Broadcom key:<\/p>\n<blockquote><p><b>C:\\Windows\\Sysnative\\regedit \/e F:\\test1.reg &#8220;HKEY_LOCAL_MACHINE\\<wbr\/>Software\\<wbr\/>Broadcom\\<wbr\/>BACS&#8221;<\/b><\/p><\/blockquote>\n<p>\nUltimately he was able to launch the 64-bit version of CSCRIPT from the same path and his application is now functioning as expected as a Windows Service!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/dropbox-software\/how-to-fix-opengl-problem\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Start Dropbox whenever your PC boots\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/dropbox-logo2-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to Fix the &quot;OpenGL&quot; Problem when Running Dropbox as a Windows Service<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/software\/google-drive-discontinued\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Goodbye Google Drive, Hello Backup and Sync!\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/backup-and-sync-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Goodbye Google Drive, Hello Backup and Sync!<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-service-no-task-scheduler\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"How to Make AlwaysUp Restart your Program Multiple Times per Day (without using the Task Scheduler)\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/stopwatch-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">How to Make AlwaysUp Restart your Program Multiple Times per Day (without using the Task Scheduler)<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>The Problem Tod Daniels of d&#8217;innovative reported a strange problem. His JScript file (run with Microsoft&#8217;s CSCRIPT.EXE) started fine from his desktop but failed when run as a windows service with AlwaysUp. By troubleshooting the situation from the command line, &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trouble-reading-registry\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2466,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[19,21,26,131,132],"class_list":["post-2372","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-32-bit","tag-64-bit","tag-alwaysup-tag","tag-regedit","tag-registry"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=2372"}],"version-history":[{"count":3,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2372\/revisions"}],"predecessor-version":[{"id":11280,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/2372\/revisions\/11280"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/2466"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=2372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=2372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=2372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}