Post by tsh73 on Dec 11, 2022 21:16:54 GMT
So we can
And if there is no varable, we'll get %environmentVariable% back - easy to check
We can get username and some paths - temp, appdata, programfiles (!!), userprofile
And there is "ver" command that returns something like
Microsoft Windows XP [Version 5.1.2600]
or
Microsoft Windows [Version 6.1.7601]
or
Microsoft Windows [Version 10.0.19045.2251]
Here's program that reads that stuff.
(says it is Win XP if "XP" is found in "ver" output, but you can check numbers, here's the table
ss64.com/nt/ver.html
)
Might get handy for making program run under Win 10 and Win XP ;)
echo %environmentVariable%
And if there is no varable, we'll get %environmentVariable% back - easy to check
We can get username and some paths - temp, appdata, programfiles (!!), userprofile
And there is "ver" command that returns something like
Microsoft Windows XP [Version 5.1.2600]
or
Microsoft Windows [Version 6.1.7601]
or
Microsoft Windows [Version 10.0.19045.2251]
Here's program that reads that stuff.
(says it is Win XP if "XP" is found in "ver" output, but you can check numbers, here's the table
ss64.com/nt/ver.html
)
Might get handy for making program run under Win 10 and Win XP ;)
'interrogating windows - environment vars (paths!) and windows version
dim info$(10, 10)
data "temp"
data "windir"
data "USERNAME"
data "APPDATA"
data "obviouslyWrongVarName"
data "ProgramFiles"
data "USERPROFILE"
data "XIZZY"
read EnvVar$
do
out$ = getEnvVar$(EnvVar$)
print "The value of "+EnvVar$+" system variable is"
print , out$
read EnvVar$
loop until EnvVar$="XIZZY"
winVer$=getWinVersion$()
print "WindowsVersion is "
print , winVer$ 'like, "Microsoft Windows XP [Version 5.1.2600]"
if instr(winVer$, "XP")>0 then print "Looks like Win XP"
filtered$=""
p=instr(winVer$, "[") 'skip all till opening [
for i =p to len(winVer$)
c$=mid$(winVer$,i,1)
if instr("0123456789.", c$) then filtered$=filtered$+c$
next
print "filtered digits are "
print , filtered$
print "val(filtered) is "
print , val(filtered$)
end
'----------------------------------------
function fileExists(path$, filename$)
'dimension the array info$( at the beginning of your program
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
sub doDelay ms
timer ms, [delay] 'delay
wait
[delay]
timer 0
end sub
function waitForFile(path$, fileName$, timeOutMS)
dMS = 50
do while timeOutMS >0
call doDelay dMS
if fileExists(path$, fileName$) then
if val(info$(1, 1))>0 then 'file should not be empty
waitForFile = 1: exit function
end if
end if
timeOutMS = timeOutMS - dMS
loop
waitForFile = 0
end function
function getEnvVar$(EnvVar$)
getEnvVar$ = ""
if fileExists(DefaultDir$, "env.txt") then kill "env.txt"
run "cmd.exe /c echo %"+EnvVar$+"% > env.txt", hide
if waitForFile(DefaultDir$, "env.txt", 2000) then
open "env.txt" for input as #1
line input #1, out$
close #1
getEnvVar$ = out$
else
print "Sorry - was not able to get var value"
exit function
end if
end function
function getWinVersion$()
getWinVersion$ = ""
if fileExists(DefaultDir$, "env.txt") then kill "env.txt"
run "cmd.exe /c ver > env.txt", hide
if waitForFile(DefaultDir$, "env.txt", 2000) then
open "env.txt" for input as #1
out$ = input$(#1,lof(#1)) '! this command outputs empty line first !
close #1
getWinVersion$ = trim$(out$)
else
print "Sorry - was not able to get var value"
exit function
end if
end function