Jump to content

@OSVersion Demistified


Recommended Posts

The end result of this script returns the correct results but I don't understand why each line isn't returning something to do with win10.

This is running in Windows 10:

AutoIt ver. 3.3.14.5

;;AutoIt_Debugger_Command:Disable_Debug
Global $OSVersion, $OS_Version, $servicepack_version

If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
    $ProgramFiles = "C:\Programs\"
Else
    $ProgramFiles = "C:\Program Files\"
EndIf
;MsgBox("", "Test", "_OSVersion = " & _OSVersion())

Func _OSVersion()
    ;MsgBox("", "Test", "@OSVersion = " & @OSVersion)
        Local $OSVersion = @OSVersion
;       Now     $OSVersion = Win_7
    $OSVersion = StringStripWS(StringRegExpReplace(@OSVersion, "(WIN_)|(Microsoft )|(Windows )|(\(TM\))|( Ultimate)", ""), 8)
;       Now     $OSVersion = 7
    ;MsgBox("", "Test", "$OS_Version = " & $OS_Version)
    $OSVersion = StringRegExpReplace(StringRegExpReplace($OS_Version, '2008', 'Win7'), 'VISTA', 'Vista')
;       Now     $OSVersion is blank
    If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", 'CurrentBuildNumber') > 7000 Then $OS_Version = 'Win7'
;       Now     $OS_Version = Win7 (which is correct)
    If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", 'CurrentBuildNumber') > 10240 Then $OS_Version = 'Win10'
;       Now     $OS_Version = Win7 (which is Not correct) CurrentBuildNumber = 17763
    If StringRegExp(FileGetVersion('winver.exe'), "^10\.\d") Then $OSVersion = "WIN_10"
;       Now     $OSVersion = Win_10  (which is correct)
    If StringRegExp(FileGetVersion('winver.exe'), "^7\.\d") Then $OSVersion = "WIN_7"
;       Now     $OSVersion = Win_10  (which is correct)

    $servicepack_version = StringReplace(@OSServicePack, "Service Pack ", "SP")
    If @error = -1 Then $servicepack_version = ""
    ;MsgBox("", "Test", "$OSVersion = " & $OSVersion & @CRLF & "$OS_Version = " & $OS_Version & @CRLF & "winver.exe = " & (FileGetVersion('winver.exe')) & @CRLF & "$servicepack_version = " & $servicepack_version & @CRLF & "@OSArch = " & @OSArch)

    ConsoleWrite($OSVersion & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') & @CRLF)
    Return $OSVersion & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '')
    ;AutoIt_Debugger_Command:Enable_Debug
EndFunc   ;==>_OSVersion

Thanks,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

What version of Autoit are you using?  Mine returns Win_10X64 although I could gather the same information using:

MsgBox(4096, "OS Version", @OSVersion & @OSServicePack & @OSArch)

Couple of other things I don't understand:
1. A number of your statements have string replacement, however many of the words you're searching would never be found, for example @OSVersion only returns Win_x, see help file, so why use string replace on words like Microsoft, Windows, Ultimate when they would never exist?

2. Also don't understand the first statement why would $ProgramFiles be "C:\Programs\" (%AllUsersProfile% for Win 7 and 10), the only difference for "Program Files" would be @OSArch version, example:

Windows 64 bit
64-bit folder = "C:\Program Files"
32-bit folder = "C:\Program Files (x86)"

Windows 32 bit
64-bit folder = ""
32-bit folder = "C:\Program Files"

Edited by Subz
Link to comment
Share on other sites

Are you running the script compiled or uncompiled?  If it is compiled, it could be how the manifest compatibility is set.  Are you using the full version of SciTE4AutoIt3?  Do you have any compiler directives that you are not showing?  

Link to comment
Share on other sites

Assume this is an upgrade from Windows 7?  What does _WinAPI_GetVersion function return?  If you do a search for "Autoit @OSVersion wrong", there are a number of posts with regards to the issue, mostly on systems that have upgraded.

Link to comment
Share on other sites

On 4/27/2019 at 11:27 PM, AdamUL said:

Are you running the script compiled or uncompiled?  If it is compiled, it could be how the manifest compatibility is set.  Are you using the full version of SciTE4AutoIt3?  Do you have any compiler directives that you are not showing?  

Thanks for the reply...

I'm running the script uncompiled.

SciTE4AutoIt3 ver. 4.1.2

I think this is the latest version.

Thanks,

Docfxit

Link to comment
Share on other sites

On 4/28/2019 at 8:07 AM, Subz said:

Assume this is an upgrade from Windows 7?  What does _WinAPI_GetVersion function return?  If you do a search for "Autoit @OSVersion wrong", there are a number of posts with regards to the issue, mostly on systems that have upgraded.

Thanks for the reply...

This is running on Win 10 that was not upgraded.  It's brand new OEM Lenovo.  I have not re-installed the OS.  The only change I made to the OS is to apply the updates from MS.

When I run the script the output shows:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Dnload\9xAddons\OSVersion.au3" /UserParams    
+>08:44:31 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\JohnD\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\JohnD\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Dnload\9xAddons\OSVersion.au3
+>08:44:31 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Dnload\9xAddons\OSVersion.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
WIN_10X64
WIN_10X64
WIN_10X64
WIN_10X64
+>08:44:31 AutoIt3.exe ended.rc:0
+>08:44:31 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.8922

According to @Jos When it says OS:Win_10 it means it's running in Windows 10.

After searching for Autoit @OSVersion wrong without the quotes, I found @QSVersion doesn't return the version of the OS that is running on the machine.  The Macro documentation says "Returns one of the following: "WIN_10", "WIN_81", "WIN_8", "WIN_7", "WIN_VISTA", "WIN_XP", "WIN_XPe","

It implies it's the OS running on the machine.  In fact it returns the compatibility the program is running in, Not the OS it's running in.

Very deceptive.  The Macro name is very misleading.

In my case through my testing @OSVersion reported Win_7 because I was running it the AutoIt Graphical Debugger.

I found The AutoIt Graphical Debugger wouldn't run in Windows 10 unless I run it in Windows 7 compatibility.

I have sent an email to the author of the AutoIt Graphical Debugger but I have not received a reply. (No big surprise since he doesn't seem to respond to anything relating to the AutoIt Graphical Debugger) 

It would be nice if:

1. The developers of AutoIt would create a new macro and call it something to reflect what compatibility mode the program is running in and use the code for @OSVersion.  Another words rename @OSVersion to what it really does.  And then rewrite @OSVersion to return the value of the actual OS that is running.  Like it implies.

2. Maybe if the developers of AutoIt would ask (Steve) the developer of the AutoIt Graphical Debugger to recompile it in Windows 10,  maybe  Steve would be willing to do it, so it doesn't have to be run in Windows 7 compatibility mode.

Docfxit

Edited by Docfxit
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...