Windows Version Detection

Triggering the calculator from a button in Windows 10 is not the same as in previous versions of Windows. For whatever reason, MS have switched to a windowed metro app. I managed to establish that the following command does the necessary in Windows 10:

calculator://

I could probably find a system folder or file that is not present in earlier Windows versions and use @ifexists to construct a button to execute calc.exe or calculator:// depending on the Windows version. However, it would be much neater (and safer) to have a reliable way of establishing the Windows version using Opus. I note that it is possible to do this using navigator.userAgent (See http://stackoverflow.com/questions/15710646/detecting-os-xp-vs-7) but the navigator object is not available under Opus. Maybe there is another way?

Regards, AB

The object/property navigator.userAgent ist javascript/browser specific and won't work in DO or a script running in WSH.

But you can use WMI to query windows information:

var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2"); var enumItems = new Enumerator(objWMIService.ExecQuery("Select * from Win32_OperatingSystem",null,48)); for(;!enumItems.atEnd();enumItems.moveNext()) { var item = enumItems.item(); var strMsg = ""+ "Computer Name : " + item.CSName + "\n"+ "Windows Version : " + item.Caption + "\n"+ "ServicePack : " + item.CSDVersion + "\n"+ "Build Number : " + item.BuildNumber + "\n"+ "Serial Number : " + item.SerialNumber + "\n"; WSH.Echo(strMsg); }
Testdrive the snippet by saving it into a *.js file and run "cscript.exe " in a DOS prompt or replace WSH.Echo() with DOpus.Output() to make it run in DO. The output should look similar to this, I hope that still works on windows 10.

---------- cscript.exe ----------
Computer Name : DSTEAK
Windows Version : Microsoft Windows 7 Professional
ServicePack : Service Pack 1
Build Number : 7601
Serial Number : XXXX-OEM-8992671-XXXXX

Thanks @tbone. That will do the trick nicely. It's a reasonable bet that the RTM version will still start with Microsoft Windows 10 which is all I need to know.

Windows Version : Microsoft Windows 10 Pro Insider Preview

Regards, AB

For anyone else who is testing Opus under Windows 10 Preview, the following button code will run the Windows calculator application correctly according to Windows version. The button must be saved as a Script Function. Thanks to @tbone for pointing me to the relevant objWMIService code.

[code]@script jscript

var cmd = DOpus.create.Command;
// If Windows version is less than 10 run calc.exe, otherwise run calculator://
cmd.runcommand((WindowsVersion()<10)?"/system\calc.exe":"calculator://");

function WindowsVersion(){ // Return Windows version e.g. 7, 8.1, 10
var objWMIService = GetObject("winmgmts:\\.\root\cimv2");
var enumItems = new Enumerator(objWMIService.ExecQuery("Select * from Win32_OperatingSystem",null,48));
var item, p, s;
for(;!enumItems.atEnd();enumItems.moveNext()) {
item = enumItems.item();
s = item.Caption.toLowerCase(); // Caption Is (e.g.) Microsoft Windows 10 Pro
p = s.indexOf("windows ");
if (!(p<0)){
s = s.substr(p + 8);
p = s.indexOf(" ");
s = (p<0)?s:s.substr(0,p);
}
}
return s;
}[/code]
Regards, AB

Can't you still run calc.exe to launch the new calculator? I read that there is still a wrapper calc.exe for compatibility with things that launch it.

The first time I attempted to run Calc in W10 Preview 10130 a couple of days ago it didn't work, which is what got me searching for a reason and the discovery that there had been a change to the new metro app. After reading your comment and trying again, it now works from a command line. Maybe I stuffed up? Always a possibility. Anyway, at least I now know how to establish the Windows version.

Regards, AB

We'll extend the DOpus.version object to provide an easy way to detect Windows versions in case it's needed, too.