forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find Operating System the program is running on ?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Mon Jun 18, 2012 6:11 pm    Post subject: Reply with quote

Thanks Detlef and Paul
Summary so far under Win7 64bit is
1) the code above as is gives me right major, minor=6, 1
2) when run it via debugger i gets wrong result = 5, 1
3) being placed in the large code i get always only wrong 5, 1
4) /win key gives me no difference
Back to top
View user's profile Send private message
dpannhorst



Joined: 29 Aug 2005
Posts: 165
Location: Berlin, Germany

PostPosted: Mon Jun 18, 2012 6:45 pm    Post subject: Reply with quote

Hi Dan,

I have no problem when I run it via debugger.

I am still getting major, minor = 6, 1

I have made a screenshot in the debug mode, but I don't know how to upload it to the forum here.

Detlef
Back to top
View user's profile Send private message Visit poster's website
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Mon Jun 18, 2012 8:51 pm    Post subject: Reply with quote

There is nothing wrong with your code. Both methods give the same result means something behind exists.

I suggest to try running it in the XP compatibility mode (Properties/Compatibility/Run this program in XP compatibility mode for/ Windows XP(Service Pack 3) ). This and future EXE versions as a result should give you 5, 1. So these two methods detect not the OS on your computer but something different.

But is there a way to get the ***OS on this computer*** instead of lowest OS the code is compatible running with ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6222
Location: Salford, UK

PostPosted: Sat Jun 23, 2012 1:20 pm    Post subject: Reply with quote

GetVersion is the old API function which has limitations.

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx

get_os_ver@ is the Salford/Silverfrost library routine and it calls the API GetVersionEx.

However the resulting major and minor version numbers are not unique as shown in the table at...

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx


So we have a problem if you need to distinguish between operating systems with the same major and minor version numbers.
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Sun Jun 24, 2012 4:22 am    Post subject: Reply with quote

It will be fine for me with the uncertainty between Win7 and Server 2012 (where both Major/Minor are equal to 6/1) but it will be not if my Win7 computer (Major 6) tells me that this is XP (Major 5)...

Things are that I've made the code compatible with XP by the following reason. This code is actually using another code as an interface between my program and the stock data source of electronic trading broker (Ameritrade or whatever, it is compatible to all of them). They communicate in a client - server manner, thanks to FTN95/CWP function allowing us to get the data from the internet (please make much more such functions ! Intel VF has 20+ more of them but they are not as user-friendly as in FTN95). This interface program when running opening internal server and my program pings its port, port responds accordingly to the protocol, and my code gets the responded data. Very easy.

The problem is that this interface program written by other authors under XP is not working flawlessly when it is moved to Win7. So i have set both mine and interface codes while working under Win7 to be compatible with XP using compatibility option of Win7 (which is also as easy as just couple clicks like i showed above).

The result is that now GetVersionEx is reporting the current Windows version on the computer as if it is XP. So when i move back to real XP sometimes i need to change all the disk names in my code manually because Win7 messed up all the disk partition letters on the computer which is not possible to rename (i have too many partitions from C to Z). If some function detected OS computer is running correctly i'd programmed that and all would work automatically.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6222
Location: Salford, UK

PostPosted: Sun Jun 24, 2012 5:55 pm    Post subject: Reply with quote

There appears to be nothing wrong with the code for get_os_ver@. Just a straight call to GetVersionEx.

The problem is probably revealed by the following comment copied from the MSDN topic on GetVersionEx....

Quote:
If compatibility mode is in effect, the GetVersionEx function reports the operating system as it identifies itself, which may not be the operating system that is installed. For example, if compatibility mode is in effect, GetVersionEx reports the operating system that is selected for application compatibility.


If all else fails there will be a registry setting somewhere that will identify the root operating system.
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Mon Jun 25, 2012 10:58 pm    Post subject: Reply with quote

Yes, thanks that you have confirmed my feelings about the whole situation and for good suggestion. As to WinAPI - do you or anyone here remember any functions which expose the core operating system ? ....i think i have met something like this before
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6222
Location: Salford, UK

PostPosted: Tue Jun 26, 2012 7:50 am    Post subject: Reply with quote

You can find the information in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion but there ought to be a simpler way.

