function echo(a){return WScript.Echo(a);}
function exit(a){return WScript.Quit(a);}
var Registry=(function(){
// this.HKEY_CLASSES_ROOT = 0x80000000;
// this.HKEY_CURRENT_USER = 0x80000001;
this.HKEY_LOCAL_MACHINE = 0x80000002;
// this.HKEY_USERS = 0x80000003;
// this.HKEY_CURRENT_CONFIG = 0x80000005;
// this.Types = new Array(
// ' ', // 0
// 'REG_SZ ', // 1
// 'REG_EXPAND_SZ ', // 2
// 'REG_BINARY ', // 3
// 'REG_DWORD ', // 4
// 'REG_DWORD_BIG_ENDIAN ', // 5
// 'REG_LINK ', // 6
// 'REG_MULTI_SZ ', // 7
// 'REG_RESOURCE_LIST ', // 8
// 'REG_FULL_RESOURCE_DESCRIPTOR ', // 9
// 'REG_RESOURCE_REQUIREMENTS_LIST', // 10
// 'REG_QWORD '); // 11
this.oRegistry=GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv');
this.Exec=function(method,hkey,sRegPath,sValueName){
var oMethod = this.oRegistry.Methods_(method);
var oInParam = oMethod.InParameters.SpawnInstance_();
oInParam.hDefKey = hkey;
oInParam.sSubKeyName = sRegPath;
if(sValueName != null)oInParam.sValueName = sValueName;
return this.oRegistry.ExecMethod_(oMethod.Name, oInParam);
};
this.EnumKey=function(sRegPath){
var oOutParam = this.Exec('EnumKey', this.HKEY_LOCAL_MACHINE, sRegPath);
return oOutParam.sNames.toArray();
};
this.EnumValues=function(sRegPath){
var oOutParam = this.Exec('EnumValues', this.HKEY_LOCAL_MACHINE, sRegPath);
var aNames = oOutParam.sNames.toArray();
var aTypes = oOutParam.Types.toArray();
var ret=[];
for(var i=0;i<aNames.length;i++){
ret.push({'Name': aNames[i], 'Type': aTypes[i]});
}
return ret;
};
// this.GetDWORDValue=function(sRegPath,sValueName){
// var oOutParam = this.Exec('GetDWORDValue', this.HKEY_LOCAL_MACHINE, sRegPath, sValueName);
// return oOutParam.uValue;
// };
// this.GetExpandedStringValue=function(sRegPath,sValueName){
// var oOutParam = this.Exec('GetExpandedStringValue', this.HKEY_LOCAL_MACHINE, sRegPath, sValueName);
// return oOutParam.sValue;
// };
this.GetStringValue=function(sRegPath,sValueName){
var oOutParam = this.Exec('GetStringValue', this.HKEY_LOCAL_MACHINE, sRegPath, sValueName);
return oOutParam.sValue;
};
return this;
})();
exit(main());
function main(){
var wshell=WScript.CreateObject('WScript.Shell');
//echo(Registry.EnumKey(sRegPath).join('\n'));
var sRegPath = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall';
try{
var items = Registry.EnumKey(sRegPath);
}catch(err){
var items = [];
}
for(var i=0;i<items.length;i++){
//echo(items[i]);
try{
var props = Registry.EnumValues(sRegPath+'\\'+items[i]);
}catch(err){
var props = [];
}
for(var j=0;j<props.length;j++){
if(props[j].Name == 'DisplayName'){
var value = Registry.GetStringValue(sRegPath+'\\'+items[i], props[j].Name);
// jre6 and jre7, older versions have to be manually dealt with
if((/^Java(\(TM\))? \d( Update \d+)?$/).test(value)){
wshell.Run('msiexec /qn /norestart /x '+items[i],0,true);
}
}
/*var v=props[j].Type;
switch(props[j].Type){
case 1:
v=Registry.GetStringValue(sRegPath+'\\'+items[i],props[j].Name);
break;
case 2:
v=Registry.GetExpandedStringValue(sRegPath+'\\'+items[i],props[j].Name);
break;
case 4:
v=Registry.GetDWORDValue(sRegPath+'\\'+items[i],props[j].Name);
break;
default:break;
}
//echo('\t'+props[j].Name + ': ' + v);
if(props[j].Name == 'DisplayName' && typeof(v)=='string' &&
// jre6 and jre7, older versions have to be manually dealt with
(/^Java\(TM\) \d( Update \d+)?$/).test(v)){
echo('msiexec /qn /norestart /x '+items[i]);
}*/
}
}
// handle 32-bit software installed on a 64-bit system
var sRegPath = 'SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall';
try{
var items = Registry.EnumKey(sRegPath);
}catch(err){
var items = [];
}
for(var i=0;i<items.length;i++){
try{
var props = Registry.EnumValues(sRegPath+'\\'+items[i]);
}catch(err){
var props = [];
}
for(var j=0;j<props.length;j++){
if(props[j].Name == 'DisplayName'){
var value = Registry.GetStringValue(sRegPath+'\\'+items[i], props[j].Name);
// jre6 and jre7, older versions have to be manually dealt with
if((/^Java\(TM\) \d( Update \d+)?$/).test(value)){
wshell.Run('msiexec /qn /norestart /x '+items[i],0,true);
}
}
}
}
return 0;
// var wmi=GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2');
// var query='SELECT * FROM Win32_Product';
// //var query='SELECT * FROM Win32_PhysicalMemory';
// var en=new Enumerator(wmi.ExecQuery(query));
// for(en.moveFirst();!en.atEnd();en.moveNext()){
// var itm = en.item();
// echo('Name: '+itm.Name);
// /*var props = new Enumerator(itm.Properties_);
// for(props.moveFirst();!props.atEnd();props.moveNext()){
// var p = props.item();
// echo(p.Name + ': ' + p.Value);
// }*/
// }
// return 0;
}