Sign in to follow this  
Followers 0
MarkS

converting batch command to AutoIT equivalence

4 posts in this topic

I have this cmd line string:

for /f 'tokens=2 usebackq skip=1' %%v in (`wmic csproduct get name`) do set modl=%%v

When executed, it sets the variable of "modl" with D830 (I'm on a Dell Latitude D830).

Is there an equivalent way to do it in AutoIt?

I seem to have a mental block when it comes to for/f loops.

Thanks

Mark

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can access the WMI COM object interface directly with AutoIt, but if you want to use the command line WMIC:

#include <Constants.au3>

Global $sExtCmd = "wmic csproduct get name"
Global $iPID = Run($sExtCmd, @WorkingDir, @SW_MINIMIZE, $STDOUT_CHILD)
Global $sStdOut = ""
Do
    $sStdOut &= StdoutRead($iPID)
Until @error
Global $sName = StringStripWS(StringMid($sStdOut, StringInStr($sStdOut, @CRLF)), 1+2)

MsgBox(64, "Name", "$sName = " & $sName)

:blink:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You can access the WMI COM object interface directly with AutoIt, but if you want to use the command line WMIC:

#include <Constants.au3>

Global $sExtCmd = "wmic csproduct get name"
Global $iPID = Run($sExtCmd, @WorkingDir, @SW_MINIMIZE, $STDOUT_CHILD)
Global $sStdOut = ""
Do
    $sStdOut &= StdoutRead($iPID)
Until @error
Global $sName = StringStripWS(StringMid($sStdOut, StringInStr($sStdOut, @CRLF)), 1+2)

MsgBox(64, "Name", "$sName = " & $sName)

:blink:

Thanks for the quick reply, that really did the trick. So, how do you access wmi directly? Is it using the _WinAPI functions? Sorry, this is kinda new to me. I've been using batch files for 20 years but I'm beginning to see benefits of expanding my horizons.....

Share this post


Link to post
Share on other sites

Basically, anything you do in Scriptomatic with VBScript is pretty easy to translate into AutoIt:

Global $oWMI = ObjGet("winmgmts:")
Global $colCS = $oWMI.ExecQuery("Select * from Win32_ComputerSystem")
Global $colBIOS = $oWMI.ExecQuery("Select * from Win32_BIOS")
Global $sModel, $sSerial

For $oComputer In $colCS
    $sModel = $oComputer.Model
Next

For $oComputer In $colBIOS
    $sSerial = $oComputer.SerialNumber
Next

MsgBox(64, "Results", "Model = " & $sModel & @CRLF & "SN = " & $sSerial)

:blink:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0