Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Created November 12, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjyoung1974/d3c5c20030368ebc89412654432dab36 to your computer and use it in GitHub Desktop.
Save gjyoung1974/d3c5c20030368ebc89412654432dab36 to your computer and use it in GitHub Desktop.
// Gordon Young 2016 gyoung@svb.com
// This script :
// 1. Reads the given Windows registry subkey value reg_multi_sz data type
// 2. Compares it to the provided expected setting
// if the configured setting is compliant the script returns 'pass',
// if the setting is non-compliant the script returns 'fail'
//The registry path we want to test
var hklm = 0x80000002, KeyName = "SYSTEM\\CurrentControlSet\\services\\Netlogon\\Parameters", ValueName = "RequireStrongKey";
//set our Array of expected CI Settings values:
var sExpectedValue = 1;
// The following function wmiExec() is is just a generic way to call "C Style" provider methods that require output parameters. This helps to return output from the GetMultiStringValue
// For example the windows regisry method we are calling look like: https://msdn.microsoft.com/en-us/library/aa390445(v=vs.85).aspx
//uint32 GetDWORDValue(
// [in] uint32 hDefKey = HKEY_LOCAL_MACHINE,
// [in] string sSubKeyName,
// [in] string sValueName,
// [out] uint32 uValue
//);
try {
function wmiExec(wmiService, providerName, methodName, methodParameters) {
var wmiProviderObject = wmiService.Get(providerName);
var wmiProviderMethod = wmiProviderObject.Methods_.Item(methodName);
var wmiInputParameterObject = wmiProviderMethod.Inparameters.SpawnInstance_();
for (var parameter in methodParameters) {
wmiInputParameterObject.Properties_.item(parameter) = methodParameters[parameter];
}
wmiOutParameterObject = wmiProviderObject.ExecMethod_(wmiProviderMethod.Name, wmiInputParameterObject);
return wmiOutParameterObject;
}
var wmiLocatorObj = WScript.CreateObject("WbemScripting.SWbemLocator"); //instanciate WMI provider
var wmiServiceDefault = wmiLocatorObj.ConnectServer(".", "root\\default");
// Executing the GetMultiStringValue method and creating an array of the resulting values.
var methodParameters = new Object();
methodParameters["hDefKey"] = hklm;
methodParameters["sSubKeyName"] = KeyName;
methodParameters["sValueName"] = ValueName;
var result = wmiExec(wmiServiceDefault, "StdRegProv", "GetDWORDValue", methodParameters);
var iResult = result.uValue;
if (sExpectedValue == iResult) {
WScript.Echo('pass')
}
else {
WScript.Echo('fail')
}
}
catch (e) {
WScript.Echo('fail');
//WScript.echo((e.number>>16 & 0x1FFF)); // Prints Facility Code
//WScript.echo((e.number & 0xFFFF)); // Prints Error Code
//WScript.echo(e.description); // Prints Description
//throw e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment