OK, let me ask another way

A lot of good answers occur when you ask the right questions.

I am attempting to write a script to run from my Streamdeck or TouchPortal app, which will facilitate a “one button” startup of all software used for MSFS. Similarly, I am attempting the associated “shutdown” script.

I have essentially accomplished that goal but for one difficulty → I can’t seem to end a process/task without getting that annoying admin yes/no popup. I’ve been researching this for days and have found no way around clicking that “Yes” button by hand. Elevating to admin doesn’t work and I’d rather not need to install yet another library for a single function call.

I only want to taskkill tasks/processes/apps that I started to begin with. Windows disallowing this doesn’t make sense to me. A task/process/app that I can run could be just as harmful as a task/process/app I could kill.

Perhaps I’m simply doing it wrong. :face_with_spiral_eyes:

It is difficult to believe that you guys with the fabulous sim cockpits didn’t run into something like this. What am I doing wrong?

As usual, thanks ahead of time for any and all feedback.

Try either of these PowerShell commands, tested with a copy of Notepad that has some text entered, and not saved.

Get-Process -Name Notepad | Stop-Process -Force
Stop-Process -Name Notepad -Force

You could also script this to make it automated. Essentially the script would launch everything, then watch for one process to exist, and when it fails to exist, it closes down everything else.

For example, it would launch MSFS, then watch every few seconds for the existence of FlightSimulator.exe, and if it finds that process it does nothing. As soon as that disappears, then it stops all the other processes it launched.

It is often risky to “ungracefully” shut down an application, as it doesn’t give it a chance to run pre-shutdown tasks if applicable, like saving state, etc. Stopping “FlightSimulator.exe” will probably result in an error message when you start it up again, as if you got a CTD.

That said, the PowerShell commands posted above will work.

Yeah, I would shut MSFS down manually then let the script take care of the rest.

A very simple would be like the following:

Do {
      Write-Host "Notepad exists"
      Sleep 1
}
While (get-process -Name Notepad)

As soon as Notepad no longer exists the loop ends, and would then run a series of “Stop-Process” commands.

So to flesh it out with some actual examples:

Start-Process "C:\Windows\Notepad.exe"
Start-Process "C:\Program Files\Windows NT\Accessories\wordpad.exe"
Do {
    Sleep 1
}
While (get-process -Name Notepad -ErrorAction SilentlyContinue)
Stop-Process -Name wordpad -Force

My bad, guys.

I do not shut down MSFS in code. I use features of Streamdeck/TouchPortal to manipulate key and mouse presses. This works for me.

It’s basically the PC to tablet interface software that I need to batch automate.

Thanks for the replies, guys

1 Like

Why not have the buttons execute a script?

Thanks for your reply. :slight_smile:

I have buttons executing the script, as I described in the original post above.

The problem is shutting down the apps without the need to click that admin popup.

Streamdeck has several addons that allow killing tasks but none will work without the popup. I’ve read many posts on Stackoverflow and others talking about elevating to admin, etcetera. They all work except for the need to click on that admin popup.

Let me take a look at the examples you posted - and THANKS for your kind responses.

1 Like

The -Force switch should stop any pop-ups from appearing. In my example. enter some text in to both applications but do not save that text, then just close Notepad manually, as if you were closing MSFS. You should see wordpad disappears, losing the unsaved data, and not prompting you.

The key in your code, for me, is

Stop-Process -Name wordpad -Force

In my shutdown.bat file I have

powershell Stop-Process -Name TrackIR5 -Force

This does indeed kill these tasks, just as all the other methods did. Unfortunately, this code still forces me to click that admin popup when I try to taskkill some programs I started.

This popup is my only issue. Everything else is working.

1 Like

Which program is forcing you to elevate to close it? If it’s something you started non elevated then it doesn’t make much sense.

It depends on what you mean by “taskkill”. Some windows functions require elevation, and for those it will generate a UAC prompt.

For example, open a regular Command Prompt, and run this:

compmgmt.msc

You should see a UAC prompt. If you don’t, worry! :wink:

Now open an elevated command prompt, and try “compmgmt.msc” again. You won’t get the prompt now as the child process inherits from the parent.

Whatever you are using you would either have to run everything from an environment already running elevated, or change the method you are using “taskkill” from, whatever that might be.

It would also be worth knowing exactly what programs you are trying to kill that generate the pop-up.

I’m not sure I can explain much better. I’ll start from scratch.

I have a startup.bat that launches my apps AND MSFS (using the developer’s startup),

start “” “C:\Program Files (x86)\NaturalPoint\TrackIR5\TrackIR5.exe”
start “” “App.2”
start “” “App.3”
start “” “C:\MSFS SDK\Tools\bin\fsdevmodelauncher.exe”

The batch file is called from either my Streamdeck or TouchPortal. This all works perfectly.

Another button (on either Streamdeck or TouchPortal) calls my shutdown.bat file. This file contains,

taskkill /F /IM “TrackIR5.exe”
taskkill /F /IM “App.2”
taskkill /F /IM “App.3”

MSFS is already shutdown via another script before running this script.

