Sign in to follow this  
Followers 0
ZiggyStardust

Newbie Looking for Language

5 posts in this topic

To make a long story short I have been out of the programming loop so long I am starting from ground zero. I have been looking hard at AutoIt to see if it will do what I need it to do. I have a little VB Script that checks for the presence if a Kingston Flash Drive in a computer based on the Windows Hardware ID:

Sub GetLockState()

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity")

For Each objItem in colItems

if objItem.DeviceID <> "" then

testDevice=InStr(objItem.DeviceID, "KINGSTON")

if testDevice <> 0 then

Wscript.Echo "Device ID: " & objItem.DeviceID

Wscript.Echo "Class GUID: " & objItem.ClassGuid

Wscript.Echo "Description: " & objItem.Description

Wscript.Echo "Manufacturer: " & objItem.Manufacturer

Wscript.Echo "Name: " & objItem.Name

Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID

Wscript.Echo "Service: " & objItem.Service

LockState = "Present"

end if

end if

Next

End Sub

Can this be accomplished easly in AutoIt?

Share this post


Link to post
Share on other sites



This should work.

Global $LockState
Local $sRet = GetLockState()

If $LockState = "Present" Then
    MsgBox(0, "Results", $sRet)
Else
    MsgBox(0, "Results", "Kingston Drive not present")
EndIf


Func GetLockState()
    Local $testDevice, $objItem, $sStr = "", $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
    Local $colItems = $objWMIService.ExecQuery("Select * from Win32_PnPEntity")
    For $objItem In $colItems
        If $objItem.DeviceID <> "" Then
            $testDevice = StringInStr($objItem.DeviceID, "KINGSTON")
            If $testDevice <> 0 Then
                $sStr &= "Device ID: " & $objItem.DeviceID & @LF
                $sStr &= "Class GUID: " & $objItem.ClassGuid & @LF
                $sStr &= "Description: " & $objItem.Description & @LF
                $sStr &= "Manufacturer: " & $objItem.Manufacturer & @LF
                $sStr &= "Name: " & $objItem.Name & @LF
                $sStr &= "PNP Device ID: " & $objItem.PNPDeviceID & @LF
                $sStr &= "Service: " & $objItem.Service & @LF & @LF
                $LockState = "Present"
            EndIf
        EndIf
    Next
    Return $sStr
EndFunc   ;==>GetLockState

Share this post


Link to post
Share on other sites

Thank Malkey. It looks enough like VB scripting I am going to give it a shot. Of course I am struggling. I am plauing with the _BlockInputEx function and must be missing something simple. I want to block everything except ESC, F5, F12, PGUP and PGDN.

Here is the code I am using:

_BlockInputEx(1, "0x1B|0x77|0x206|0x111|0x121")

The ESC key is about the only one that is not blocked of the four. I looked at the on-line documentation for ASCII codes and nothing really tells me what the hex representation is for PgUp, PgDN, (I really want to allow Up, Dn, Left and RIght arrow). Getting the hex values for the extended ascii set is one question. The second would be when do I use the hex value and when can I use the litteral "ESC"

Share this post


Link to post
Share on other sites

The Asc() command gives the ASCII code of a character, but when I run Asc('{pgdn}') or Asc('{pgup}') it returns the code for the bracket, so I guess that pgdn doesn't have a code :)

you can still use the string values for _BlockInputEx, so it would be

_BlockInputEx(1, '{pgdn}|{pgup}|{esc}|{F5}|{F12}')

If you are new to AutoIt, then I would highly recommend simply reading through the help file that comes with AutoIt. AutoIt was my first scripting language, and I completely taught myself to code using only the help file and SciTE.


[font=arial, sans-serif]How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?[/font][font=arial, sans-serif]<div>This is how you annoy a web developer.</span>[/font]

Share this post


Link to post
Share on other sites

Thank you both for the replies. Greatly appreciated. In reading through the docs I was looking at the wrong chart. I should have been looking through the send documentation. The string values are listed in detal.

I think I was a little leery of jumping back in to programming after a 15 year hatius. I sat down for 10 hours yesterday with AutoIt, Led Zeppelin and a set of Bose headphones and was very, very pleased with where I was at the end of the day. I guess you can teach an old dog new tricks :)

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