Home All Groups Group Topic Archive Search About

Convert Script code to VB.Net

Author
6 Mar 2006 6:13 PM
Allen
Given a script like the following is there a recipe I could use to convert
it to VB.net code.'myServer = "."'The following moniker identifies the
root\cimv2 namespace on the myServer computer. An SWbemServices object is
returned.'objWMIService = GetObject("winmgmts:\\" & myServer &
"\root\cimv2")'colItems = objWMIService.ExecQuery("Select * from
Win32_Processor")'For Each objItem In colItems' Wscript.Echo("Processor Id:
" & objItem.ProcessorId)' Wscript.Echo("Maximum Clock Speed: " &
objItem.MaxClockSpeed)'NextI tried the following but don't really know why
it works.The parameter for GetObject is a path name to a file.What does the
path I used point to?Dim strComputer As String = "."Dim objWMIService As
Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Dim colItems
As Object = objWMIService.ExecQuery("Select * from Win32_Processor")For Each
objItem As Object In colItemsConsole.WriteLine("Processor Id: " &
objItem.ProcessorId)Console.WriteLine("Maximum Clock Speed: " &
objItem.MaxClockSpeed)NextInstead of Object are there .Net types that can be
used for this script?In general, given a script how does one determine the
types to use?I know I'm asking for a lot and I'd be appreciative for partial
answers or any help at all.Thanks

Author
6 Mar 2006 6:34 PM
Allen
I've no idea what happed to the previous post.
Here it is again.

Given a script like the following is there a recipe I could use to convert
  it to VB.net code.

'myServer = "."
'objWMIService = GetObject("winmgmts:\\" & myServer &
   "\root\cimv2")
'colItems = objWMIService.ExecQuery("Select * from
   Win32_Processor")
'For Each objItem In colItems' Wscript.Echo("Processor Id:
   " & objItem.ProcessorId)' Wscript.Echo("Maximum Clock Speed: " &
   objItem.MaxClockSpeed)
'Next

I tried the following but don't really know why it works.
  The parameter for GetObject is a path name to a file.What does the
  path I used point to?

Dim strComputer As String = "."Dim objWMIService As
   Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim colItems  As Object =
  objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem As Object In colItemsConsole.
WriteLine("Processor Id: " &
   objItem.ProcessorId)Console.
WriteLine("Maximum Clock Speed: " &
   objItem.MaxClockSpeed)
Next

Instead of Object are there .Net types that can be
used for this script?In general, given a script how does one determine the
types to use?

I know I'm asking for a lot and I'd be appreciative for partial
answers or any help at all.Thanks
Author
6 Mar 2006 6:42 PM
Cor Ligthert [MVP]
Allen,

See this link on our website.
I thought that it is almost what your want.

http://www.vb-tips.com/default.aspx?ID=632054ab-5fe5-4779-a6be-111ae0c748f2

There are more WMI tips search for that just on WMI

I hope this helps,

Cor

Show quoteHide quote
"Allen" <allen99NOSPAM@a-znet.com> schreef in bericht
news:%23JmvWyUQGHA.564@TK2MSFTNGP12.phx.gbl...
> I've no idea what happed to the previous post.
> Here it is again.
>
> Given a script like the following is there a recipe I could use to convert
>  it to VB.net code.
>
> 'myServer = "."
> 'objWMIService = GetObject("winmgmts:\\" & myServer &
>   "\root\cimv2")
> 'colItems = objWMIService.ExecQuery("Select * from
>   Win32_Processor")
> 'For Each objItem In colItems' Wscript.Echo("Processor Id:
>   " & objItem.ProcessorId)' Wscript.Echo("Maximum Clock Speed: " &
>   objItem.MaxClockSpeed)
> 'Next
>
> I tried the following but don't really know why it works.
>  The parameter for GetObject is a path name to a file.What does the
>  path I used point to?
>
> Dim strComputer As String = "."Dim objWMIService As
>   Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Dim colItems  As Object =
>  objWMIService.ExecQuery("Select * from Win32_Processor")
> For Each objItem As Object In colItemsConsole.
> WriteLine("Processor Id: " &
>   objItem.ProcessorId)Console.
> WriteLine("Maximum Clock Speed: " &
>   objItem.MaxClockSpeed)
> Next
>
> Instead of Object are there .Net types that can be
> used for this script?In general, given a script how does one determine the
> types to use?
>
> I know I'm asking for a lot and I'd be appreciative for partial
> answers or any help at all.Thanks
>
>
>
Author
6 Mar 2006 9:29 PM
Allen
You never had to use
Dim objWMIService As Object = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Do you know what that does?


Nice site
Thanks


Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:eZieG2UQGHA.1868@TK2MSFTNGP09.phx.gbl...
> Allen,
>
> See this link on our website.
> I thought that it is almost what your want.
>
> http://www.vb-tips.com/default.aspx?ID=632054ab-5fe5-4779-a6be-111ae0c748f2
>
> There are more WMI tips search for that just on WMI
>
> I hope this helps,
>
> Cor
>
> "Allen" <allen99NOSPAM@a-znet.com> schreef in bericht
> news:%23JmvWyUQGHA.564@TK2MSFTNGP12.phx.gbl...
>> I've no idea what happed to the previous post.
>> Here it is again.
>>
>> Given a script like the following is there a recipe I could use to
>> convert
>>  it to VB.net code.
>>
>> 'myServer = "."
>> 'objWMIService = GetObject("winmgmts:\\" & myServer &
>>   "\root\cimv2")
>> 'colItems = objWMIService.ExecQuery("Select * from
>>   Win32_Processor")
>> 'For Each objItem In colItems' Wscript.Echo("Processor Id:
>>   " & objItem.ProcessorId)' Wscript.Echo("Maximum Clock Speed: " &
>>   objItem.MaxClockSpeed)
>> 'Next
>>
>> I tried the following but don't really know why it works.
>>  The parameter for GetObject is a path name to a file.What does the
>>  path I used point to?
>>
>> Dim strComputer As String = "."Dim objWMIService As
>>   Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>> Dim colItems  As Object =
>>  objWMIService.ExecQuery("Select * from Win32_Processor")
>> For Each objItem As Object In colItemsConsole.
>> WriteLine("Processor Id: " &
>>   objItem.ProcessorId)Console.
>> WriteLine("Maximum Clock Speed: " &
>>   objItem.MaxClockSpeed)
>> Next
>>
>> Instead of Object are there .Net types that can be
>> used for this script?In general, given a script how does one determine
>> the
>> types to use?
>>
>> I know I'm asking for a lot and I'd be appreciative for partial
>> answers or any help at all.Thanks
>>
>>
>>
>
>