{"id":54673,"date":"2009-01-06T11:51:00","date_gmt":"2009-01-06T11:51:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/01\/06\/hey-scripting-guy-how-can-i-modify-registry-settings-that-configure-windows-explorer\/"},"modified":"2009-01-06T11:51:00","modified_gmt":"2009-01-06T11:51:00","slug":"hey-scripting-guy-how-can-i-modify-registry-settings-that-configure-windows-explorer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-modify-registry-settings-that-configure-windows-explorer\/","title":{"rendered":"Hey, Scripting Guy! How Can I Modify Registry Settings That Configure Windows Explorer?"},"content":{"rendered":"<h2><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" class=\"nearGraphic\" \/> <\/h2>\n<p>Hey, Scripting Guy! Why does it feel like every single default setting in Microsoft Windows is wrong? It is so frustrating to me to spend five minutes changing all the defaults. For example, I open Internet Explorer and there are no system files. I look at files, but there are no file extensions. The names of text files that I put in all capital letters so that they will be easy to find are not capitalized. And when the computer boots up, it takes forever because it is trying to find file shares and printers on the network. I mean it is easy enough to change; it is just time consuming, especially when I am troubleshooting an issue. Can you fix this please?<\/p>\n<p>&#8211; WA<\/p>\n<p><img decoding=\"async\" height=\"5\" width=\"5\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"Spacer\" border=\"0\" \/><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" class=\"nearGraphic\" \/><\/p>\n<p>Hi WA,<\/p>\n<p>As someone who considers himself to be a power user, I most certainly sympathize with your complaint. However, as someone who has a mother who is not a power user and who lives more than 300 miles (482 kilometers) away, I am perfectly content with the defaults. So as much as I appreciate our readers, I will not file a user interface bug for you with the Windows team. What I will do, however, is show you the script I use to set things up the way I like them. <\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"EXC\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td style=\"border-right: #cccccc 1px solid\">\n<p class=\"lastInCell\"><b>Standard disclaimer<\/b>: The script today talks about editing the registry. Microsoft does not support editing the registry. If this script causes your computer to crash or you to gain weight, we warned you. If your cat begins to shed fur abnormally or your dog begins barking at the moon, well these things can happen if you are not careful. Changing the registry is not related to animal behavior or animal husbandry. Please back up your registry before proceeding to run this script. Back up your banking records from your computer. Send all your credit card information to the Scripting Guys, and we will hold all of it for you just in case of disaster. <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<table cellpadding=\"0\" cellspacing=\"0\" class=\"dataTable\" id=\"ECD\">\n<thead><\/thead>\n<tbody>\n<tr valign=\"top\" class=\"record\">\n<td style=\"border-right: #cccccc 1px solid\">\n<p class=\"lastInCell\"><b>Disclaimer about the standard disclaimer<\/b>: Don&#8217;t send us any of your personal information. There&#8217;s a black hole down the hall from us.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The first thing you should do before working with the registry is make sure you are either working in a virtual machine that allows you to roll back changes if you wish, or ensure that you have a good backup of the registry. Jerry Honeycutt has written a number of <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/books\/8762.aspx\">good books about the registry<\/a> for Microsoft Press, as well as a number of excellent articles <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/windowsxp\/using\/setup\/expert\/honeycutt_03march17.mspx\">such as this one<\/a>. <\/p>\n<p>For a good overview of the registry, you can refer to <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/guide\/sas_reg_fzit.mspx?mfr=true\">this article<\/a>. To explore the registry, you can use the <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/tools\/twkmatic.mspx\">Tweakomatic<\/a>, which produces scripts in VBScript. Here is a good <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/begin\/ss0807.mspx\">Sesame Script article<\/a> that provides an overview of the registry. And here is the <a target=\"_blank\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/os\/registry\/default.mspx\">Script Center registry archive<\/a>. <\/p>\n<p>In our script today we will modify several of the registry settings that configure Windows Explorer. Of course before we do that, we may want to see what the settings are. So we will create a script that contains two functions. One function displays the Windows Explorer settings, and the other will configure them. We first define some command-line parameters. To do this, we use the <b>param<\/b> keyword. Because these command-line parameters take effect only if they are present, we make them switched. This gives us the advantage of only retrieving the registry settings, only setting the registry settings, or getting the settings and then setting them as well. This image shows an example of obtaining only the registry settings for Windows Explorer: <\/p>\n<p><img decoding=\"async\" height=\"319\" width=\"500\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/january\/hey0106\/hsg_1_6_09_01.jpg\" alt=\"Image that shows obtaining only the registry settings for Windows Explorer\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The line of code that actually creates the parameter is shown here: <\/p>\n<pre class=\"codeSample\">Param([switch]$get,[switch]$set)<\/pre>\n<p>We then create the <b>Get-ExplorerSettings<\/b> function. It is a scripting best practice to create the functions in the order in which they will be used in the script. If this is not possible, you may choose to arrange the functions alphabetically or by intended use. What you do not want is a jumble of functions whose only arrangement is the order in which you figured out you needed them. To create a function, we use the function key word. Because there is nothing to pass to the function, the parentheses are empty. This is seen here:<\/p>\n<pre class=\"codeSample\">Function Get-ExplorerSettings()<\/pre>\n<p>After we have created the function definition, we create the script block for the <b>Get-ExplorerSettings<\/b> function. The script block begins and ends with curly brackets (which are like <a target=\"_blank\" href=\"http:\/\/en.wikipedia.org\/wiki\/Curly_fries\">curly fries<\/a> only with zero carbs). The cool thing about using Windows PowerShell to read the registry is that you can use the <b>Get-ItemProperty<\/b> cmdlet and specify the path parameter and&mdash;voila!&mdash; you get back all the properties from that registry key. This is seen here in a truncated&nbsp;fashion: <\/p>\n<pre class=\"codeSample\">PS C:\\&gt; Get-ItemProperty -Path HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\nPSPath                                : Microsoft.PowerShell.Core\\Registry::HKEY_CURRENT_USER\\Software\\Microsoft\\Window\n                                        s\\CurrentVersion\\Explorer\\Advanced\nPSParentPath                          : Microsoft.PowerShell.Core\\Registry::HKEY_CURRENT_USER\\Software\\Microsoft\\Window\n                                        s\\CurrentVersion\\Explorer\nPSChildName                           : Advanced\nPSDrive                               : HKCU\nPSProvider                            : Microsoft.PowerShell.Core\\Registry\nHidden                                : 1\nShowCompColor                         : 1\nHideFileExt                           : 0\nDontPrettyPath                        : 1\nShowInfoTip                           : 1\n<\/pre>\n<p>We use the <b>Get-ItemProperty<\/b> cmdlet to return the entire registry key. We store this custom Windows PowerShell object in a variable called <b>$RegExplorer<\/b> as seen&nbsp;here: <\/p>\n<pre class=\"codeSample\">{\n$RegExplorer =  Get-ItemProperty -Path HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\n<\/pre>\n<p>It is time to print out the values we obtained from the registry. However, because we are not interested in everything from the registry key and we would like to explain a bit about the values, we use a subexpression and expanding strings to print out the information in which we are interested. There are two kinds of strings in Windows PowerShell. The first is expanding and the second is literal. The double quotation mark will expand the value of a variable. The problem here is that we want to avoid concatenation by using the expanding string. However, if we do not use a subexpression, we will get an unraveling of the object as seen&nbsp;here: <\/p>\n<pre class=\"codeSample\">PS C:\\&gt; \"Display hidden files and folders is $RegExplorer.SuperHidden\"\nDisplay hidden files and folders is @{Hidden=1; ShowCompColor=1; HideFileExt=0; DontPrettyPath=1; ShowInfoTip=1; HideIc\nons=0; MapNetDrvBtn=0; WebView=0; Filter=0; SuperHidden=1; SeparateProcess=0; ListviewAlphaSelect=0; ListviewShadow=0;\nListviewWatermark=0; TaskbarAnimations=0; StartMenuInit=2; StartButtonBalloonTip=2; ServerAdminUI=0; LoosenRudeAppCheck\n=1; TaskbarSizeMove=0; TaskbarGlomming=1; Start_LargeMFUIcons=1; Start_MinMFU=6; Start_ShowControlPanel=1; Start_Enable\nDragDrop=1; StartMenuFavorites=0; Start_ShowHelp=1; Start_ShowMyComputer=1; Start_ShowMyDocs=1; Start_ShowMyMusic=1; St\nart_ShowMyPics=1; Start_ShowPrinters=1; Start_ShowRun=1; Start_ScrollPrograms=0; Start_ShowSearch=1; Start_ShowSetProgr\namAccessAndDefaults=1; Start_ShowRecentDocs=2; Start_AutoCascade=1; Start_NotifyNewApps=1; Start_AdminToolsRoot=2; Star\ntMenuAdminTools=1; NoNetCrawling=1; FolderContentsInfoTip=1; FriendlyTree=0; WebViewBarricade=1; DisableThumbnailCache=\n0; ShowSuperHidden=0; ClassicViewState=0; PersistBrowsers=0}.SuperHidden\n<\/pre>\n<p>As you can see, everything is displayed. To prevent this unraveling, we use the subexpression to force Windows PowerShell to evaluate what is in the parentheses first and then return the value to the string. We do this for all the property values in which we are interested, as shown&nbsp;here: <\/p>\n<pre class=\"codeSample\">\"Display hidden files and folders is $($RegExplorer.SuperHidden)\"\n\"Hide File extensions is set to $($RegExplorer.HideFileExt)\"\n\"Show system files and folders is set to $($RegExplorer.ShowSuperHidden)\"\n\"Hide desktop icons $($RegExplorer.HideIcons)\"\n\"Use Web view for folders $($RegExplorer.WebView)\"\n\"Display correct file name capitalization $($RegExplorer.DontPrettyPath)\"\n\"Prevent automatically locate file shares and printers $($RegExplorer.NoNetCrawling)\"\n} #end Get-ExplorerSettings\n<\/pre>\n<p>After creating <b>Get-ExplorerSettings<\/b>, it is time to create a function to allow us to change some of the values. The first thing we do is use the <b>function<\/b> keyword to create the <b>Set-ExplorerSettings<\/b> function as seen here: <\/p>\n<pre class=\"codeSample\">Function Set-ExplorerSettings()<\/pre>\n<p>We could have cheaped out and used a series of <b>Set-ItemProperty<\/b> cmdlets, each with a hard-coded value for each property we wished to change. But then we decided that it would be much cooler to use a hash table here. Don&rsquo;t get too excited about the term <i>hash table<\/i>&mdash;it is very similar to the Dictionary Object from VBScript fame. <\/p>\n<p>To create a hash table, you use the ampersand and a set of curly brackets as seen here. Note that each key\/value pair is assigned with an equal sign, and each pair is separated by the semicolon: <\/p>\n<pre class=\"codeSample\">$a = @{\"a\" = 1; \"b\" = 2}<\/pre>\n<p>If you want to know how many items are in the hash table, you can use the count as seen here: <\/p>\n<pre class=\"codeSample\">$a.Count<\/pre>\n<p>To walk through the hash table, you can use the <b>foreach<\/b> statement just like in VBScript. This is seen here: <\/p>\n<pre class=\"codeSample\">foreach($key in $a.keys) { $key; $a[$key] }<\/pre>\n<p>Here you can see the hash table we create named&nbsp;<strong>$regValues<\/strong>: <\/p>\n<pre class=\"codeSample\">{\n $RegValues = @{\n                \"SuperHidden\" = 1 ;\n                \"HideFileExt\" = 0 ;\n                \"ShowSuperHidden\" = 0 ;\n                \"HideIcons\" = 0 ;\n                \"WebView\" = 0 ;\n                \"DontPrettyPath\" = 1 ;\n                \"NoNetCrawling\" = 1\n                                    }\n<\/pre>\n<p>We can now create a variable to hold the path to the registry settings. We call the path variable <b>$path<\/b> (for obvious reasons): <\/p>\n<pre class=\"codeSample\">$path = \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\"<\/pre>\n<p>When that is done, we need to walk through the hash table. To do this we use the <b>foreach<\/b> statement. We use the variable <b>$key<\/b> as the enumerator to keep track of our place in the collection of keys we obtain from the keys property. When we do this, we use the <b>Set-ItemProperty<\/b> cmdlet connect to the path specified in the <b>$path<\/b> variable, connect to the registry property name held in the <b>$key<\/b> variable, and assign the value that is associated with that element from the hash table. The last thing the function does is use an expanding string and a subexpression to print out a confirmation message for each registry key. This message is seen in this image: <\/p>\n<p><img decoding=\"async\" height=\"319\" width=\"500\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/january\/hey0106\/hsg_1_6_09_02.jpg\" alt=\"Image of the confirmation message for each registry key\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The complete <b>foreach<\/b> statement is shown&nbsp;here: <\/p>\n<pre class=\"codeSample\">ForEach ($key in $RegValues.Keys)\n  {\n    Set-ItemProperty -path $path -name $key -value $RegValues[$key]\n   \"Setting $path $($key) to $($RegValues[$key])\"\n  }\n} #end Set-ExplorerSettings\n<\/pre>\n<p>After&nbsp;that has been done, it is time to evaluate the command-line parameters to see which function gets called. To do this, we use the <b>if<\/b> statement. If the script was run with the <b>&ndash;get<\/b> parameter, the <b>Get-ExplorerSettings<\/b> function is called. If the script was run with the <b>&ndash;set<\/b> parameter, the <b>Set-ExplorerSettings<\/b> function is called. If both parameters are used, both functions will run. This is seen in this image: <\/p>\n<p><img decoding=\"async\" height=\"319\" width=\"500\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/january\/hey0106\/hsg_1_6_09_03.jpg\" alt=\"Image that shows which functions are called\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Here is the code that evaluates the command line: <\/p>\n<pre class=\"codeSample\">if($get) { Get-ExplorerSettings }\nif($set) { Set-ExplorerSettings }\n<\/pre>\n<p>The complete script is uploaded to the Scripting Guys Script Repository. You can <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/8ac61441-1ad2-4334-b69c-f9189c605f83?SRC=Home\">download the script from that location <\/a>&#8230; remember to save the file with a .ps1 file extension. <\/p>\n<p>Well, WA, that is about it for today. Remember that you can use Tweakomatic to easily discover additional things you could configure by using this technique. See you tomorrow as we continue registry week.<\/p>\n<p style=\"padding-right: 0px;padding-left: 0px;font-size: 11px;padding-bottom: 1em;margin: 0px;line-height: 15px;padding-top: 0px;font-family: Verdana, Arial, Helvetica, sans-serif\"><span style=\"font-family: Verdana;font-size: small\"><span class=\"Apple-style-span\" style=\"font-size: 11px;line-height: 15px\"><b><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/b><\/span><\/span><\/p>\n<p><span style=\"font-family: Verdana;font-size: small\"><b>&nbsp;<\/b><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Why does it feel like every single default setting in Microsoft Windows is wrong? It is so frustrating to me to spend five minutes changing all the defaults. For example, I open Internet Explorer and there are no system files. I look at files, but there are no file extensions. The names [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,47,31,26,3,226,45],"class_list":["post-54673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-management-tasks","tag-operating-system","tag-registry","tag-scripting-guy","tag-windows-explorer","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Why does it feel like every single default setting in Microsoft Windows is wrong? It is so frustrating to me to spend five minutes changing all the defaults. For example, I open Internet Explorer and there are no system files. I look at files, but there are no file extensions. The names [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=54673"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54673\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=54673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=54673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=54673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}