Toggle IE Debugging Setting with PowerShell
Recently I’ve been working in JavaScript and found that by default the ability to debug into JavaScript in IE using Visual Studio is turned off. It makes some sense that this is the case since the the majority of the users really don’t need to do that, but for developers this either causes us to have to update the setting manually or it hand cuffs us into writing alert statements in our client side code. I updated it manually when I needed it, but then when I was off browsing Google/Bing/MSDN for how to do something I got annoyed to death by the warnings of their bad javaScript. I needed a quick way to toggle this setting that didn’t require me to have to go through the menu system on IE all the time. The setting for this value happens to be in the registry at:
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]:: DisableScriptDebuggerIE
Valid values are “yes” or “no”. Note that this is inverse from what you would expect since the name is “Disable”ScriptDebuggerIE. If you want to debug in VS 2008 then this value should be set to “no”. By default the value is set to “yes”.
I found that I needed to change this setting in my development work, so in order to be able to quickly turn this off and on I created a PowerShell Script to take care of this. The script toggles the value so you can switch it back and forth with the same script. Here is the code I used:
$currentValue = (Get-ItemProperty -path 'hkcu:\Software\Microsoft\Internet Explorer\main' -name DisableScriptDebuggerIE).DisableScriptDebuggerIE
if ($currentValue -eq 'yes')
{
Write-Host "Toggle Script Debugging On."
set-itemproperty 'hkcu:\Software\Microsoft\Internet Explorer\main' -name DisableScriptDebuggerIE -value 'no'
}
else {
Write-Host "Toggle Script Debugging Off."
set-itemproperty 'hkcu:\Software\Microsoft\Internet Explorer\main' -name DisableScriptDebuggerIE -value 'yes'
}
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Note you have to have PowerShell installed for this to work. Also note that PowerShell is secure by default, meaning you can’t just double click this and see it work without jumping through some hoops.
-
Ensure that your PowerShell is set to allow execution of local scripts (“set-executionpolicy RemoteSigned”). For more about what this means type “help about_signing” at a PowerShell prompt. Make sure you’re happy with the setting you choose so that you are secure.
-
Save the script above into a to a known location and name is something like toggleIEDebugging.ps1.
-
Create a shortcut to the script.
-
Modify the properties of the shortcut to be the following:
C:\WINNT\system32\windowspowershell\v1.0\powershell.exe &‘C:*pathToSavedScript*\toggleIEDebugging.ps1’
Now you can double-click the shortcut (I have mine on my desktop) and turn on IE debugging. This only modifies the value for NEW instances of IE, so if once you run it, only new instances of IE will have the new setting.
Now to debug into your JavaScript you should just have to set a breakpoint, hit F5 or attach to an already running instance of IE where your app is running. It’s MUCH easier than using alert boxes.