EDN Admin
Well-known member
I am currently working with a vbscript that fetch and add instances to WMI such as finding Installed Antivirus Information and much more, I want do this stuff through vb.net, how can we do this in vb.net.
My VBscript is below
<pre class="prettyprint lang-vb strComputer = "."
On Error Resume Next
MsgBox "Start"
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootSecurityCenter")
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")
If Err = 0 Then
For Each objAntiVirusProduct In colItems
strMessage = ""
strMessage = strMessage & objAntiVirusProduct.companyName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.displayName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.onAccessScanningEnabled & vbCRLF
strMessage = strMessage & objAntiVirusProduct.productUptoDate & vbCRLF
strMessage = strMessage & objAntiVirusProduct.versionNumber & vbCRLF
MsgBox strMessage, , "AntiVirus SecurityCenter"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set colItems = oWMI.ExecQuery("Select * from FirewallProduct")
If Err = 0 Then
For Each objFirewallProduct In colItems
strMessage = ""
strMessage = strMessage & objFirewallProduct.companyName & vbCRLF
strMessage = strMessage & objFirewallProduct.displayName & vbCRLF
strMessage = strMessage & objFirewallProduct.enabled & vbCRLF
strMessage = strMessage & objFirewallProduct.versionNumber & vbCRLF
MsgBox strMessage, , "Firewall SecurityCenter"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootSecurityCenter2")
If Err.Number = -2147217394 Then
Err.Clear
MsgBox "WMI Class SecurityCenter2 not found"
Else
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")
If Err = 0 Then
For Each objAntiVirusProduct In colItems
strMessage = ""
strMessage = strMessage & objAntiVirusProduct.displayName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.productState & vbCRLF
MsgBox strMessage, , "AntiVirus SecurityCenter2"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set colItems = oWMI.ExecQuery("Select * from FirewallProduct")
If Err = 0 Then
For Each objFirewallProduct In colItems
strMessage = ""
strMessage = strMessage & objFirewallProduct.companyName & vbCRLF
strMessage = strMessage & objFirewallProduct.displayName & vbCRLF
strMessage = strMessage & objFirewallProduct.enabled & vbCRLF
strMessage = strMessage & objFirewallProduct.versionNumber & vbCRLF
MsgBox strMessage, , "Firewall SecurityCenter2"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
End If
MsgBox "Done"
[/code]
Any help will be appreciated
Thanks
View the full article
My VBscript is below
<pre class="prettyprint lang-vb strComputer = "."
On Error Resume Next
MsgBox "Start"
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootSecurityCenter")
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")
If Err = 0 Then
For Each objAntiVirusProduct In colItems
strMessage = ""
strMessage = strMessage & objAntiVirusProduct.companyName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.displayName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.onAccessScanningEnabled & vbCRLF
strMessage = strMessage & objAntiVirusProduct.productUptoDate & vbCRLF
strMessage = strMessage & objAntiVirusProduct.versionNumber & vbCRLF
MsgBox strMessage, , "AntiVirus SecurityCenter"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set colItems = oWMI.ExecQuery("Select * from FirewallProduct")
If Err = 0 Then
For Each objFirewallProduct In colItems
strMessage = ""
strMessage = strMessage & objFirewallProduct.companyName & vbCRLF
strMessage = strMessage & objFirewallProduct.displayName & vbCRLF
strMessage = strMessage & objFirewallProduct.enabled & vbCRLF
strMessage = strMessage & objFirewallProduct.versionNumber & vbCRLF
MsgBox strMessage, , "Firewall SecurityCenter"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootSecurityCenter2")
If Err.Number = -2147217394 Then
Err.Clear
MsgBox "WMI Class SecurityCenter2 not found"
Else
Set colItems = oWMI.ExecQuery("Select * from AntiVirusProduct")
If Err = 0 Then
For Each objAntiVirusProduct In colItems
strMessage = ""
strMessage = strMessage & objAntiVirusProduct.displayName & vbCRLF
strMessage = strMessage & objAntiVirusProduct.productState & vbCRLF
MsgBox strMessage, , "AntiVirus SecurityCenter2"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
Set colItems = oWMI.ExecQuery("Select * from FirewallProduct")
If Err = 0 Then
For Each objFirewallProduct In colItems
strMessage = ""
strMessage = strMessage & objFirewallProduct.companyName & vbCRLF
strMessage = strMessage & objFirewallProduct.displayName & vbCRLF
strMessage = strMessage & objFirewallProduct.enabled & vbCRLF
strMessage = strMessage & objFirewallProduct.versionNumber & vbCRLF
MsgBox strMessage, , "Firewall SecurityCenter2"
Next
Else
strMessage = ""
strMessage = strMessage & "Error Number: " & Err.Number & vbCRLF
strMessage = strMessage & "Error Source: " & Err.Source & vbCRLF
strMessage = strMessage & "Error Description: " & Err.Description & vbCRLF
MsgBox strMessage
Err.Clear
End If
End If
MsgBox "Done"
[/code]
Any help will be appreciated
Thanks
View the full article