Page 2 of 2

Re: CommonAppData on Windows 10 systems

Posted: Mon Jan 18, 2021 11:22 am
by amyren
plouf wrote: Sun Jan 17, 2021 5:23 pm using google search, found the following conversation

https://stackoverflow.com/questions/310 ... m-registry

explains why if you get "6.3" you should double check using the new variables
CurrentMajorVersionNumber and
CurrentMinorVersionNumber

if it works for you, please post result for future help, since i have not handy win10 atm to check
Thanks, I think that would work. CurrentMajorVersionNumber or CurrentMinorVersionNumber does not exist in the Windows 7 registery. I dont know how this is in Windows 8.1. ReadRegistryKey will give an error if the entry does not exist, thats why I used ExitOnError(False) in the example below.

Code: Select all

SetFont(#SANS, 36)
SetFontStyle(#ANTIALIAS)
ExitOnError(False)
winver$ = ReadRegistryKey(#HKEY_LOCAL_MACHINE,"Software/Microsoft/Windows NT/CurrentVersion/CurrentVersion")
winver = Val(winver$)
If winver <  6.1
	TextOut(#CENTER, #CENTER, "Your Windows version is older than Windows 7")
ElseIf winver = 6.1 
	TextOut(#CENTER, #CENTER, "You are using Windows 7 or 2008 Server")
ElseIf winver = 6.2 
	TextOut(#CENTER, #CENTER, "You are using Windows 8.0 or 2012 Server")
Else
	winmajor$ = ReadRegistryKey(#HKEY_LOCAL_MACHINE,"Software/Microsoft/Windows NT/CurrentVersion/CurrentMajorVersionNumber")
	winmajor = Val(winmajor$)
	If winmajor < 10
		TextOut(#CENTER, #CENTER, "You are using Windows 8.1 Or 2012 Server")
	Else
		TextOut(#CENTER, #CENTER, "You are using Windows 10 or newer")
	EndIf
EndIf
WaitLeftMouse
End
I discovered what for me was an unexpected bahaviour of ExitOnError()
If using Val(ReadRegisteryKey(xxx) on a key that doesnt exist, the script will exit on an error regardless if ExitOnError is set to false.
Thats why I read the registerykey into a string first and then convert it into value in a separate line in the script above.

Re: CommonAppData on Windows 10 systems

Posted: Fri Jan 22, 2021 12:21 am
by airsoftsoftwair
amyren wrote: Mon Jan 18, 2021 11:22 am I discovered what for me was an unexpected bahaviour of ExitOnError()
If using Val(ReadRegisteryKey(xxx) on a key that doesnt exist, the script will exit on an error regardless if ExitOnError is set to false.
Yes, that's true because it is a syntactical error, i.e. Val() is not passed enough arguments. Those errors can't be disabled by ExitOnError(). So this is defined behaviour.