Instr() not working properly?

Author Message
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)
0
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
 
#1
    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)
    0
    novice_scripter
    Why does the code below not return the correct results?
    Because error messages are written to StdErr, not to StdOut. InStr() works perfectly fine. It just doesn't have anything to work on.
     
    #2
      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)
      0
      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

       
      #3
        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)
        0
        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
         
        #4
          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)
          0
          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.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9