Click here to Skip to main content
14,486,686 members
Rate this:
Please Sign up or sign in to vote.
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

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 4 days ago
v6
Comments
gggustafson 4 days ago
   
Have you tried verbatum identifiers? See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim
CyberSecII 4 days ago
   
Can you show me an examble?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
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
};
   
Comments
CyberSecII 4 days ago
   
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 4 days ago
   
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 4 days ago
   
Thank you for taking the time to help me!! You helped me very much to understand how I can fix my error!!
phil.o 4 days ago
   
You're welcome.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100