Wie kann ich meine exe ausführen Via Powershell?

Hallo, ich habe ein Programm geschrieben, was Dateien in andere Formate formatieren kann. Jetzt würde ich es gerne mit Powershell starten, aber es passiert einfach nichts. wenn ich aber die Exe ausführe funktioniert alles.
Diesen Pfad benutze ich:
$executablePath = ‘D:\test6\ConvertMenu.exe’

# Starte das C#-Projekt

Start-Process -FilePath $executablePath -Wait

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
8 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Erzesel
1 year ago

Since Powershell does not generate an error message in your case, your program seems to be started at least successfully (to stop yourself without any message)

If you run your program via “Start-Process”, this happens in another window. If the program does not itself have mechanisms to keep the relevant window open, it may snap so quickly that you do not get any (error) messages to face!

Start process is used only if the result of the program execution should not have any influence on the calling script. (apart from -Wait)

Should the called program operate its issues within the console of the running script, use the & call operator or .-dotsourcing .

Demo.ps1

$Code = @'
using System;
class TestProg{
    public static void Main(string[] args){
        Console.WriteLine("Hallo Welt");
        Console.WriteLine("...beliebige Taste zum Beenden");
        Console.ReadKey(); //Fenster offen halten
    }
}
'@


$ProgramPath=".\Hallo Welt.exe"
 #unser kleines Beispielprogramm Quick&Dirty compilieren (funktioniert nicht  mit Powershell 6 und  höher!)
Add-Type -typeDefinition $Code  -OutputType ConsoleApplication -OutputAssembly "Hallo Welt.exe" 


#Aufrufen von (nichtsystem)-Programmen in Powershell
 #parallel/entkoppelt zum aufrufenden Powershell-Prozess (eigenes Fenster,Environment, etc.)
Start-Process -FilePath $ProgramPath -wait


 #innerhalb von Powershell in einem untergeordneten (wirkungs)Bereich (childscope)
& $ProgramPath


 #innerhalb von Powershell im aktuellen Scope
. $ProgramPath
pause

…who needs VisualStudio to compile C#? 😅


naaman
1 year ago

As much as I know, the Powershell does not execute .EXE files. The Powershell is not meant for that. .EXE files are running only and do not require any surface from which they must be started.

On the other hand, .BAT files can be executed in a powershell, e.g. the autoexec.asked

Your xyz.exe file should therefore be a xyz.bat file. It is not enough to simply rename a file to xyz.bat.

Erzesel
1 year ago
Reply to  naaman

Where did you get that bullshit?

With Powershell you can start/execute pretty much everything:

From Windows 11 22H2 the fileassociation was removed to .bat. Windows batch files have (for 30 years) the ending .cmd

..and autoexec.bat died no later than Windows98

naaman
1 year ago
Reply to  Erzesel

Windows batch files have (for 30 years) the ending.cmd

Unauthorised

cmd is only the call of the command line

Is called via Windowskey+R.

If you have no idea, you should leave it to write Unfug.

Erzesel
1 year ago

There’s someone hanging out of the window.

Look at my “playground”:

In Batch and Powershell, you should certainly not try to measure with me!

Xandros0506
1 year ago
&  "D:\test6\ConvertMenu.exe"

is usually sufficient. If your program does not start over it, check the event display, which is logged there.

Erzesel
1 year ago
Reply to  DANIELdjldqwj

If Powershell does not provide an error message when calling via &-Calloperator /.-dotSourcing, it must be obvious.

Perhaps your program will only end without any message from itself.