Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add this command
cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" "C:\Users\admin\Desktop\Install.exe""
on a proccess.start like this

C#
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
   FileName = "cmd",
   Arguments = "/k cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" "C:\Users\admin\Desktop\Install.exe"", 
   WindowStyle = ProcessWindowStyle.Hidden,
   UseShellExecute = true,
   ErrorDialog = false
};



but I get errors from the double slashes please help.

What I have tried:

I have tried to split the command into pieces like this "++" but it doesn't work.
Posted
Updated 26-Mar-20 12:27pm
v6
Comments
gggustafson 26-Mar-20 17:18pm    
Have you tried verbatum identifiers? See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim
CyberSecII 26-Mar-20 17:57pm    
Can you show me an examble?

1 solution

You only need to enclose paths between double quotes when there is a space somewhere in the path; which is not the case here. Moreover, if you want a double quote to appear in the string, you have to escape it with a backslash \. Conversely, if you want a backslash to appear in the string, you have to escape it also, which leads to a double backslash \\.
All of this put together:
C#
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
   FileName = "cmd",
   Arguments = "/k cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start C:\\Users\\admin\\Desktop\\Install.exe\"",
   WindowStyle = ProcessWindowStyle.Hidden,
   UseShellExecute = true,
   ErrorDialog = false
};
 
Share this answer
 
Comments
CyberSecII 26-Mar-20 18:33pm    
the command must stay like it was because if you remove the double splashes then the command becomes useless it doesn't do the job. all double splashes most stay there, is there any other way to do that without editing the command itself?
cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" "C:\Users\admin\Desktop\Install.exe""
phil.o 26-Mar-20 18:40pm    
If they must absolutely be here then do as I told you: escape them.
Arguments = "/k cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"C:\\Users\\admin\\Desktop\\Install.exe\"\""
CyberSecII 26-Mar-20 18:56pm    
Thank you for taking the time to help me!! You helped me very much to understand how I can fix my error!!
phil.o 26-Mar-20 19:00pm    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900