WMi script in VB

Author Message
Vbnavigate

  • Total Posts : 7
  • Scores: 0
  • Reward points : 0
  • Joined: 6/20/2010
  • Status: offline
WMi script in VB Sunday, June 27, 2010 6:10 AM (permalink)
0
I am using Visual Studio 2008. I want to put a wmi script inside a Vb code.

For example, following the example from link
http://msdn.microsoft.com/en-us/library/aa390387%28VS.85%29.aspx ,  I have my code as follows:

 Dim strComputer, objReg, strKeyPath, subkey, arrSubKeys()         

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\XYZ Installs"
objReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)

For Each subkey In arrSubKeys
ListBox1.Items.Add(subkey.ToString)
       Next


I get the following exception in the line highlighted in red above.
InvalidCastException: Conversion from type 'DBNull' to type 'Object()' is not valid.

But when this code is executed separately in command line as a wmi script, it works fine. I am not sure if the issue is with declarations.

Any help is highly appreciated!

 
#1
    Vbnavigate

    • Total Posts : 7
    • Scores: 0
    • Reward points : 0
    • Joined: 6/20/2010
    • Status: offline
    Re:WMi script in VB Sunday, June 27, 2010 7:30 AM (permalink)
    0
    One of the problems I found is, I tried to list all the folders inside "SOFTWARE" and "XYZ Installs" is not getting listed. I opened the registry editor and found "XYZ Installs" inside "SOFTWARE" though.
     
    #2
      dm_4ever

      • Total Posts : 3687
      • Scores: 82
      • Reward points : 0
      • Joined: 6/29/2006
      • Location: Orange County, California
      • Status: offline
      Re:WMi script in VB Sunday, June 27, 2010 10:32 AM (permalink)
      0
      Are you writing this in VB.NET?
      dm_4ever

      My philosophy: K.I.S.S - Keep It Simple Stupid
      Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
      Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
       
      #3
        ginolard

        • Total Posts : 1347
        • Scores: 23
        • Reward points : 0
        • Joined: 8/11/2005
        • Status: offline
        Re:WMi script in VB Sunday, June 27, 2010 7:14 PM (permalink)
        0
        Why on earth would you want to run VBscript code from a VB application?

        If you want to know the VB.NET equivalent post something in the "Other Programming Languages" forum.  There are some .NET coders on here, myself included, who can probably help you out
        Author of ManagePC - http://managepc.net

         
        #4
          TomRiddle

          • Total Posts : 620
          • Scores: 12
          • Reward points : 0
          • Joined: 2/7/2008
          • Location: Australia
          • Status: offline
          Re:WMi script in VB Sunday, June 27, 2010 10:04 PM (permalink)
          0
          This forum is vbscript only
          In theory we know nothing about Visual Studio
           
          -join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
           
          #5
            rasimmer

            • Total Posts : 2363
            • Scores: 163
            • Reward points : 0
            • Joined: 3/19/2009
            • Location: Cedar Rapids, IA
            • Status: offline
            Re:WMi script in VB Monday, June 28, 2010 2:10 AM (permalink)
            0
            Well, no one really answered the question.  As several member eluded, you don't want to use vbScript code in a .NET application, you should be utilizing .NET to elminate unnecessary code and ensure that the application is working efficiently.  If you do a web search for "VB.NET WMI code generator", you should be able to find a code generator to get you started, or just doing a search for "VB.NET WMI StdRegProv" will provide other forums like this:  http://www.netframeworkdev.com/net-base-class-library/stdregprov--wmi-code-generator-4074.shtml
             
            #6

              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