Jump to content
LaunchBox Community Forums

AHK Script - Additional Apps Requiring Elevated Permissions


Recommended Posts

EDIT: Seemingly solved. Solution was to specify pathway to run pnputil.exe to it's install location in "C:\Windows\WinSxS\amd64_microsoft-windows-pnputil_31bf3856ad364e35_10.0.22621.2506_none_dd3e282938270e6f\pnputil.exe". Depending on update, the random string of letters might change, I found it by opening the WinSxS file and searching for "pnputil" to find the correct folder, and then copying the EXE within's path.

 

TLDR; I have a .bat file that must be ran as administrator. How do I do so from the running script of an emulator in Launchbox?

 

Hello,

I'm hoping somebody can help me out with an issue I'm having getting my cab working properly.

The cabinet is running a standard windows computer that is configured to launch into Bigbox as shell. I have 4 zero-delay arcade controllers connected as the primary controllers. To compensate for the controllers activating in random order, I tick "enable all controllers" in Bigbox so all 4 work to control the UI.

I additionally run the software vJoy and Lichtknarre for handling Wii Motes connected via Bluetooth as light guns for light gun games. vJoy creates virtual joysticks as HID devices, while Lichtknarre runs as an elevated .exe and translates the wii motes to vJoy.

I've run into compatibility issues with Lichtknarre and some emulators, so I want that opened and closed alongside light gun games specifically. I'm assuming due to it being an elevated .exe, I couldn't get it to launch from the running AHK, but I found I could run it with the game as an additional application, and I could run a .bat from the running AHK and it would close Lichtknarre correctly. I've got this working completely fine.

When I close a light gun game, vJoy usually winds up stuck pointing in whatever direction it last detected, and makes the bigbox interface impossible to navigate. I've created .bat files that enable and disable the HID device using pnputil, which work fine if I run them myself elevated as administrator. The enable .bat works fine as an additional app to the emulator, but I can't get the disable .bat to run from the running AHK script. I've tried 'run example.bat', 'run *runas example.bat', I've tried creating a shortcut for the bat that is ticked to always run as admin and having the running script launch that (run example.bat - shortcut.lnk OR run *runas example.bat - shortcut.lnk), but I've been unable to get the script to properly run the .bat such that it disables the vJoy HID device.

I'm assuming I'm doing something wrong and it's not running the bat as administrator, or failing to launch at all when I use the shortcut that is set to always run as administrator.

How do I properly elevate the running script so that it launches the bat files as administrator?

Edited by silver30001
Link to comment
Share on other sites

HI @silver30001

I do something similar for Wiimotes, but with Touchmote, Demulshooter and MameHooker which can require elevated launching, plus using pnputil to enable and disable devices - but I use ahks rather than bat files as I find them easier to work with.

I am happy to try to help and give advice and work through it with you, but it might take a few goes.

Do you have AHK downloaded and installed or do you just use the one with LaunchBox?

I'm guessing you do something like this

1) Enable devices

2) Launch Lichtknarre

3) Game launches and you play for a bit

4) Press Exit button/Game closes

5) Disable devices

6) Close Lichtknarre

If I have the correct idea could you upload your bat files that work standalone and I will have a look and see if I can help.

Cheers

 

Link to comment
Share on other sites

Posted (edited)

Hello @Kiinkyfoxx

For context, I'm currently configuring light gun games for the TeknoParrot platform.

I've only been using the AHK that comes with LaunchBox, but if I can resolve this by installing it in full I'm completely open to doing so.

I've created a second Emulator in Launchbox's list that is identical to my normal one, but with the following running script added:

Spoiler

$1Joy12::
{
    Run, C:\...\KillLichtknarre.bat
}

My KillLichtknarre.bat has the following:

Spoiler

taskkill /f /im Lichtknarre.exe

pnputil /disable-device "vJoy Driver ID"

The above .bat works fine if I right click the file and run as administrator, but not if Launchbox attempts to run it. I've tried making a shortcut for the .bat that's ticked to always run as administrator, but that also doesn't seem to work.