When I run the shutdown.bat script, it doesn’t work. If I run it as admin, it works but always prompts with the UAC. I have tried everything and I can not bypass the UAC.

Anyways, thanks for your input!

I would stop using “taskkill” in that case, as that may be were the issue is.

I tried this out with Notepad. Entered some text, and entered this:

taskkill /F /IM notepad.exe
SUCCESS: Sent termination signal to the process "notepad.exe" with PID 25432.

Sorry, I missed the “/F” in my test, so that did close Notepad down as expected, but obviously no UAC prompts.

Either taskkill is somehow generating those, or the application being closed down is.

Try commenting out all the “taskkill” commands except one, and see which one is causing it by working down the list with each one in isolation.

I tried your example and I verify that notepad dies without the prompt.

If I use, in a normal command window

powershell Stop-Process -Name TrackIR5 -Force

I get

Stop-Process : Cannot stop process “TrackIR5 (768)” because of the following
error: Access is denied
At line:1 char:1

  • Stop-Process -Name TrackIR5 -Force
  •   + CategoryInfo          : CloseError: (System.Diagnostics.Process (TrackIR
     5):Process) [Stop-Process], ProcessCommandException
      + FullyQualifiedErrorId : CouldNotStopProcess,Microsoft.PowerShell.Command
     s.StopProcessCommand
    

If I run the same command in an elevated command window, it works with no prompt.

Two apps being killed in my script cause the popup, TrackIR5 and another, so I have been focusing on TrackIR5. I am now running/killing only TrackIR5 from my scripts. Both startup and shutdown scripts run from Streamdeck buttons.

When running a normal batch file called by a Streamdeck button, nothing happens. If I run the batch file from a Streamdeck as admin button, it always prompts. Same with TouchPortal.

Remember, I’m starting/killing a single app now, TrackIR5.

So it looks like Track IR is requesting elevation just to shut down. I can’t say I’ve ever heard of that.

There are some tricks you can do to make this work, assuming we can’t persuade Track IR to not request elevation on shutdown.

One is have your script be the action for a scheduled task. Scheduled tasks can be made to run elevated, with no UAC prompts.

So instead of calling your script, you run the scheduled task which in turns runs your script. Takes a couple of minutes to set up.

I’m on my phone right now, but later I can show you some examples.

I would appreciate any help. You have been too kind already. :slight_smile: :slight_smile:

I believe I have tried what you are suggesting but I will await your examples.

Note: I have found a way to do this on the Streamdeck only but not in TouchPortal. The Advanced Launcher plugin from BarRaider has a processKiller that kills stuff without prompting. So far, I have seen no equivalent in TouchPortal.

1 Like

No worries.

So first we create our task. I’ve hidden mine in an “MSFS” folder I created.

image

On the General tab, give it a name, and enable “Run with highest privileges”.

image

Then go to the Actions tab, and add the batch file, wherever it might be:

That’s pretty much it for configuring it. You can try it immediately by right-clicking on its name, and running it:

image

To run this scheduled task from another script, command line, or wherever, you would run this:

schtasks /Run /TN "MSFS\MSFS_addon_shutdown"

To confirm elevation is working correctly, I altered the script to instead run Notepad.

start notepad

And then attempted to edit this file:

C:\Windows\system32\drivers\etc\hosts

You can’t write to this file, by default, without elevating the editor, and it works as expected. If Notepad was not running elevated, when I attempted to “Save” it would do a “Save As…” instead, and prompt for a new file name.

Note that this can be very dangerous in the wrong hands, as you now have a script that itself could be freely edited, and anything you put in it will be running as an elevated task, so could be used for destructive purposes as well as constructive!

Thanks for that. Yeah, that is very dangerous stuff.

For now, I have this all working on Streamdeck using a plugin as described, and where that doesn’t work, calling a script which does. The two apps giving the prompt are killed with the BarRaider plugin described above. The other apps don’t require admin to be killed and of course, MSFS is closed with automated keyboard keys and mouse clicks. As long as the Streamdeck version works, I can live with it not working on TouchPortal.

Thanks for your help. Certainly, above and beyond. :slight_smile:

1 Like

Just a followup here…

I’ve changed some environmental stuff like running the sim in a user account. This only appears to change which apps I can start and kill. It’s just weird. Gotta’ love MS Windows.

I tried your task example above. Unfortunately, my particular Windows 10 OS doesn’t present me with those choices, at least not as a non-admin user. There are several stark differences that I won’t list here but most notably, there was no option to run as admin. OTOH, it appears that I could customize the generated command line, but I suspect it wouldn’t suppress the popup.

One other thing is that this method in the example only allows running the batch file when logging in which would be useless in a batch file used to kill tasks. Better would be the ability to run whenever. There was a “trigger on event” choice in the task scheduler but I couldn’t figure out what to put in those fields.

So, I’ve been having fun exploring all kinds of combinations of apps and plugins and stuff, from both admin and user perspectives.

Anyways, thanks again for your help.

1 Like

Sounds like you might have a “Home” edition, as that does have big differences, like not being able to join a domain.