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

Giodude

GBAtemp's official rock
OP
Member
Joined
May 17, 2015
Messages
5,094
Trophies
1
Age
23
Location
New York
XP
2,761
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.
 

RattletraPM

Well-Known Member
Member
Joined
Jan 18, 2017
Messages
897
Trophies
1
XP
8,341
Country
Italy
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!
 

migles

All my gbatemp friends are now mods, except for me
Member
Joined
Sep 19, 2013
Messages
8,033
Trophies
0
Location
Earth-chan
XP
5,299
Country
China
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
 

RHOPKINS13

Geek
Member
Joined
Jan 31, 2009
Messages
1,355
Trophies
2
XP
2,629
Country
United States
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

General chit-chat
Help Users
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
    BakerMan @ BakerMan: damn