-2

I need to execute some cmd command which will require Windows Script Host to be enabled. By default, Windows Script Host is enabled. But the problem is some of my clients, Windows Script Host is disabled. One of the reasons behind it is by using the software called Smadav. It altered the system configuration of the Operating system and somewhat disabling and preventing it from using the Windows Script Host.

I tried to re-enabled Windows Script Host manually while Smadav is installed and running by re-configuring Registry, the location is in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Script Host\Settings then I added an entry Enabled with a value of 1, but still, Windows Script Host is prevented by Smadav and won't execute.

The solution is to uninstall the Smadav, but I still need to re-enable the Windows Script Host. I want to do it programmatically, anybody can help me out? Below is my current code, but it doesn't work. Not changing the value of key nor creating the key if it doesn't exist.

            string location = @"SOFTWARE\Microsoft\Windows Script Host\Settings";
            RegistryKey enabled = Registry.LocalMachine.OpenSubKey(location, true);
            if (enabled != null) //key exist, just enable it by setting value to 1
            {
                enabled.SetValue("Enabled", 1, RegistryValueKind.DWord);
                enabled.Close();
            }
            else { //key doesn't exist, create a key and set the value to 1
                enabled.CreateSubKey("Enabled");
                enabled.SetValue("Enabled", 1, RegistryValueKind.DWord);
                enabled.Close();
            }
Polar
  • 3,327
  • 4
  • 42
  • 77

1 Answers1

-4

To enable or disable Windows Script Host, type regedit.exe in Run box and hit Enter to open the Registry Editor.

Navigate to the following key:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Script Host\Settings

In the right panel, you will see Enabled. If you see the entry 0, it means that the Windows Script Host access is disabled on your Windows machine.

Double Click on it and give it Value Data 1 to enable it.

A value of 1 will enable Windows Script Host
A value of 0 will disable Windows Script Host.

Click on OK and exit the Registry. If you don’t see this entry, then you may need to create it, as it does not exist by default in Windows.

You will now, no longer receive the Windows Script Host access is disabled on this machine. In this way you can enable or disable Windows Script Host.

Source: https://www.thewindowsclub.com/windows-script-host-access-is-disabled-on-this-machine

Mr Hery
  • 829
  • 1
  • 7
  • 25
  • 1
    Which part of the middle paragraph of the question do you think is not covering everything in this answer already? – Damien_The_Unbeliever Nov 07 '19 at 10:56
  • 1
    I actually mention that I did make a changes manually, exactly as what you answered but I want it to enabled programmatically. – Polar Nov 07 '19 at 11:03