Jump to content

Detect 'Home' OS


Anteaus
 Share

Recommended Posts

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!

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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)

Link to comment
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

Link to comment
Share on other sites

  • 1 year later...

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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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.

Link to comment
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.

Edited by Dougiefresh
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...

;) 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
Link to comment
Share on other sites

  • Moderators

All,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...