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
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
PaulLaidler
Site Admin


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

PostPosted: Wed Jul 04, 2012 6:49 am    Post subject: Reply with quote

Brilliant! I will see if I can build that into a library function for future use.
Back to top
View user's profile Send private message AIM Address
Wilfried Linder



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

PostPosted: Wed Jul 04, 2012 7:57 am    Post subject: Reply with quote

Here is some modified code (f95) - see the subroutine get_os_info:

Code:
WINAPP

program test

IMPLICIT NONE

integer*4       bits,err_code
character*256   name,version,build

call get_os_info(name,version,build,bits,err_code)
print*,'Name     ',name(1:len_trim(name))
print*,'Version  ',version(1:len_trim(version))
print*,'Build    ',build(1:len_trim(build))
print*,'Bits     ',bits
print*,'err_code ',err_code
end

! ---------------------------------------------------------------------

subroutine get_os_info(name,version,build,bits,err_code)

IMPLICIT NONE
include 'win32api.ins'

integer,parameter::HKEY_LOCAL_MACHINE=Z'80000002'
integer*4       hKey,l,j,bits,err_code
character*256   RegPath,name,version,build

err_code = -1
name     = ' '
version  = ' '
build    = ' '
bits     = 32

RegPath  = 'Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion'
j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
if (j /= 0) then
  RegPath = 'Software\Microsoft\Windows NT\CurrentVersion'
  j = RegOpenKey(HKEY_LOCAL_MACHINE,trim(RegPath),hKey)
else
  bits = 64
end if

if (j == 0) then
  l = 256
  j = RegQueryValueEx(hKey,"ProductName",CCORE1(0),CCORE1(0),name,l)
  l = 256
  j = RegQueryValueEx(hKey,"CurrentVersion",CCORE1(0),CCORE1(0),version,l)
  l = 256
  j = RegQueryValueEx(hKey,"CurrentBuildNumber",CCORE1(0),CCORE1(0),build,l)
end if
j = RegCloseKey(hKey)

err_code = 0
return
end


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



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

PostPosted: Thu Jul 05, 2012 8:40 pm    Post subject: Reply with quote

Works like charm! Thanks again
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Jul 06, 2012 11:13 am    Post subject: Reply with quote

I have added a new routine called get_wow_ver@ for the next release.
This provides the machine operating system whilst get_os_ver@ remains unchanged and provides the compatible operating system when the executable runs in compatibility mode.
Back to top
View user's profile Send private message AIM Address
DanRRight



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

PostPosted: Sat Jul 07, 2012 6:10 pm    Post subject: Reply with quote

Thanks, Paul
Back to top
View user's profile Send private message
Shahram



Joined: 13 May 2013
Posts: 25

PostPosted: Sun Apr 27, 2014 9:28 am    Post subject: I incurred the same Reply with quote

Yes whenever you call GET_OS_VER@ in a large program, the result is not correct for windows 8. However, with a trick you can avoid such problem,


just write the following program:

winapp
program getver
use mswin
implicit none

INTEGER PLATFORMID, MAJOR, MINOR
OPEN(UNIT=40,FILE='winver.92',FORM='UNFORMATTED')
call GET_OS_VER@( PLATFORMID, MAJOR, MINOR )
write(40)MAJOR, MINOR,PLATFORMID
stop
end

This writes the result in a file and then in your large program read these values, it would be correct.
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
Page 3 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