15 Replies Latest reply on May 17, 2017 2:39 AM by Marc Autret

    Incorrect value of $.os on Windows 10

    antosuv Level 1

      ExtendScript gives incorrect value of the operation system version:

       

      $.os // -> "Windows 7/64 6.2 (32-bit emulation)"
      

       

      Tested on Windows 10 64bit, ESTK and InDesign CS6 and CC2015.

        • 1. Re: Incorrect value of $.os on Windows 10
          Laubender Adobe Community Professional & MVP

          Hi,

          just seen this today written and posted by Werner Perplies, a German scripting colleague:

           

          Windows-Version ermitteln

          ( Get Windows version )

          May, 11, 2017

          Windows-Version ermitteln - Adobe® InDesign® Automatisierung

           

          Werner provides a free ExtendScript script for creating a batch routine reading out information directly from the Windows system. The function can be included into other ExtendScript scripts as well. Couldn't test it, because I'm on Mac OSX, but it is looking promissing.

           

          If you are facing issues, contact Werner or best leave a note at his forum where he posted the script.

          Werner is providing a downloadable zip with three jsx files. One main file with two files that run with an #include statement.

          To download the zip or to leave a message you have to log into Werner's website.

           

          Note: All explanations on the site are in German.

           

          Regards,
          Uwe

          1 person found this helpful
          • 2. Re: Incorrect value of $.os on Windows 10
            Laubender Adobe Community Professional & MVP

            FWIW: Werner is writing, that the problems of $.os with Windows alraedy started with Windows 8 and that he solved the problem to read out the exact version and even more.

             

            Regards,
            Uwe

            • 3. Re: Incorrect value of $.os on Windows 10
              Marc Autret Level 4

              Hi Uwe

               

              It seems that the problem also regards Windows 7 seen from CS4 (ExtendScript 3.92). In my example, $.os returned something like "Windows Vista/64 6.1 Service Pack 1 (32-bit emulation)", the actual OS signature being "Windows 7 etc".

               

              A fix is now featured in IdExtenso's Env module—see the onEngine() callback here:

              IdExtenso/$$.Env.jsxlib at master · indiscripts/IdExtenso · GitHub

               

              By contrast with Werner's solution—which is great, by the way—I use a temporary batch that simply parses the result of the VER command. It's a little less detailed than the WMIC instruction, but I think it should go faster while producing sufficient information for my goal.

               

              I hope some generous beta-testers will tell me whether the trick works on their platform.

              (Just load the framework in TRACE mode—i.e $$.load(-1)—and see if the log file shows a correct OS signature.)

               

              Best,

              Marc

              1 person found this helpful
              • 4. Re: Incorrect value of $.os on Windows 10
                Trevorׅ Adobe Community Professional

                Nice one Marc,

                 

                I must say I'm quite excited about your repository.

                Here's my pennies worth, it avoids making the temp .bat file.

                 

                function getWindowsData() {
                    // By Trevor http://creative-scripts.com
                    // Nicked the regestry key from https://forum.sysinternals.com/exact-windows-version-in-registry-key_topic1902.html
                    // The following value names are some of the more useful ones (At least for me)
                    // Use regedit or whatever to see other valid options
                    // Name ........................... Value on my System
                    // CompositionEditionID             Professional
                    // CurrentBuild                     14393
                    // CurrentBuildNumber               14393
                    // CurrentMajorVersionNumber        10
                    // CurrentMinorVersionNumber        0
                    // DigitalProductId                 None of your Business
                    // DigitalProductId4                None of your Business
                    // EditionID                        Professional
                    // InstallationType                 Client
                    // InstallDate  
                    // InstallTime
                    // ProductId                        00330-80000-00000-????
                    // ProductName                      Windows 10 Pro
                    // RegisteredOrganization           Microsoft
                    // RegisteredOwner                  Trevor
                    // ReleaseId                        1607
                    // SystemRoot                       C:\WINDOWS
                    if ($.os[0] === 'M') {
                        return 'For Windows Only';
                    }
                    var vbs, c, args, _arguments, argsL;
                    argsL = arguments.length;
                    args = [];
                    if (!argsL) {
                        _arguments = ['ProductName'];
                        argsL++;
                    } else {
                        _arguments = arguments;
                    }
                    for (c = 0; c < argsL; c++) {
                        vbs = 'CreateObject("InDesign.Application").ScriptArgs.SetValue "windowsData", CStr(CreateObject("WScript.Shell").RegRead ("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\' +
                            _arguments[c] +
                            '"))';
                        app.doScript(vbs, ScriptLanguage.VISUAL_BASIC);
                        args.push(app.scriptArgs.getValue("windowsData"));
                    }
                    return args;
                }
                
                alert('Windows ' + getWindowsData('CurrentMajorVersionNumber', 'CurrentMinorVersionNumber', 'CurrentBuildNumber').join('.')); // => Windows 10.0.1493
                alert(getWindowsData()); // => Windows 10 Pro
                

                 

                 

                Shame on the OP that you didn't even get any thanks for you version.

                 

                Regards

                 

                Trevor

                1 person found this helpful
                • 5. Re: Incorrect value of $.os on Windows 10
                  Trevorׅ Adobe Community Professional

                  Oh well, I just read Reliable way to get Windows Version from registry - Stack Overflow that the CurrentMajorVersionNumber and CurrentMinorVersionNumber keys are new to Wiindows 10 so that leaves us with Windows 10 Pro Build 14393  using ProductName and CurrentBuild.

                  Back to the drawing board for the minor version.

                   

                  P.s. for 64 bit can just check for x86 program files

                  • 6. Re: Incorrect value of $.os on Windows 10
                    Trevorׅ Adobe Community Professional

                    Here's using Ver with no bat

                     

                    Of course as you know the big advantage of Marc's method as he well knows is that it can be used in modular mode.

                    This one can't, but on the other hand one can normally catch a point in a script before the app is busy.

                    This method shows a nice way of returning values from cmd to InDesign through vbs.

                     

                    // By Trevor http://www.creative-scripts.com
                    // Help from https://technet.microsoft.com/en-us/library/ee156605.aspx
                    var vbs, ver;
                    vbs = ['Set objShell = CreateObject("WScript.Shell")',
                        'Set objExecObject = objShell.Exec("cmd /c Ver")',
                        'Do While Not objExecObject.StdOut.AtEndOfStream',
                        'strText = cstr (objExecObject.StdOut.ReadLine())',
                        'If Instr(strText, "Reply") > 0 Then',
                        'Exit Do',
                        'End If',
                        'Loop',
                        'CreateObject("InDesign.Application").ScriptArgs.SetValue "Ver", strText'
                    ].join('\n');
                    app.doScript(vbs, ScriptLanguage.VISUAL_BASIC);
                    ver = app.scriptArgs.getValue("Ver");
                    alert(ver); // => Microsoft Windows [Version 10.0.14393]
                    
                    • 7. Re: Incorrect value of $.os on Windows 10
                      Laubender Adobe Community Professional & MVP

                      Hi Trevor,

                      did you try Werner's method I linked to?

                      wmic (Windows) should also provide a lot of information.
                      And it is not restricted to Windows 10.


                      ( But as I already said: I cannot test it, because I'm on OSX )

                       

                      Regards,
                      Uwe

                      • 8. Re: Incorrect value of $.os on Windows 10
                        Marc Autret Level 4

                        Thanks a lot Trevor, 'benchmarking' these various approaches would be really great.

                         

                        Not totally confident with using a VBS subscript, since there are some environments where VBS is simply deactivated for security reasons—mine is a good example!

                         

                        However, I am not satisfied either with my current solution. The batch file approach is notoriously dangerous and most anti-malware will inhibit or sandbox the procedure. In addition, running a shell command (through either a BAT or a WScript) seems to take too much time for a task as stupid as getting the OS signature. The whole thing consumes up to 3,000 ms on my platform

                         

                        So, I'm still looking for a faster workaround. I strongly suspect that the Win version can be found and quickly parsed from some static file under the %windir%/System32 directory…

                         

                        @+

                        Marc

                        • 9. Re: Incorrect value of $.os on Windows 10
                          Trevorׅ Adobe Community Professional

                          Hi Uwe and Marc

                           

                          I only actually tried out my version from ID and other solutions like wmic and more from cmd.

                          I did see both of the both Marc's and Werner's code. I'm quite very surprised Marc's method takes so long. My getWindowsData function took 16ms which is pretty decent the 'Ver' script took 185 ms.

                           

                          I was not keen on Werner's solution because of it's running the vbs file, as ID has the vbs doScript I didn't like the idea of producing the file for nothing.

                          I also like Marc see problems with running vbs. I'd be interested to here of problems with the bat file.

                           

                          Marc do you mean to say that on your system you can't use doScript for vbs?

                          So this wouldn't work for you?

                          function openURL(url){
                              // by Trevor http://creative-scripts.com
                              var script, isMac;
                              isMac = +($.os[0]==='M');
                              if(!/^http/.test('' + url)) url = 'http://' + url;
                              script = localize(isMac ? 'open location "%1"' : 'CreateObject("WScript.Shell").Run("%1")',url);
                              app.doScript(script, ScriptLanguage[["VISUAL_BASIC","APPLESCRIPT_LANGUAGE"][isMac]]);
                          }
                          openURL('creative-scripts.com');
                          

                           

                          I'm very interested in the answer to that.

                           

                          I did see somewhere that there's is a .inf file in the System32 directory with the info but I can't remember where.

                           

                          Regards

                           

                          Trevor

                          1 person found this helpful
                          • 10. Re: Incorrect value of $.os on Windows 10
                            Marc Autret Level 4

                            Hi Trevor,

                             

                            Well well well!

                            Your snippet perfectly works on my Win7 system from any InDesign version, which implies that my alleged "VBS switcher" no longer blocks anything :-/

                            What is weird is wscript / cscript commands are nevertheless disabled at the cmd shell level… No idea how InDesign can run ScriptLanguage.VISUAL_BASIC under such circumstances, the fact is that it can. WindowsUpdate likely did an obscure job under the hood.

                             

                            So VBS sounds much more indelible than I thought and, with respect to your argument, there are good reasons to reconsider the available paths.

                             

                            (function showWinVersion()
                            // -------------------------------------
                            // Just for testing (assumes version >= Vista.)
                            {
                                vbs = """
                                    Dim r,o
                                    '---
                                    Set w = GetObject("winmgmts:")
                                    Set a = w.ExecQuery("Select * From Win32_OperatingSystem")
                                    '---
                                    For Each o in a
                                        r = Trim(o.Caption)
                                        r = r & "/" & o.OSArchitecture
                                        r = r & " (" & o.Version
                                        r = r & ", " & o.CSDVersion & ")"
                                        r = r & RTrim(" " & o.OtherTypeDescription)
                                        Exit For
                                    Next
                                    '---
                                    CreateObject("WScript.Shell").Popup r, 5
                                """;
                                
                                app.doScript(vbs, ScriptLanguage.VISUAL_BASIC);
                            })();
                            
                            

                             

                            No batch file generated and instant result, that's of course very tempting.

                            From now, what should we consider the best approach?

                             

                            @+

                            Marc

                            1 person found this helpful
                            • 11. Re: Incorrect value of $.os on Windows 10
                              Trevorׅ Adobe Community Professional

                              Hi Marc,

                               

                              Very interesting facts about the vbs blocker. I can't say I'm surprised, Windows is not particularly know for it's security!

                              There's a lot of security questions here.

                              Regarding which version to use? The vbs ones have major advantages of portability and speed with the disadvantage of mod mode.

                              So I guess a hybrid version might be best, one that will detect mod mode and if the app is free run the vbs and if not run the batch file.

                              Regarding timing the winmgmts method after changing the popup to a scriptArgs was taking about 150ms.

                              Given that the results of the winmgmts method is pretty complete - on my system Microsoft Windows 10 Pro/64-bit (10.0.14393) - I think that's the best one to use.

                               

                              I did a little edit on the vbs script as the was a problem with an extra ", " in your version

                              For Each o in a

                              r = o.Caption & "/" & o.OSArchitecture & " (" & o.Version  & ")"

                              Next

                              '---

                              CreateObject("InDesign.Application").ScriptArgs.SetValue "Ver", r

                               

                              BTW I now avoid when possible use of """  because it completely messes up my linters, color schemes and auto-formatters  also it can cause problems on when used with doscript see here #13 Re: Compiled scripts in 2015

                               

                              Regards

                               

                              Trevor

                              • 12. Re: Incorrect value of $.os on Windows 10
                                Laubender Adobe Community Professional & MVP

                                Hi Trevor,

                                 

                                //EDIT…

                                 

                                FWIW: About the tripple " notation:
                                I can see also the ESTK having trouble to do a decent job on code formatting, if one is using it this way:

                                 

                                var s = """\"Text String.\"""";
                                alert(s);
                                

                                 

                                This code is working as expected, but the ESTK is showing this where usually I'd think that something is wrong with my code looking at the code colors:

                                 

                                TrippleFencing-ESTK-View-1.png

                                 

                                 

                                Wheras writing it this way all looks fine:

                                 

                                var s = """
                                \"Text String.\"
                                """;
                                alert(s);
                                

                                 

                                TrippleFencing-ESTK-View-2.png

                                 

                                Regards,
                                Uwe

                                 

                                PS: I think, you do not use the ESTK anymore. Nevertheless I wanted to post this for scripters that still are hooked on the ESTK for developing and debugging.

                                1 person found this helpful
                                • 13. Re: Incorrect value of $.os on Windows 10
                                  Marc Autret Level 4

                                  Hi Uwe,

                                   

                                  A quick note on the triple quote syntax for declaring literal strings (which is ExtendScript specific.)

                                   

                                  1. It supports all escape sequences available in JS: \" \' \\ \n \r \b \t \v \f \xHH \uHHHH.

                                   

                                  2. But those escape sequences aren't required— except \\ —if the character is entered as is. This way you can insert quotes and newlines without breaking the syntax. Hence you save readability with literals where characters would require to be escaped in normal JS declaration.

                                   

                                  From 1 and 2, you can observe the following results:

                                   

                                  var s1 = """"test"""";   // That's <TQ>"test"<TQ>
                                  var s2 = """\"test\""""; // That's <TQ>\"test\"<TQ>, but escaping is not needed.
                                  
                                  alert( s1===s2 );        // => true
                                  
                                  // Now we enter newlines:
                                  
                                  var s3 = """
                                  "test"
                                  """;
                                  
                                  alert( s3===s1 );        // => false
                                  
                                  // Indeed:
                                  alert( s3.toSource() );  // => (new String("\n\"test\"\n"))
                                  

                                   

                                  @+

                                  Marc

                                  2 people found this helpful
                                  • 14. Re: Incorrect value of $.os on Windows 10
                                    Laubender Adobe Community Professional & MVP

                                    Hi Marc,

                                    thank you for that. Already noticed that \n \r \" \' are obviously supported.

                                    Good to know that \\ is the exception.

                                     

                                    It's only that I get a bit alerted when using the ESTK and code formatting acts a bit strange:

                                     

                                    TripleFence-CodeFormattingESTK-1.png

                                    TripleFence-CodeFormattingESTK-2.png

                                     

                                    So I will fencing the code with """ followed by a return at the start and end fencing with a return followed by """.

                                     

                                    What do you think about Trevor's concern using the triple """ fencing if one wants to use jsxbin code and run that jsxbin code fenced by triple ''' with a doScript() ? See my reply back in 2015 where I could detect a crash with CC 2015 but not with CC 2014.2 Re: Compiled scripts in 2015

                                     

                                    I'm not sure anymore, if that really is a problem.
                                    Just tested the old files with CC 2017.1 and had no crash.
                                    Also tested with an updated CC 2015.4.1 and had no crash.

                                     

                                    Regards,
                                    Uwe

                                    • 15. Re: Incorrect value of $.os on Windows 10
                                      Marc Autret Level 4

                                      Hi Uwe,

                                       

                                      I didn't investigate how ESTK deal with TQ, but I wonder who really would use ESTK for writing code that require TQ.

                                       

                                      > What do you think about Trevor's concern using the triple """

                                      > fencing if one wants to use jsxbin code and run that jsxbin code

                                      > fenced by triple ''' with a doScript() ?

                                       

                                      I read the related thread but couldn't reproduce the bug in CC 2015.1 from Windows 7 platform. No idea where it came from. As far as both TQ and Mac OS were involved, maybe the issue was linked to the internal encoding of the newline character—the famous \r vs. \n battle. Indeed, when we triple-quote multiple lines from within some EDI, the only character we aren't 100% sure about is the newline sequence, as it depends on how the EDI is configured (Mac vs. Win vs. Unix linefeed.) So, we aren't 100% sure about the actual contents of the triple-quoted string at this point. Now, assume that either the interpreter or the jsbin-compiler had some problem in parsing or propagating Mac-compliant newlines in those nested codes… Who knows? In your experiments you removed the TQ syntax by explicitly entering ... + '\n' + ... + '\n' … What if you typed '\r' or '\r\n' instead? Anyway, it seems Adobe fixed that.

                                       

                                      @+

                                      Marc

                                      2 people found this helpful