Within a Game's metadata is the Additional Apps tab, and I have Lichtknarre.exe and the following .bat ticked to start before main application.

Spoiler

pnputil /enable-device "vJoy Driver ID"

The Additional Apps seem to launch both Lichktnarre and enable vJoy just fine, it's mainly closing the app I'm having issues with.

Edited by silver30001
Link to comment
Share on other sites

3 hours ago, silver30001 said:

$1Joy12::
{
    Run, C:\...\KillLichtknarre.bat
}

Have you removed stuff from that pathway, or is that really the full pathway?

You could try replacing the above with

Spoiler
$1Joy12::
{
Run *Runas "taskkill" /IM "Lichtknarre.exe" /F,,hide ;This runs taskkill as admin and hidden

WinWaitClose, ahk_exe Lichtknarre.exe

Sleep, 500

Run *Runas "pnputil" /disable-device "vJoy Driver ID",C:\WINDOWS\system32,hide ;this run puputil as admin and hidden

WinWaitClose, ahk_exe PnPUtil.exe

SoundBeep, 2000, 2000 ; This is just to make a beep at the end to check if running you can remove the whole line if works
}

ExitApp

 

 

Edited by Kiinkyfoxx
Link to comment
Share on other sites

Modified pathway to obscure identifying information. Didn't realize it was in there until I reviewed the posting and rush removed it lol

The taskill for Lichtknarre appears to be working, but I'm getting an error on the pnputil line for disabling the driver:

Spoiler

Error: Failed attempt to launch program or document:
Action: <pnputil>
Verb: <Runas>
Params: </disable-device "ROOT\HIDCLASS\0001>

Specifically: The system cannot find the file specified

Line#
002: Return
003: {
004: Run, *Runas "taskkill" /IM "Lichtknarre.exe /F,,hide
006: WinWaitClose,ahk_exe Lichtknarre.exe
008: Sleep,500
--> 010: Run,*Runas "pnputil" /disable-device "ROOT\HIDCLASS\0001",C:\\WINDOWS\system32,hide
012: WinWaitClose,ahk_exe PnPUtil.exe
014: SoundBeep,2000,2000
015: }
017: ExitApp
018: Exit
019: Exit
019: Exit

The current thread will Exit

Not exactly sure what's happening here, as the same pnputil command in a .bat file works fine when ran as admin.

Link to comment
Share on other sites

Alright, the only thing I've learned from this is that Windows utilities are weird.

In the batch file, I wasn't specifying a pathway, when you run the batch as administrator, it gets access to a bunch of utilities that you don't get otherwise, even if you elevate the command within the file. This is why it had to be opened as administrator, I think.

There is 100% a "pnputil.exe" located in C:\Windows\System32. This is not the actual application apparently, according to a random broadcom forum thread I found, it's a virtual link to the actual install location, and scripts have issues working properly when attempting to use it.

I set the pathway to "C:\Windows\WinSxS\amd64_microsoft-windows-pnputil_31bf3856ad364e35_10.0.22621.2506_none_dd3e282938270e6f\pnputil.exe" in the AHK Running script, and it is now working as expected.

Thanks for your help @Kiinkyfoxx!

Link to comment
Share on other sites

oh in that case you could call to the command prompt in AHK with comspec variable (path to the command prompt) this way you can use the command prompt way of calling to Windows utilities. this way Windows still knows it's correct location despite just using "pnputil" to call to it.

for ex, little test output for proof of concept

Run, %comspec% /c pnputil > textout.txt

or for elevated Admin privileges, note if you try this one as it will output to \Windows\system32 folder (I thought, why isn't the file showing up on the desktop for a sec when I tested it lol)

Run, *RunAs %comspec% /c pnputil > textout.txt

 

I know it is resolved, just wanted to point out you can make use of the command prompt through AHK to make that a little more straight forward, especially if you're more familiar with batch files

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...