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

Discussion in 'Computer Software and Operating Systems' started by Giodude, Apr 10, 2018.

  1. Giodude
    OP

    Giodude GBAtemp's official rock

    Member
    11
    GBAtemp Patron
    Giodude is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    May 17, 2015
    United States
    New York
    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.
     
  2. Fishaman P

    Fishaman P Speedrunner

    Member
    7
    Jan 2, 2010
    United States
    Wisconsin
    Depends, do you know any programming?
     
  3. TotalInsanity4

    TotalInsanity4 GBAtemp Supreme Overlord

    Member
    20
    Dec 1, 2014
    United States
    Under a rock
    Just add the exe to your "run on startup" folder
     
    Uiaad likes this.
  4. froggestspirit

    froggestspirit D/P/Pt Demix Guy

    Member
    8
    Jul 28, 2011
    United States
    if you got money to burn, you can get a titan one, it will let you use the pro controller on multiple things.
     
  5. RHOPKINS13

    RHOPKINS13 Geek

    Member
    7
    Jan 31, 2009
    United States
    Check out USBDeview from Nirsoft, it's free and allows you to do exactly what you want. B-)
     
    migles likes this.
  6. RattletraPM

    RattletraPM GBATemp's official 蒸気イーブイ

    pip Reporter
    15
    Jan 18, 2017
    Italy
    Shinjuku Station
    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 and TotalInsanity4 like this.
  7. migles

    migles All my gbatemp friends are now mods, except for me

    Member
    14
    GBAtemp Patron
    migles is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    Sep 19, 2013
    China
    Earth-chan
    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
     
  8. RHOPKINS13

    RHOPKINS13 Geek

    Member
    7
    Jan 31, 2009
    United States
    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%
     
Loading...