Launch .exe file when USB device is plugged in (specifically a controller)

  • Thread starter Thread starter Giodude
  • Start date Start date
  • Views Views 3,221
  • Replies Replies 7

Giodude

GBAtemp's official rock
Member
Joined
May 17, 2015
Messages
5,094
Reaction score
1,849
Trophies
2
Age
26
Location
New York
XP
2,812
Country
United States
Im using the switch pro controller drivers with my pc so i cant use my pro controller with certain xinput only programs. Only small issue is,i have to boot up a program every time i plug in the controller. Is there a way for windows to boot up a program right when it detects a specific device is connected? Not too big of a deal, but would streamline things immensely.
 
I saw your post and I wanted to check if what you wanted could be made with an AutoIt script... and it turns out yes, indeed it can! :D
Here's a little script for ya:

Code:
$sDeviceName="PLAYSTATION(R)3 Controller"
$sExe="notepad.exe"

Func CheckDeviceName($sName)
   Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

   $vObjQuery = $vObjWMI.ExecQuery("SELECT * FROM Win32_PnPEntity")
   If IsObj($vObjQuery) Then
       For $vObjItem In $vObjQuery
           If $vObjItem.Name==$sName Then
               Return 1
           EndIf
       Next
   EndIf
   Return 0
EndFunc

While 1
   If CheckDeviceName($sDeviceName)==1 Then
       ShellExecute($sExe)
       Do
           Sleep(100)
       Until CheckDeviceName($sDeviceName)==0
   EndIf
   Sleep(100)
WEnd

Just replace the device name in $sDeviceName to whatever you want (I tested it with my PS3 controller) and $sExe to the executable you want to run when your device is plugged in, then run (or compile) the code in AutoIt!
 
Check out USBDeview from Nirsoft, it's free and allows you to do exactly what you want. B-)
usbdeview is cool but how can make it run the program when that specific device is plugged?
i only found the option that does it if ANY usb device is plugged or unplugged
 
usbdeview is cool but how can make it run the program when that specific device is plugged?
i only found the option that does it if ANY usb device is plugged or unplugged

Interesting, doesn't sound like there's any way of doing this without doing at least a little scripting.

USBDeview has multiple variables you can send when a device is plugged in. You can make a really simple batch file, and check whether %product_name% = "Switch Pro Controller" (or whatever name it shows up as from USBDeview).

Your batch file may look like this:

Code:
@echo off
IF "%~1"=="Switch Pro Controller" GOTO launchprog
GOTO end
:launchprog
start "" "C:\myprog.exe"
:end

And then in USBDeview the command you'd execute would be something like C:\myscript.bat %product_name%
 

Site & Scene News

Popular threads in this forum