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();
}