Jump to content
Sign in to follow this  
ptrex

VBscript code transposed in AutoIT code.

Recommended Posts

I have transposed a VBscript that gets some WMI object information in AutoIT.

I used the Beta version of AutoIT for it.

This script runs OK (no errors messages), but the output is not correct.

Since there is no information yet available in the Help files, relating to the new features of the Beta version. I would appreciated some feedback.

This is the VBscript :

On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _

("Select * from Win32_PhysicalMemoryArray")

For Each objItem in colItems

Wscript.Echo "Description: " & objItem.Description

Next

This is the AutoIt version :

$strComputer = "."

$objWMIService = objGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$colItem = $objWMIService.ExecQuery("Select Description from Win32_PhysicalMemoryArray")

Msgbox (0, "Description: ", $colItem, 2)

I did some guesing for translating this in AutoIT

I saw that the VB syntax CreateObject is translated in ObjCreate in AutoIt

So I guesed that the VB syntax GetObject is translated to ObjGet ??!!

Are there some help files available.

I would be interested to access the WMI objects in AutoIt.


Share this post


Link to post
Share on other sites

Might try search for Scriptomatic

heres code generated by it:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemoryArray", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output = $Output & "Depth: " & $objItem.Depth & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "Height: " & $objItem.Height & @CRLF
      $Output = $Output & "HotSwappable: " & $objItem.HotSwappable & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "Location: " & $objItem.Location & @CRLF
      $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
      $Output = $Output & "MaxCapacity: " & $objItem.MaxCapacity & @CRLF
      $Output = $Output & "MemoryDevices: " & $objItem.MemoryDevices & @CRLF
      $Output = $Output & "MemoryErrorCorrection: " & $objItem.MemoryErrorCorrection & @CRLF
      $Output = $Output & "Model: " & $objItem.Model & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "OtherIdentifyingInfo: " & $objItem.OtherIdentifyingInfo & @CRLF
      $Output = $Output & "PartNumber: " & $objItem.PartNumber & @CRLF
      $Output = $Output & "PoweredOn: " & $objItem.PoweredOn & @CRLF
      $Output = $Output & "Removable: " & $objItem.Removable & @CRLF
      $Output = $Output & "Replaceable: " & $objItem.Replaceable & @CRLF
      $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF
      $Output = $Output & "SKU: " & $objItem.SKU & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "Tag: " & $objItem.Tag & @CRLF
      $Output = $Output & "Use: " & $objItem.Use & @CRLF
      $Output = $Output & "Version: " & $objItem.Version & @CRLF
      $Output = $Output & "Weight: " & $objItem.Weight & @CRLF
      $Output = $Output & "Width: " & $objItem.Width & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PhysicalMemoryArray" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Since there is no information yet available in the Help files, relating to the new features of the Beta version. I would appreciated some feedback.

<{POST_SNAPBACK}>

Please look again. The helpfile that is installed with the beta is pretty complete.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

$colItem = $objWMIService.ExecQuery("Select Description from

$colItem is an array. You can't just display that array with msgbox. You need to "translate" the for loop to AutoIT as well.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

$colItem is an array. You can't just display that array with msgbox. You need to "translate" the for loop to AutoIT as well.

Cheers

Kurt

<{POST_SNAPBACK}>

Yep, Kurt is right.

ptrex: You forgot to convert these vb script:

For Each objItem in colItems
Wscript.Echo "Description: " & objItem.Description

Next

That would be:

For $objItem in $colItems
 Msgbox(0,"","Description: " & $objItem.Description)
Next

Regards,

-Sven

Edited by SvenP

Share this post


Link to post
Share on other sites

Hi Guys,

Thanks for the numerous feedback.

The Solution of Kurt and Sven did it.

Nevertheless I selected 1 item in the Array to display, It still needed the

For ... Loop.

2 items open from the feedback :

DaleHohm :

I did a search in the AutoITX help on ObjCreate and ObjGet but no results.

I' ve used the AutoITx Help file which is 159 Kb large dated 06/04/2005

Still gafrost:

I' ve installed Scriptomatic now. How did you manage to get an AutIT script out of it. Because It only supports VBscript, Perl, Jscript and Phyton.

Or did you create a VBscript from it and manually modified it to AutoIT script ?

By the way the script you added didn't run.

Thanks a lot.


Share this post


Link to post
Share on other sites

gafrost:

Thanks al lot for the tip !!! This can save me a lot of time.

Regarding the Help on AutoITX - ObjCreate and ObjGet, seemes that I was looking in the wrong Helpfile.

For anyone still interested :

For help on these subjects you don' t need to look into the AutoITx help file, but in the regaular AutoIT help file

Thanks you all for the support eventually everythings is sorted out.

AutoIT is the MAX !!!


Share this post


Link to post
Share on other sites

>I did a search in the AutoITX help on ObjCreate and ObjGet but no results.

You will need the latest Beta. Help file > 1 MB. See links to beta versions at bottom of download page.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...