0

I have a program I wrote in , which works as I want in , but not in . The thing is that because the program is intended for casual people, I don't want to give them instructions about how to reach the executable using cd, ls etc…

Is there any way to make Windows run the program in Windows PowerShell, when clicking my .exe, instead of in Command Prompt?

I will post code if necessary

Compo
  • 36,585
  • 5
  • 27
  • 39
Zenix
  • 1
  • 1
  • When a .exe file is run, the operating system loads it into memory. It does not matter if cmd.exe or powershell.exe is being used. What do you mean by "...tried the program on PowerShell..."? – lit Jan 25 '21 at 15:48
  • When I click on my program .exe it opens a Command Line and it works as intended but with degraded perfomance because I use a lot of system("CLS"), system("COLOR XX"), Sleep() in the range of 25ms and 100ms and a lot of printf. Frustrated because of the bad perfomance I came with the idea of testing it in PowerShell, so I opened it, went to the program folder and typed in the ".\nameofprogram.exe" command that makes it start, and to my surprise it worked flawlessly. What I want is that when my .exe is clicked, it is opened in PowerShell instead of CMD – Zenix Jan 25 '21 at 16:45
  • `Is there any way to make Windows run the program in Windows PowerShell`. [***Nope***.] PowerShell only runs `*.ps*` in the PowerShell consolehost. Any executable is run by cmd.exe. See these MS articles: [PowerShell: Running Executables](https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx) [about_Command_Precedence](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-7) – postanote Jan 25 '21 at 20:29

2 Answers2

0

I am not really a windows user, but here is my suggestions:

  1. You can write a little .bat script to open your application in powershell, for example: How to run a PowerShell script from a batch file
BarFoo
  • 1
  • 3
  • Unfortunately that didn't work. Anyway thank you so much for the response :D – Zenix Jan 25 '21 at 15:47
  • Ah, too bad... May I ask, are you using a lot of std::endl; in your code? Perhaps you could try to replace them with "\n" where suitable? Maybe it runs better in CMD then? std::endl is pretty expensive, as it is a return character + a flush. – BarFoo Jan 25 '21 at 15:54
  • No, what is affecting the performance are the system("COLOR XX") functions mixed with very big fonts (it seems CMD can't keep up but PowerShell does) . I havent used std::endl yet – Zenix Jan 25 '21 at 16:38
  • I see, perhaps you could consider not using a terminal emulator to do what you want to do? Perhaps you could use a new window with an OpenGL context to draw what you need? – BarFoo Jan 25 '21 at 17:25
0

If you want to run the .exe program with PowerShell loading it, use the command:

powershell -NoLogo -NoProfile -Command "& C:\path\to\theapp.exe"

This can be placed into a .bat file script if needed.

lit
  • 14,456
  • 10
  • 65
  • 119