PDA

View Full Version : OS Name


limboo
08-23-2008, 08:45 AM
Well the problem is that i've got this code


OSName = System.GetOSName();

if OSName ~= "Windows XP" or OSName ~= "Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
else
end


but it gives this result (see the picture)
i don't think thats what it has to do
can you help me with that?

bule
08-23-2008, 09:00 AM
Try checking for the OS version.

Windows 2000 is 5.0, XP is 5.1, Windows 2003 Server is 5.2.
Vista is 6.0.

limboo
08-23-2008, 09:08 AM
that worked bule, thanks.:)

and how do i check if its home or pro
same question for vista

thanks

Ulrich
08-23-2008, 10:05 AM
There is an error in your boolean logic in the first post. The condition will always return true.

No text can be simultaneously equal to both strings "Windows XP" and "Windows Server 2003".

Ulrich

limboo
08-23-2008, 10:16 AM
So i need to use and?

limboo
08-23-2008, 10:53 AM
but does someone know how to find out if it's XP Pro, Home, XP64bit and for vista the same thing

Ulrich
08-23-2008, 10:56 AM
So i need to use and?

Probably. There is a simple rule for boolean comparisons, which you can use if something doesn't work as expected. Often reading the same comparison in another way makes the error more obvious. All you have to do is invert everything.

In your case, you wrote:
if OSName ~= "Windows XP" or OSName ~= "Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
end


This is the same as:
if OSName == "Windows XP" and OSName == "Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
end


If after the inversion your boolean logic still makes sense to you, then it is probably right.

You haven't said what exactly do you want, so it is quite hard to help you.

Ulrich

limboo
08-23-2008, 11:01 AM
I've tried it with and and now it works fine at least i can access the application (haven't tried it with Windows Server 2003 yet but it will probably work)

and to upeters what i want is to let my app check if the client has the correct os

HMMurdock
08-23-2008, 01:53 PM
you currently have:

not(x) or not(y)

you need:

not(x or y)

limboo
08-23-2008, 03:58 PM
you mean


if OSName ~= "Windows XP" or"Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
end


nope ain't going to work
the only thing that works is

if OSName ~= "Windows XP" and "Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
end

but thats not my question anymore because i've solved it myself (with some help from upeters) my next question is how do i check if it's XP Pro, Home, 64bit, The same with Vista (Starter, Home Basic, Home Premium, Buisness, Enterprise, Ultimate, 32 bit, 64bit)

thanks

HMMurdock
08-23-2008, 07:55 PM
if OSName ~= "Windows XP" and "Windows Server 2003" then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
endThat will always evaluate to true. So while it will allow you to get past that point in the code, it isn't actually doing anything useful.

"Windows XP" and "Windows Server 2003" will always be false.
So if you evaluate the expression, ~= false it will always return true.

not(x or y) in your case would be

if not (OSName == "Windows XP" or OSName == "Windows Server 2003") then
Dialog.Message("OS", "You don't have the right os to run this program", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
Application.Exit()
end

limboo
08-24-2008, 02:24 AM
Thanks Murdock :D

couldn't have thought of that in a thousand years:o

HMMurdock
08-24-2008, 03:27 AM
my next question is how do i check if it's XP Pro, Home, 64bit, The same with Vista (Starter, Home Basic, Home Premium, Buisness, Enterprise, Ultimate, 32 bit, 64bit)

thanks

I would start with

result = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", true);

That won't work on any of the Win9x versions, but it should return the full OS Name on any of the latter versions. And you can use the System.Is64bitOS() to handle the 64bit question.

limboo
08-24-2008, 04:21 AM
nope, on my xp computer it only tells me Microsoft Windows XP