Launching application via shortcut using Process.Start C #

Is there a way to launch an application through a shortcut from a C # application?

I am trying to run .lnk from my C # application. The shortcut contains a significant number of arguments, which I would prefer that the application not be remembered.

Attempting to launch a shortcut through Process.Start throws an exception.

thanks

EDIT:

The exception is "Win32Exception": "The specified executable is not a valid Win32 application."

Here is the (abbreviated) code:

ProcessStartInfo info = new ProcessStartInfo ( "example.lnk" ); info.CreateNoWindow = true; info.UseShellExecute = false; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.RedirectStandardInput = true; Process whatever = Process.Start( info ); 
+9
source share
5 answers

Setting UseShellExecute = false was the problem. As soon as I deleted it, it stopped crashing.

+5
source

Could you post some code. Something like this should work:

 Process proc = new Process(); proc.StartInfo.FileName = @"c:\myShortcut.lnk"; proc.Start(); 
+14
source

if your file is EXE or another type of file, such as ".exe" or ".mkv" or ".pdf", and you want to run it using a shortcut for which your code should like.

I want to run the program "Translator.exe".

 Process.Start(@"C:\Users\alireza\Desktop\Translator.exe.lnk"); 
0
source

If you use UseShellExecute = false and try to run the batch file, be sure to add .bat at the end of the file name. You do not need .bat if UseShellExecute = true. It made me just spend an hour working ... hoping to save someone else.

0
source

I spent hours trying to figure it out today, and fortunately found the answer on another website, so please be sure to vote for my answer if that helps you. I would appreciate it!

 Imports System Module Module1 Sub Main() RunCMDCom("start", "%userprofile%\desktop\AnyShortCut.lnk", False) End Sub Public Sub RunCMDCom(command As String, arguments As String, permanent As Boolean) Dim p As Process = New Process() Dim pi As ProcessStartInfo = New ProcessStartInfo() pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments pi.FileName = "cmd.exe" p.StartInfo = pi p.Start() End Sub 

End module

-one
source

All Articles