Anteaus Posted February 20, 2008 Share Posted February 20, 2008 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 More sharing options...
Xenobiologist Posted February 20, 2008 Share Posted February 20, 2008 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 More sharing options...
Anteaus Posted February 20, 2008 Author Share Posted February 20, 2008 Does this help?Quite possibly, will give it a try.Thanks. Link to comment Share on other sites More sharing options...
Nahuel Posted February 20, 2008 Share Posted February 20, 2008 (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 February 20, 2008 by Nahuel Link to comment Share on other sites More sharing options...
Xenobiologist Posted February 21, 2008 Share Posted February 21, 2008 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 More sharing options...
Swift Posted February 21, 2008 Share Posted February 21, 2008 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 More sharing options...
Xenobiologist Posted February 22, 2008 Share Posted February 22, 2008 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 More sharing options...
Dougiefresh Posted April 6, 2009 Share Posted April 6, 2009 (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 MegaIt 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 endfuncThere 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 April 6, 2009 by Dougiefresh Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 6, 2009 Moderators Share Posted April 6, 2009 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 More sharing options...
Cynagen Posted April 6, 2009 Share Posted April 6, 2009 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 More sharing options...
Dougiefresh Posted April 6, 2009 Share Posted April 6, 2009 (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 April 6, 2009 by Dougiefresh Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 6, 2009 Moderators Share Posted April 6, 2009 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 More sharing options...
Dougiefresh Posted April 7, 2009 Share Posted April 7, 2009 Awesome! That's for the info! Link to comment Share on other sites More sharing options...
wolle7 Posted April 8, 2009 Share Posted April 8, 2009 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 When I use it with "#RequireAdmin" I get the message that I have Vista Is that a correct behaviour ? Cheers Wolle Cheers Wolle Link to comment Share on other sites More sharing options...
Dougiefresh Posted April 18, 2009 Share Posted April 18, 2009 (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 April 18, 2009 by Dougiefresh Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 18, 2009 Moderators Share Posted April 18, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now