If no one can suggest a better way then I will add a new routine to the library that will extract the relevant information (or maybe change get_os_ver@).
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Thu Jun 28, 2012 12:59 am    Post subject: Reply with quote

Still searching for simple way...May be John Horspool will remind us which WinAPI function reported Windows OS ? I think i played with one of his suggestions and have seen along the other things as a side effect some function told about Windows version. Or may be it was even some of Clearwin ?!
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Thu Jun 28, 2012 9:11 am    Post subject: Reply with quote

I don't know if this can help, but according to Paul's remark I wrote a little test:

Code:
      WINAPP

      program test

      IMPLICIT NONE

      include 'win32api.ins'

      INTEGER,PARAMETER::HKEY_LOCAL_MACHINE=Z'80000002'
      integer*4      hKey,l,j
      character*256  RegPath,version,string

      RegPath = 'Software\Microsoft\Windows NT\CurrentVersion'

      j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
      if (j .eq. 0) then
        version = ' '
        l = 256
        j = RegQueryValueEx(hKey,"ProductName",
     *    CCORE1(0),CCORE1(0),version,l)
        string = 'OS '//trim(version)
        print*,string(1:len_trim(string))
        version = ' '
        l = 256
        j = RegQueryValueEx(hKey,"CurrentVersion",
     *    CCORE1(0),CCORE1(0),version,l)
        string = 'Version '//trim(version)//', build'
        version = ' '
        l = 256
        j = RegQueryValueEx(hKey,"CurrentBuildNumber",
     *    CCORE1(0),CCORE1(0),version,l)
        string = trim(string)//' '//trim(version)
        print*,string(1:len_trim(string))
      end if
      j = RegCloseKey(hKey)

      RegPath = 'SYSTEM\CurrentControlSet\Control\ProductOptions'
      j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
      if (j .eq. 0) then
        version = ' '
        l = 256
        j = RegQueryValueEx(hKey,"ProductSuite",
     *    CCORE1(0),CCORE1(0),version,l)
        print*,version(1:len_trim(version))
      end if
      j = RegCloseKey(hKey)

      end


You may compare the results with those from winver.exe. Surely there are more parameters of interest in the registry database.

Regards - Wilfried
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Thu Jun 28, 2012 3:28 pm    Post subject: Reply with quote

Addition to see whether Windows7 is installed as 32- or 64-bit version:

Code:
      integer*2   dummy

      j = 64
      call attach@('c:\windows\syswow64',dummy)
      if (dummy .ne. 0) j = 32
      print*,j


Regards - Wilfried
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Fri Jun 29, 2012 4:30 am    Post subject: Reply with quote

Thanks Wilfried for the shot. Well, seems this task is harder then it looks. Getting with this method the same story as with previous method. As soon as EXE is in compatibility mode with XP, it detects XP not Win7.

It was interesting though how you have detected 32 vs 64 bit OS....May be meantime i will use it as a temporal indirect solution, because my real XP was 32 bit and Win7 is 64bit Smile. By the way will it work with the 32bit Win7 ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6222
Location: Salford, UK

PostPosted: Tue Jul 03, 2012 2:50 pm    Post subject: Reply with quote

I can confirm that the registry value above also changes with the compatibility mode. So I am stuck for now.

See also http://blogs.msdn.com/b/patricka/archive/2010/01/14/common-problems-with-checking-os-versions-in-code.aspx
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Tue Jul 03, 2012 3:55 pm    Post subject: Reply with quote

If I change the first RegPath line in my example above from

Code:
      RegPath = 'Software\Microsoft\Windows NT\CurrentVersion'


to

Code:
      RegPath =
     * 'Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion'


then I get the message "Windows 7" even if I run the programme in compatibility mode (XP). May be this helps?

If yes, then to prevent problems on PCs with "real" XP operation system I would replace the first line by

Code:
      RegPath =
     * 'Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion'
      j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
      if (j .ne. 0) then
        RegPath = 'Software\Microsoft\Windows NT\CurrentVersion'
        j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
      end if


Regards - Wilfried
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2154
Location: South Pole, Antarctica

PostPosted: Tue Jul 03, 2012 7:15 pm    Post subject: Reply with quote

Holly...that works...wow people started doing real wizardry here...i even still not get what and how Smile. Nice to see the little miracle done. Kudos and big thanks, Wilfried!!! Thanks all for the efforts.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group