novice_scripter
-
Total Posts
:
3
- Scores: 0
-
Reward points
:
0
- Joined: 1/26/2009
-
Status: offline
|
Instr() not working properly?
Friday, January 06, 2012 5:52 AM
( permalink)
Hello forum, The gist of what i'm trying to do is check whether a certain software version exists by reading from a registry key. on windows 7x64 the value will be found in the "Wow6432Node" key. On XPx32 systems it will be found in another key. I'm going to run my script in a mixed environment and want it to read from the correct key when accessing each system. Why does the code below not return the correct results? Thanks in advance. set wshell = wscript.createobject("wscript.shell") set OS64KEY = wshell.exec("REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node") ' detects if Operating System is 64bit OS64KEY= Ucase(OS64KEY.stdout.readAll) if instr(OS64KEY,"ERROR") > 0 then wscript.echo "key not exist" else wscript.echo "key exist" end if
|
|
|
|
59cobalt
-
Total Posts
:
975
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Instr() not working properly?
Friday, January 06, 2012 2:25 PM
( permalink)
novice_scripter Why does the code below not return the correct results? Because error messages are written to Std Err, not to Std Out. InStr() works perfectly fine. It just doesn't have anything to work on.
|
|
|
|
59cobalt
-
Total Posts
:
975
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Instr() not working properly?
Saturday, January 07, 2012 6:34 AM
( permalink)
BTW, checking the actual address width might be a more appropriate test: Set wmi = GetObject("winmgmts://root/cimv2")
is64bit = False
For Each obj In wmi.ExecQuery("SELECT * FROM Win32_Processor")
If obj.AddressWidth = 64 Then is64bit = True
Next
|
|
|
|
DiGiTAL.SkReAM
-
Total Posts
:
1259
- Scores: 7
-
Reward points
:
0
- Joined: 9/7/2005
- Location: Clearwater, FL, USA
-
Status: offline
|
Re:Instr() not working properly?
Monday, January 09, 2012 9:49 PM
( permalink)
59cobalt BTW, checking the actual address width might be a more appropriate test: Set wmi = GetObject("winmgmts://root/cimv2")
is64bit = False
For Each obj In wmi.ExecQuery("SELECT * FROM Win32_Processor")
If obj.AddressWidth = 64 Then is64bit = True
Next Shouldn't the first line of your code be: Set wmi = GetObject("winmgmts:\\.\root\cimv2") The "winmgmts://root/cimv2" part causes an Error of 'Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'GetObject''.
<message edited by DiGiTAL.SkReAM on Monday, January 09, 2012 10:00 PM>
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
|
|
59cobalt
-
Total Posts
:
975
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: offline
|
Re:Instr() not working properly?
Monday, January 09, 2012 10:57 PM
( permalink)
DiGiTAL.SkReAM Shouldn't the first line of your code be: Set wmi = GetObject("winmgmts:\\.\root\cimv2") Yes, I omitted the host part by mistake. It was supposed to be GetObject("winmgmts://./root/cimv2"). Thanks for catching.
|
|
|
|