Jump to content

Objects and AutoIt..


Recommended Posts

Can some one explain to me what an object is used for and how it makes my scripting less skiddiedly do like?

Also, an example script would be nice.

What are objects for? etc.

eg-

$strComputer = "."
$objWMIServices = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$sink = ObjCreate("WbemScripting.SWbemSink")
ObjEvent($sink,"SINK_")
$objWMIServices.ExecNotificationQueryAsync ($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'")

While 1
    Sleep(500)
Wend

Func SINK_OnObjectReady($objObject, $objAsyncContext)
 If $objObject.TargetInstance.DriveType = 2 Then
        Select
            Case $objObject.Path_.Class()="__InstanceCreationEvent"
               ;USB detected
            Case $objObject.Path_.Class()="__InstanceDeletionEvent"
               ;USB removed
        EndSelect
    EndIf
EndFunc

How the hell does

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

$sink = ObjCreate("WbemScripting.SWbemSink")

ObjEvent($sink,"SINK_")

$objWMIServices.ExecNotificationQueryAsync ($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'")

work???

Edited by System238
Link to comment
Share on other sites

Event sinks are kind of jumping in at the deep end. You might want to start on easier object references and work your way up to those. Search for something easy like adding a local user:

#RequireAdmin

$oWinNT = ObjGet("WinNT://.")
$oUser = $oWinNT.Create("user", "MyNewUser")
$oUser.SetPassword("MyNewPa$$word")
$oUser.SetInfo

:)

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...