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,356
Trophies
2
XP
2,638
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 @ BakerMan:
    this is my first aurora tbh
    +1
  • BakerMan @ BakerMan:
    i mean, multiple have happened in my lifetime, but it's always been too cloudy
  • BakerMan @ BakerMan:
    IT'S LIKE THAT ALMOST EVERY FUCKING METEOR SHOWER TOO
  • BigOnYa @ BigOnYa:
    You need to setup a time lapse camera, be neat
  • BigOnYa @ BigOnYa:
    I actually use a pic of it on my pc desktop cause its cool looking
  • Xdqwerty @ Xdqwerty:
    Apparently the pro versión of pizza boy is back aswell
  • Xdqwerty @ Xdqwerty:
    Gonna download the update
  • Xdqwerty @ Xdqwerty:
    Only 2 antiviruses detected the APK as a virus on virustotal so it Must be safe
  • Xdqwerty @ Xdqwerty:
    Cuz false positive
  • Xdqwerty @ Xdqwerty:
    Wait
  • Xdqwerty @ Xdqwerty:
    Eh nvm
  • BakerMan @ BakerMan:
    sadly, the clouds are setting in now

    hey BigOnYa the clouds are coming from the south, maybe check again
  • Xdqwerty @ Xdqwerty:
    Good night it's 11 pm
  • BakerMan @ BakerMan:
    night
  • BigOnYa @ BigOnYa:
    @BakerMan Nuh I'm in for the night playing Fallout 4, ill look tomorrow night
  • BigOnYa @ BigOnYa:
    Ok had let dog out, and yea still can't see it, oh well. Maybe tom night.
  • K3Nv2 @ K3Nv2:
    Ballocks these drives aren't allowing raid
  • BigOnYa @ BigOnYa:
    That sucks, well you will get double the space then atleast.
  • K3Nv2 @ K3Nv2:
    @Sicklyboy needs to come back
  • BigOnYa @ BigOnYa:
    Did you try Raid 10?
  • K3Nv2 @ K3Nv2:
    I did raid69
  • K3Nv2 @ K3Nv2:
    The physical disk keeps disabling in bios
  • BakerMan @ BakerMan:
    hey ken did you see the aurora tonight?
  • BakerMan @ BakerMan:
    also sorry it was too cloudy, that sucks
    BakerMan @ BakerMan: also sorry it was too cloudy, that sucks