Topic: Which Operating System

Hello,
is there a way we can have a script determine the operating system (eq XP, Windows 7, Windows 10, Windows Server etc) that the end user PC is running?
Thanks, David

2 (edited by derek 2019-01-02 03:04:19)

Re: Which Operating System

Hi David,
How's things?
I think there are other environment variables that might show more detailed information but perhaps ('OS') is enough for what you need?
Please have a look at the attached (XP probably shows up as _NT - but I guess if you wanted, you could just add another line of script to substitute _XP where it finds _NT).
Derek.

Post's attachments

Attachment icon winversion.zip 334.86 kb, 363 downloads since 2019-01-02 

Re: Which Operating System

Hey there, all good here thank you. I hope you are too. It's nearly 5pm here and 31 degrees. You're probably thinking about snow. Thanks for the demo, I'll give it a go later when I get home and report back to you. Best regards, David.

Re: Which Operating System

Hello Derek, thank you for the idea. I get _NT on my Windows 10 pc also. I want to know exactly what version of Windows is running and having that knowledge gives me control over whether my application will run or not. It is a networked environment and I am to use this to prevent some PCs from running the software, partly as a security measure and party because of other Windows 10 only software running. Ultimately, I would like to detect screen resolution too so this application won't run in an insufficient screen resolution with window sizes being too big.
Thanks and regards, David.

Re: Which Operating System

Hi David,
I'm guessing it shows that way because at the kernel level, it's still basically windows_nt.
I can't test it because I'm still on XP but you could try replacing 'OS' with 'OSTYPE' in the script (line4) and that might display the info' you need.
With regard to screen resolution, you could use screen.width and screen.height (see attachment).
Derek.

Post's attachments

Attachment icon winversion2.zip 336.45 kb, 344 downloads since 2019-01-03 

Re: Which Operating System

derek wrote:

Hi David,
I'm guessing it shows that way because at the kernel level, it's still basically windows_nt.
I can't test it because I'm still on XP but you could try replacing 'OS' with 'OSTYPE' in the script (line4) and that might display the info' you need.
With regard to screen resolution, you could use screen.width and screen.height (see attachment).
Derek.

Hello Derek, thanks for this example.  I tried it and changed to "ostype" but the Edit1 field came out empty.  I'm running Windows 8.1 - any ideas why?

Re: Which Operating System

Hi David, Gonpublc2k,
I thought I'd read somewhere that 'ostype' might work with later versions of Windows;  sorry about that.
However, there's nothing to stop you creating a new system environment variable ('ostype' or whatever you want to call it) and give it the OS Version description.  Then give the script the name of your new environment variable and it's value pulls through to the program like any other environment variable.  But obviously, you'd need to do that for each PC that's running your program (which may be impractical).
Another way might be to write a batch file that runs the DOS command that shows the Operating System details (in XP, the command is 'ver', but I'm not sure about later versions) and then write the output to a file.  Then, in the script, read the contents of that file into your edit field.
I've attached an example (but obviously you'll need to edit the included batch file and replace 'ver' with whatever DOS command works with your version of Windows);  the screenshot shows how it looks on my machine but yours will obviously be different.
At least this might give you a couple of options.
Derek.

Post's attachments

Attachment icon winversion3.zip 395.87 kb, 377 downloads since 2019-01-04 

Re: Which Operating System

Hi Derek, Gonpublc2k,
thank you both for the help from both of you. In my current situation, I will not have access to the PCs running the software and I will not be able to rely on anyone else at the site to do any sort of setup for me with variables and batch files. The SQLite file in my application has a table called Configuration which only ever has one record in it and it contains various bits of information specific to the customer such as address and all that information that it will print to the reports it will generate.. I have been experimenting with writing a small program in a different language that will read the OS version and then write that into the appropriate field in the Configuration table. So, when the main form of my MVD application opens, a script runs my other little program which will write the OS version into the Configuration table. Then MVD will read the Configuration table and it will determined in code whether the application can run or not. At this stage, I think that will be my best way forward as it gives certainty of differentiating between all operating systems either installed locally or thin clients. Thanks again for the help you have given.
Regards, David.

