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)
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!
|
|
|
|
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)
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.
|
|
|
|
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)
Are you writing this in VB.NET?
|
|
|
|
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)
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
|
|
|
|
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)
This forum is vbscript only In theory we know nothing about Visual Studio
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-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)
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
|
|
|
|