-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPath.js
89 lines (82 loc) · 2.41 KB
/
getPath.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var HKLM = 0x80000002;
var HKLM_text = "HKEY_LOCAL_MACHINE";
var Name = "\\DisplayName";
var Location = "\\InstallLocation";
var agentNames = new Array("xagt", "FireEye Endpoint Agent");
var regKeyPath = new Array(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
var ret = "";
if (WScript.Arguments.Length >= 1)
{
ret = WScript.Arguments(0);
}
for (var i = 0; i < regKeyPath.length; ++i)
{
if (isInstalled(regKeyPath[i]))
{
break;
}
}
if (ret.lastIndexOf("\\") != (ret.length - 1))
{
ret = ret.concat("\\");
}
WScript.Echo(ret);
//-----
function isInstalled(path)
{
var found = false;
var rtn = regGetSubKeys(".", path)
if ( rtn.Results == 0 )
{
var objShell = WScript.CreateObject("WScript.Shell");
var subKeyValue;
for (var idx=0;idx<rtn.SubKeys.length;idx++)
{
var exists = true;
var fullKeyName = HKLM_text + "\\" + path + "\\" + rtn.SubKeys[idx];
try
{
subKeyValue = objShell.RegRead(fullKeyName + Name);
for (var i = 0; i < agentNames.length; ++i)
{
if (subKeyValue == agentNames[i])
{
ret = objShell.RegRead(fullKeyName + Location);
found = true;
break;
}
}
}
catch (e) {
exists = false;
}
if (found)
break;
}
}
return found;
}
//-------------------------------------------------------------
// function : regGetSubKeyNames(strComputer, strRegPath)
// Based upon https://gallery.technet.microsoft.com/scriptcenter/Simple-JScriptJavascript-2a46ed8b#content
// purpose : return an array with names of any subKeys
//-------------------------------------------------------------
function regGetSubKeys(strComputer, strRegPath)
{
var aNames = null;
var objLocator = new ActiveXObject("WbemScripting.SWbemLocator");
var objService = objLocator.ConnectServer(strComputer, "root\\default");
var objReg = objService.Get("StdRegProv");
var objMethod = objReg.Methods_.Item("EnumKey");
var objInParam = objMethod.InParameters.SpawnInstance_();
objInParam.hDefKey = HKLM;
objInParam.sSubKeyName = strRegPath;
var objOutParam = objReg.ExecMethod_(objMethod.Name, objInParam);
if (objOutParam.ReturnValue == 0) // Success
{
aNames = (objOutParam.sNames != null) ? objOutParam.sNames.toArray(): null;
}
return { Results : objOutParam.ReturnValue, SubKeys : aNames };
}