Re: Which Operating System

Hello.


Please download latest beta version, I have added variables to determine the operating system
https://www.dropbox.com/s/anufoqnsh809x … a.zip?dl=0


Example:

procedure Form1_Button3_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Form1.Edit1.Value := Win32MajorVersion; // Specifies which major Windows Operating System version is operating.
    Form1.Edit2.Value := Win32MinorVersion; // Specifies which minor Windows Operating System version is operating.
    Form1.Edit3.Value := Win32BuildNumber;   // Specifies the build level of the Windows Operating System operating.
    Form1.Edit4.Text  := Win32CSDVersion; // Specifies the Win32 latest installed service pack.

{
Major Version = 6
 - Windows 8 (version 6.2)
 - Windows 7 (version 6.1)
 - Windows Vista (version 6.0)

Major Version = 6
 - Windows XP (version 5.1)
 - Windows 2000 (version 5.0)
}

end;

For resolution:

    Form1.Edit5.Value := Screen.Width;
    Form1.Edit6.Value := Screen.Height;
Dmitry.

Re: Which Operating System

Hello Dmitry,
thank you for the update. I am running Windows 10 Home 64bit on the machine I am using right now and the major and minor OS version shows as 6.2 which is the same as you say for Windows 8. Tomorrow I'll run it on Windows 10 Pro 64bit and Windows 7 and see what they report.
The screen resolution functions are great, thank you,
David

Re: Which Operating System

Hello Dmitry,
I run a test program on a Windows 10 Professional 64bit PC and it shows as version 6.2 also, the same as Windows 10 Home 64bit. The Win32BuildNumber shows 9200 for both OS's above and no text is returned for the Win32CSDVersion parameter on either of these operating systems.
I thought I was still running Windows 7 around here somewhere to test it on but it looks like I've upgraded everything to Windows 10.
I hope that helps,
David

Re: Which Operating System

Hi Dmitry, David,
Thanks for the latest update.
Just for information, it works correctly with XP (I've added a look-up table to convert the numbers to something more meaningful).
Derek.

Post's attachments

Attachment icon osversion.zip 337.56 kb, 342 downloads since 2019-01-13 

Re: Which Operating System

radsoft wrote:

Hello Dmitry,
thank you for the update. I am running Windows 10 Home 64bit on the machine I am using right now and the major and minor OS version shows as 6.2 which is the same as you say for Windows 8. Tomorrow I'll run it on Windows 10 Pro 64bit and Windows 7 and see what they report.
The screen resolution functions are great, thank you,
David

Unfortunately I can't solve this problem, there is some problem with Windows API.
But you can detect version using system registry, example:


function OSVersion: string;
var
   reg: TRegistry;
begin
     reg := TRegistry.Create;
     reg.Access := KEY_READ;  // KEY_ALL_ACCESS    req. administrator's rights
     reg.RootKey := HKEY_LOCAL_MACHINE;

     if reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion', false) then
     begin
         if reg.ValueExists('ProductName') then Result := reg.ReadString('ProductName');
     end
         else ShowMessage('Can''t open the key.');

     reg.CloseKey;
     reg.Free;
end;
Dmitry.

Re: Which Operating System

Unfortunately I can't solve this problem, there is some problem with Windows API.

Microsoft has changed the API.

Example:

With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases. To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

In other words:
Depending on your application target (Compiled part inside the software header), Windows 10 tells what is required for the software to work. Without access to the registry, you can not get the versioninformation for sure.
Dmitry can not compile as Windows 10 Target because it could loose backward compatibility with previous Windows Version.

Re: Which Operating System

Thanks Dmitry, the registry reports this Windows 10 Pro 64bit as version 6.3. Thanks for the effort you put in and maybe it is something that could be resolved at a later stage but I could use the registry method you describe. The screen resolution functions are excellent, thank you.
David