pintas Posted November 15, 2009 Share Posted November 15, 2009 (edited) I've taken a small piece of code i found here to monitor usb insertion and removal, and i'm trying to add some features to it, but i came across a problem. expandcollapse popup#Include <Constants.au3> $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Opt("TrayMenuMode", 1) $Pen = "Program" $Exit = TrayCreateItem("Exit") TraySetState() While 1 Sleep(100) $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $Exit Exit ExitLoop EndSelect $objEvent = $colEvents.NextEvent $autorun = $objEvent.TargetInstance.DeviceId & "\autorun.inf" $drive = $objEvent.TargetInstance.DeviceId $i = 0 If $objEvent.TargetInstance.DriveType = 2 Then Select Case $objEvent.Path_.Class()="__InstanceCreationEvent" $UsedToBe = 0 If Not FileExists($autorun) And $UsedToBe = 0 Then TrayTip("Pen Security", $autorun & " not present ! ;)", 2, 1) EndIf Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR) PlaySound() For $I = 1 To 3 If FileExists($autorun) Then $UsedToBe = 1 FileSetAttrib($autorun, '-SHR-A') FileDelete($autorun) Sleep(500) Else ExitLoop EndIf Next If Not FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $autorun & " deleted ! ;)", 2, 1) EndIf If FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $drive & "\AUTORUN.INF NOT DELETED !" & @CRLF & "Pen-Drive Probably Write-Protected.", 5, 1) EndIf Case $objEvent.Path_.Class()="__InstanceDeletionEvent" Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR) ExitLoop EndSelect EndIf Next Wend What am i doing wrong here? How can add functions to my tray without losing the loop to detect usb? How can i get that Exit Case working inside the loop? Can i use two loops? Edited November 15, 2009 by pintas Link to comment Share on other sites More sharing options...
Kip Posted November 15, 2009 Share Posted November 15, 2009 (edited) Case $msg = $Exit Exit ExitLoop EndSelectThe "ExitLoop" is useless here. EndIf Next WendHow does this script even run? You close a For statement that doesn't even exist. Edited November 15, 2009 by Kip MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
pintas Posted November 15, 2009 Author Share Posted November 15, 2009 (edited) You're right, i forgot to paste some important parts, but the script is very long now and it's kind of hard to keep track of everything all the time. But the For statement is in my original full two thousand lines script... The problem is the case $msg = $Exit doesn't do anything. Why??? btw, that's just an example, i've added many more of those, but they don't work... Edited November 15, 2009 by pintas Link to comment Share on other sites More sharing options...
Kip Posted November 16, 2009 Share Posted November 16, 2009 Well, if you leave out important parts, then how can we help you? MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
pintas Posted November 16, 2009 Author Share Posted November 16, 2009 Well, if you leave out important parts, then how can we help you? I meant the for statement. As you can see i just removed the Next in the end of this example, and still there is no way i can get it working. Do i need to have two different files running side by side to have the same effect? Btw... I got an eye on X programming expandcollapse popup#Include <Constants.au3> $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Opt("TrayMenuMode", 1) $Pen = "Program" $Exit = TrayCreateItem("Exit") TraySetState() While 1 Sleep(100) $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $Exit Exit ExitLoop EndSelect $objEvent = $colEvents.NextEvent $autorun = $objEvent.TargetInstance.DeviceId & "\autorun.inf" $drive = $objEvent.TargetInstance.DeviceId $i = 0 If $objEvent.TargetInstance.DriveType = 2 Then Select Case $objEvent.Path_.Class()="__InstanceCreationEvent" $UsedToBe = 0 If Not FileExists($autorun) And $UsedToBe = 0 Then TrayTip("Pen Security", $autorun & " not present ! ;)", 2, 1) EndIf Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR) PlaySound() For $I = 1 To 3 If FileExists($autorun) Then $UsedToBe = 1 FileSetAttrib($autorun, '-SHR-A') FileDelete($autorun) Sleep(500) Else ExitLoop EndIf Next If Not FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $autorun & " deleted ! ;)", 2, 1) EndIf If FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $drive & "\AUTORUN.INF NOT DELETED !" & @CRLF & "Pen-Drive Probably Write-Protected.", 5, 1) EndIf Case $objEvent.Path_.Class()="__InstanceDeletionEvent" Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR) ExitLoop EndSelect EndIf Wend Link to comment Share on other sites More sharing options...
JohnOne Posted November 16, 2009 Share Posted November 16, 2009 (edited) Are you saying it dosent exit ? because thats what it looks like it would do Anyhow, have a look at continuecase, or possibly continueloop Edited November 16, 2009 by JohnOne AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
pintas Posted November 16, 2009 Author Share Posted November 16, 2009 Are you saying it dosent exit ? because thats what it looks like it would doAnyhow, have a look at continuecase, or possibly continueloopThanks JohnOne, i'll take a look at it.With or without the for statement the script simply doesn't work. Link to comment Share on other sites More sharing options...
Kip Posted November 16, 2009 Share Posted November 16, 2009 I meant the for statement. As you can see i just removed the Next in the end of this example, and still there is no way i can get it working. Do i need to have two different files running side by side to have the same effect? Btw... I got an eye on X programming expandcollapse popup#Include <Constants.au3> $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 5 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Opt("TrayMenuMode", 1) $Pen = "Program" $Exit = TrayCreateItem("Exit") TraySetState() While 1 Sleep(100) $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $Exit Exit ExitLoop EndSelect $objEvent = $colEvents.NextEvent $autorun = $objEvent.TargetInstance.DeviceId & "\autorun.inf" $drive = $objEvent.TargetInstance.DeviceId $i = 0 If $objEvent.TargetInstance.DriveType = 2 Then Select Case $objEvent.Path_.Class()="__InstanceCreationEvent" $UsedToBe = 0 If Not FileExists($autorun) And $UsedToBe = 0 Then TrayTip("Pen Security", $autorun & " not present ! ;)", 2, 1) EndIf Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been added." & @CR) PlaySound() For $I = 1 To 3 If FileExists($autorun) Then $UsedToBe = 1 FileSetAttrib($autorun, '-SHR-A') FileDelete($autorun) Sleep(500) Else ExitLoop EndIf Next If Not FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $autorun & " deleted ! ;)", 2, 1) EndIf If FileExists($autorun) And $UsedToBe = 1 Then TrayTip("Pen Security", $drive & "\AUTORUN.INF NOT DELETED !" & @CRLF & "Pen-Drive Probably Write-Protected.", 5, 1) EndIf Case $objEvent.Path_.Class()="__InstanceDeletionEvent" Consolewrite("Drive " & $objEvent.TargetInstance.DeviceId & "has been removed."& @CR) ExitLoop EndSelect EndIf Wend Does the example you post here work? MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now