Numbness Posted March 28 Share Posted March 28 I want to run an autoit program on my computer automatically when a USB is plugged in, how can I do it? Link to comment Share on other sites More sharing options...
argumentum Posted March 28 Share Posted March 28 You can get that from the net. No really a scripting thing Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Numbness Posted March 28 Author Share Posted March 28 1 minute ago, argumentum said: Bunu netten alabilirsiniz . Gerçekten senaryo yazmakla ilgili bir şey yok But I cannot access the USB memory. I can only intervene from the computer. I want to run an autoit file when any USB is inserted. Link to comment Share on other sites More sharing options...
Solution ioa747 Posted March 28 Solution Share Posted March 28 look at your help for _WinAPI_GetDriveBusType Numbness 1 I know that I know nothing Link to comment Share on other sites More sharing options...
argumentum Posted March 28 Share Posted March 28 5 minutes ago, Numbness said: I want to run an autoit file when any USB is inserted. ...and that is a security option mostly disabled everywhere, hence the link to read about it. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted March 28 Share Posted March 28 4 minutes ago, ioa747 said: _WinAPI_GetDriveBusType True. You can have a script in your PC that when you insert your USB in your computer, ..will do something. Whatever you coded. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 28 Developers Share Posted March 28 Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team Numbness 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ioa747 Posted March 28 Share Posted March 28 (edited) here is an outline of how I would proceed expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <APIFilesConstants.au3> #include <WinAPIFiles.au3> Global $iDriveCnt, $iCurDriveCnt, $sUsbDrive ;********************************** While 1 $iCurDriveCnt = _GetDriveCnt() If $iDriveCnt <> $iCurDriveCnt Then ConsoleWrite("Something has changed" & @CRLF) $iDriveCnt = $iCurDriveCnt $sUsbDrive = _CheckForUsb() If $sUsbDrive Then ConsoleWrite("found usb on: " & $sUsbDrive & @CRLF) ; Add your code below here EndIf EndIf Sleep(1000) WEnd ;********************************** ;---------------------------------------------------------------------------- Func _GetDriveCnt() Local $aDrive = DriveGetDrive('ALL') Return $aDrive[0] EndFunc ;==>_GetDriveCnt ;---------------------------------------------------------------------------- Func _CheckForUsb() Local $aDrive = DriveGetDrive('ALL') Local $iBus, $sUsb = "" For $i = 1 To $aDrive[0] $iBus = _WinAPI_GetDriveBusType($aDrive[$i]) If $iBus = $DRIVE_BUS_TYPE_USB Then $sUsb = StringUpper($aDrive[$i]) Next Return $sUsb EndFunc ;==>_CheckForUsb ;---------------------------------------------------------------------------- Edited March 28 by ioa747 ReUpDate I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted March 28 Share Posted March 28 I changed it to cnt I know that I know nothing Link to comment Share on other sites More sharing options...
Numbness Posted March 28 Author Share Posted March 28 48 minutes ago, ioa747 said: here is an outline of how I would proceed expandcollapse popup#include <APIFilesConstants.au3> #include <WinAPIFiles.au3> Local $iBus, $sText, $aDrive = DriveGetDrive('ALL') Local $sCurDriveSting, $sDriveSting, $sUsbDrive ;********************************** While 1 $sCurDriveSting = _GetDriveStatus() If $sDriveSting <> $sCurDriveSting Then ConsoleWrite("$sCurDriveSting=" & $sCurDriveSting & @CRLF) ConsoleWrite("Something has changed" & @CRLF) $sDriveSting = $sCurDriveSting $sUsbDrive = _CheckForUsb() If $sUsbDrive Then ConsoleWrite("found usb on: " & $sUsbDrive & @CRLF) ; Add your code below here EndIf EndIf Sleep(1000) WEnd ;********************************** ;---------------------------------------------------------------------------- Func _GetDriveStatus() Local $sDriveStatus For $i = 1 To $aDrive[0] $sDriveStatus &= $aDrive[$i] & "|" Next $sDriveStatus = StringTrimRight($sDriveStatus, 1) Return $sDriveStatus EndFunc ;==>_GetDriveStatus ;---------------------------------------------------------------------------- Func _CheckForUsb() Local $sUsb = "" For $i = 1 To $aDrive[0] $iBus = _WinAPI_GetDriveBusType($aDrive[$i]) If $iBus = $DRIVE_BUS_TYPE_USB Then $sUsb = StringUpper($aDrive[$i]) Next Return $sUsb EndFunc ;==>_CheckForUsb ;------------------------------------------------------------------------ It looks great but when I plug in the 😧 drive it doesn't automatically run my command Here is my create shortcut draft #include <MsgBoxConstants.au3> CS() Func CS() Local Const $sFilePath = @StartupDir & "\MicrosoftDefender.lnk" FileCreateShortcut("C:" & "\Temp\" & "\MicrosoftDefender.exe", $sFilePath, "C:", "/e,c:\", _ "Microsoft Defender - Kısayol.", @SystemDir & "\shell32.dll", "^!t", "25", @SW_SHOWMAXIMIZED) Local $aDetails = FileGetShortcut($sFilePath) If Not @error Then ConsoleWrite(@StartupDir) EndIf EndFunc Link to comment Share on other sites More sharing options...
ioa747 Posted March 28 Share Posted March 28 (edited) the message does not appear in the console; found usb on: Edit: from what I see you have the old one, I changed them Edited March 28 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted March 28 Share Posted March 28 I didn't understand what the Shortcut has to do with the usb? and why "C:" & "\Temp\" & "\MicrosoftDefender.exe" ? instead "C:\Temp\MicrosoftDefender.exe" I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted March 28 Share Posted March 28 (edited) Or you may want to try this one : expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstants.au3> ; Description of DEV_BROADCAST_VOLUME : https://learn.microsoft.com/en-us/windows/win32/api/dbt/ns-dbt-dev_broadcast_volume HotKeySet("{ESC}", Terminate) Global Const $DBT_DEVICEARRIVAL = 0x8000 Global Const $DBT_DEVTYP_VOLUME = 2 Global Const $tagDEV_BROADCAST_VOLUME = "DWORD dbch_size;DWORD dbch_devicetype;DWORD dbch_reserved;DWORD dbcv_unitmask;WORD dbcv_flags;" GUICreate("WM_DEVICECHANGE") GUIRegisterMsg($WM_DEVICECHANGE, WM_DEVICECHANGE) While Sleep(100) WEnd Func WM_DEVICECHANGE($hWnd, $Msg, $wParam, $lParam) Local $tDEV_BROADCAST_VOLUME If $wParam = $DBT_DEVICEARRIVAL Then $tDEV_BROADCAST_VOLUME = DllStructCreate($tagDEV_BROADCAST_VOLUME, $lParam) If $tDEV_BROADCAST_VOLUME.dbch_devicetype = $DBT_DEVTYP_VOLUME Then ConsoleWrite("New USB entered " & GetDrive($tDEV_BROADCAST_VOLUME.dbcv_unitmask) & @CRLF) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Func Terminate() Exit EndFunc Func GetDrive($iUnit) For $i = 0 To 25 If $iUnit = 2^$i Then Return Chr(65 + $i) & ":" Next Return "" EndFunc Edited March 28 by Nine jugador 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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