1

So I was trying to write a quick Batch file but it only did half the code, so I switched it to PowerShell because I remembered a while back I was able to get it to work and turns out this did work.

My issue is essentially I have a handful of users I want to have access to this "it just closes a program and reopens". They're familiar with Batch files (which I couldn't get to reopen the program) but would not be used to using a PowerShell script and having to right click to run as PowerShell which I'm expecting will cause issues and many of the users to not use the script in the first place.

Is there either something I did wrong on the batch file for it not to reopen or is there a way to change the left click option on the PowerShell(currently left click opens the script in notepad; ideally it would just run as PowerShell on left click)

The code is the same for both PowerShell and CMD copied and pasted directly to.

taskkill /IM ADM.TrayApp.exe /F
Start-Process  "C:\Program Files (x86)\athenahealth, Inc\aNetDeviceManager\3.1.4.0\TrayApp\CoreModule\ADM.TrayApp.EXE"
NAVI
  • 49
  • 7
  • 3
    the batch command `start` should be able to do the same: `start "dummytitle" "C:\blahblah\program.exe` (important to know that `start` handles the first quoted argument as a window title. It can be anything or it can be empty (`""`), but it is required when you use the program path quoted (which you must because of the spaces) – Stephan Jun 01 '23 at 20:03
  • It's a tray application, does that make a difference? – NAVI Jun 01 '23 at 20:38

1 Answers1

0
  • You cannot use PowerShell's Start-Process directly in a batch file - you'd have to call via powershell.exe, the Windows PowerShell CLI or pwsh, the PowerShell (Core) CLI).

  • However, as Stephan points out, cmd.exe's internal start command provides similar functionality, so its use should be sufficient in your case (as Stephan notes, some window title enclosed in "..." is needed as the first argument if the executable to launch is enclosed in "..." too; "" will do):

    start "" "C:\Program Files (x86)\athenahealth, Inc\aNetDeviceManager\3.1.4.0\TrayApp\CoreModule\ADM.TrayApp.EXE"
    
  • It is possible to make PowerShell scripts execute by default when (double-)left-clicked from File Explorer or the desktop, but requires nontrivial setup on each machine:

    • See this answer.
    • The linked answer also describes an alternative technique of providing simple companion batch files whose sole purpose is to execute an associated PowerShell script.
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Yep I see I I was so quick to add the "" I didn't even notice I still had the -process in the Batchfile. That worked. – NAVI Jun 01 '23 at 20:45