Sign in to follow this  
Followers 0
Anteaus

Detect 'Home' OS

16 posts in this topic

Writing a script that modifies user permissions, and want to ensure that it isn't run on a Home release of XP or Vista, as that might result in damage to an OS which is not designed to run with limited users.

Any suggestions? This is actually much harder to do than it might seem!

Share this post


Link to post
Share on other sites



Writing a script that modifies user permissions, and want to ensure that it isn't run on a Home release of XP or Vista, as that might result in damage to an OS which is not designed to run with limited users.

Any suggestions? This is actually much harder to do than it might seem!

Does this help?

MsgBox(0,0, _getOSVersion())

Func _getOSVersion()
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Local $colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For $objOperatingSystem In $colSettings
        Return StringMid($objOperatingSystem.Caption, 19)
    Next
EndFunc   ;==>_getOSVersion

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Does this help?

Quite possibly, will give it a try.

Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well... what about these macros?

@OSBuild Returns the OS build number. For example, Windows 2003 Server returns 3790

@OSLang Returns code denoting OS Language. See Appendix for possible values.

@OSServicePack Service pack info in the form of "Service Pack 3" or, for Windows 95, it may return "B"

@OSTYPE Returns "WIN32_NT" for NT/2000/XP/2003/Vista and returns "WIN32_WINDOWS" for 95/98/Me

@OSVersion Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"

Edited by Nahuel

Share this post


Link to post
Share on other sites

Well... what about these macros?

Let me know if it works for other OS than XP to. Thanks!

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

If @OSVersion = "Win_XP" Then $1 = "Windows XP"
If @OSVersion = "Win_VISTA" Then $1 = "Windows Vista"
If @OSVersion = "Win_2003" Then $1 = "Windows 2003"
If @OSVersion = "Win_2000" Then $1 = "Windows 2000"
If @OSVersion = "Win_98" Then $1 = "Windows 98"
If @OSVersion = "Win_95" Then $1 = "Windows 95"
MsgBox(0, "", $1)

Share this post


Link to post
Share on other sites

If @OSVersion = "Win_XP" Then $1 = "Windows XP"
 If @OSVersion = "Win_VISTA" Then $1 = "Windows Vista"
 If @OSVersion = "Win_2003" Then $1 = "Windows 2003"
 If @OSVersion = "Win_2000" Then $1 = "Windows 2000"
 If @OSVersion = "Win_98" Then $1 = "Windows 98"
 If @OSVersion = "Win_95" Then $1 = "Windows 95"
 MsgBox(0, "", $1)
@Swift : There is a difference to know what version of windows your system and is and to know whether is it XP HOME or PRO or WIN 98 SE or VISTA ....

Understand? :)

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Does this help?

MsgBox(0,0, _getOSVersion())

Func _getOSVersion()
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Local $colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For $objOperatingSystem In $colSettings
        Return StringMid($objOperatingSystem.Caption, 19)
    Next
EndFunc   ;==>_getOSVersion

Mega

It helped me with my project, until someone with a non-English OS tried to run my script. Then it refused to ID the French XP Home Edition as Home Edition by simple comparsion of output (ie: if _GetOSVersion = "XP Home Edition" then)

So what I did was this:

func _GetOSVersion()
  local $Type = ""
  If @OSVersion = "Win_VISTA" Then $Type = "Windows Vista"
  If @OSVersion = "Win_2003" Then $Type = "Windows 2003"
  If @OSVersion = "Win_2000" Then $Type = "Windows 2000"
  If @OSVersion = "Win_98" Then $Type = "Windows 98"
  If @OSVersion = "Win_95" Then $Type = "Windows 95"
  If @OSVersion = "Win_XP" Then
    $Type = "Windows XP Professional"
    If FileExists(@SystemDir & "\SECEDIT.EXE") = 0 Then $Type = "Windows XP Home Edition"
    local $T = RegRead("HKLM\SYSTEM\WPA\MediaCenter", "Installed")
    If @error = 0 And $T = 1 Then $Type = "Windows XP MCE 2005"
  endif
  return $Type
endfunc
There are a few small problems with this code. First, should a user decide to put a SECEDIT.EXE file in the %WinDir%\system32 folder on a XP Home system, this code will ID the OS as Pro, not Home. Fortunately, it is much harder to fake out the code to ID a system as MCE, as a reboot into safe mode is required. I have verification from the guy with the French XP Home that this works on his system, so this will work for non-English OS's.

NOTE: I selected SECEDIT.EXE as the file to check for because I nLite'd a Home and Pro OS down to as close to nothing as I could get. SECEDIT.EXE was one of the files that remained in Pro that didn't exist in Home.

Edited by Dougiefresh

Share this post


Link to post
Share on other sites

Something wrong with GetVersionEx() API?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

If you detect Win_VISTA, you might want to look in the registry, as it's there spelled out in plain (whatever the default installed language is). The location of the key in question is:

32bit: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName

64bit: HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\ProductName

These keys work for XP too, but XP doesn't list the version in that key. You might want to look at the differences between a copy of Home and a copy of Pro here in this specific section of the registry, it might get you further.


Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Cynagen, are you sure that the key that your referring to will be in English on, let's say, a French XP install? And besides, that information can be gotten with @OSVersion....

I didn't say there was anything wrong with the API that was being used. However, if the script that you are writing is for English and someone non-English runs it, the script won't be able to ID the OS properly using this code. I found that out when a person with a non-English OS tried to run my English-only script. It failed because the function's output wasn't in English, which the script was testing for. So I thought others might be interested in my solution.... that's all.

Edited by Dougiefresh

Share this post


Link to post
Share on other sites

Cynagen, are you sure that the key that your referring to will be in English on, let's say, a French XP install? And besides, that information can be gotten with @OSVersion....

I didn't say there was anything wrong with the API that was being used. However, if the script that you are writing is for English and someone non-English runs it, the script won't be able to ID the OS properly using this code. I found that out when a person with a non-English OS tried to run my English-only script. It failed because the function's output wasn't in English, which the script was testing for. So I thought others might be interested in my solution.... that's all.

GetVersionEx() isn't dependent on the language of the OS.

Here's an example that could work:

http://www.autoitscript.com/forum/index.ph...st&p=665576


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Awesome! That's for the info!

Share this post


Link to post
Share on other sites

If @OSVersion = "Win_XP" Then $1 = "Windows XP"
If @OSVersion = "Win_VISTA" Then $1 = "Windows Vista"
If @OSVersion = "Win_2003" Then $1 = "Windows 2003"
If @OSVersion = "Win_2000" Then $1 = "Windows 2000"
If @OSVersion = "Win_98" Then $1 = "Windows 98"
If @OSVersion = "Win_95" Then $1 = "Windows 95"
MsgBox(0, "", $1)
When I test this from the SciTE I get with my Vista the message that I have XP :D When I use it with "#RequireAdmin" I get the message that I have Vista :o

Is that a correct behaviour ?

Cheers Wolle


Cheers Wolle

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

;) LOL! ^_^ No, it shouldn't report that. Wow.... that's interesting because I hadn't tested it on Vista. I've just tested it on XP. The AutoIT documentation says it should work.... obviously it doesn't work as intended!

Thanks for killing the code! LOL!

Edited by Dougiefresh

Share this post


Link to post
Share on other sites

All,

The script correctly determines Vista for me (x32 HP SP1).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0