I have the follwoing c# code:
string cmdInnoSetup = #"""C:\Program Files (x86)\Inno Setup 5\compil32\""" + " /cc " + #"""c:\\SetupScript.iss""";
System.Diagnostics.Process.Start("cmd.exe","/k "+ cmdInnoSetup);
But when I execute it I got the following message:
"Program not found"
But when I remove double quotation from second part sentence "c:\\SetupScript.iss" then the code works fine!
Now how can I solve this illogical problem in order to keep both of paths inside double quotation !
How to let code work by setting double quotation for source and destination as well!
You can try using the string written like this:
"\"C:\\Program Files (x86)\\Inno Setup 5\\compil32\\\"" + " /cc \"c:\\SetupScript.iss\"";
Try this two lines, I tried it and it works:
string cmdInnoSetup = #"""C:\Program Files (x86)\Inno Setup 5\compil32.exe"" /cc 'c:\SetupScript.iss'";
System.Diagnostics.Process.Start("cmd.exe", "/k " + cmdInnoSetup);
You could try calling your program differently. Such as:
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Inno Setup 5\compil32.exe", #"/cc ""c:\SetupScript.iss""");
Unless you really need the cmd to perform the output it should do basically the same.
(I didn't try it with InnoSetup myself but with another program)
Related
I've tried to do my due diligence in searching before I post but I am having trouble with a space in a file path when launching a powershell script in a C# app. I have tried escaping quotes, using # pretty much anywhere, single quotes. What am I missing here?
This is how I am defining the path:
public string importMusicLocation = #"C:\Program Files\Automation Toolbox\Scripts\Music_Import.ps1";
Then I launch a powershell process and point to the path, previously I had this working just fine without spaces when pointing to the path on my Desktop, but now that I want to put the application in Program Files the powershell window only detects the path up to the space.
private void LaunchPshell(string script) {
string strCmdText = Path.Combine(Directory.GetCurrentDirectory(), script);
var process = System.Diagnostics.Process.Start(#"C:\windows\system32\windowspowershell\v1.0\powershell.exe", strCmdText);
process.WaitForExit();
}
Like 5 minutes after I posted this I realized I don't need to be combining a directory, I was going to delete this but I can post the solution in case anyone else needs it. The general syntax for powershell to launch a script is & 'C:\Program Files\Some Path':
public string importMusicLocation = #"& 'C:\Program Files\Automation Toolbox\Scripts\Music_Import.ps1'";
and
private void LaunchPshell(string script) {
var process = System.Diagnostics.Process.Start(#"C:\windows\system32\windowspowershell\v1.0\powershell.exe", script);
process.WaitForExit();
}
Try quoting your path value with double quotes like
string importMusicLocation = #"""C:\Program Files\Automation Toolbox\Scripts\Music_Import.ps1""";
So, PowerShell.exe utility will receive the argument as quoted string and the spacing issue shouldn't arise
"C:\Program Files\Automation Toolbox\Scripts\Music_Import.ps1"
I'm trying to run this command with several quotation marks:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="10.10.10.10:9999" -user-data-dir=C:\filterbypass www.example.com"
I've tried adding backslashes to the before C and after com, no luck
Tried assigning it to a string
string \"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="10.10.10.10:9999" -user-data-dir=C:\filterbypass www.example.com\"
with hopes to run the command like that, but still nothing.
try
{
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server="10.10.10.10:9999" -user-data-dir=C:\filterbypass www.example.com");
}
catch { }
Can anyone show me where I'm going wrong here? Thanks,
You need to separate the binary to run from the arguments. I would recommend using ProcessStartInfo to make this clearer:
var info = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
Arguments = "--proxy-server=10.10.10.10:9999 " +
#"--user-data-dir=C:\filterbypass " +
"www.example.com"
};
var process = Process.Start(info);
(Note the use of -- for the user-data-dir switch, by the way - it looks like all the command line flags are prefixed with --, not -. It's possible that it works both ways...)
I'm trying to run a remote batch file - already located on the remote machine - using PsExec, called via Process in C#. I've confirmed that all required files already exist, but believe I may have a problem with my syntax, as the redirected output indicates that it can't find the file specified.
The machine against which PsExec runs is dynamic, which is the myArray[0].MachineName value (this pulls in without issue).
wsStopProcess.StartInfo.FileName = #"C:\Windows\system32\PsExec.exe";
wsStopProcess.StartInfo.Arguments = #" \\" + myArray[0].MachineName + #"D:\stopprofile.bat";
wsStopProcess.StartInfo.UseShellExecute = false;
wsStopProcess.StartInfo.CreateNoWindow = true;
wsStopProcess.StartInfo.RedirectStandardOutput = true;
wsStopProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
wsStopProcess.Start();
Any ideas on what appears to be formatted incorrectly? I'm guessing it's too many backslashes (or not enough!) somewhere.
I think the main problem is you do not have a space between the two arguments.
Try this:
wsStopProcess.StartInfo.Arguments = #"\\" + myArray[0].MachineName + #" D:\stopprofile.bat";
I would also warn you that I could not get psexec to work 100%, despite trying many different things.
Try this:
wsStopProcess.StartInfo.Arguments = #"\\" + myArray[0].MachineName + #" D$\stopprofile.bat";
So instead of using : try $ sign. Also setting breakpoint on the above line while debugging will help you to see the exact path.
There are MULTIPLE threads here asking how to change an icon - and nearly all of them say to use a command line tool such as ResHacker - but none of them (that I have seen) explain how to do so. I read into ResHacker's help file, and I found some text which explained how to go about changing the icon of a win32 executable file.
I tried the below code, and it gave me the following error:
Code:
p.StartInfo.Arguments = "-addoverwrite " + txtProtect.Text + "," + txtProtect.Text + "," + sICOpath + "," + "ICONGROUP" + ", MAINICON, 0";
Error:
"C:\Users\Evan\Desktop\ResHacker.exe" -addoverwrite C:\Users\Evan\Desktop\output.exe,C:\Users\FARINA_EVAN\Desktop\output.exe,C:\Users\Evan\Desktop\ExeWithIcon.exe,ICONGROUP, MAINICON, 0
Error: Invalid resource type.
I realize that this is a bit... Old, but the reason this won't work is because you're trying to get the icon FROM a .exe, which doesn't work with the command line of ResHacker.
The only thing I can think of is to Extract the icon from the .exe and save it as a .ico.
Then you can do the "push."
I wasn't able to find anything on how to programmatically run ResHacker except through manipulating the command line through C# like you are attempting to do. However, to speak to the root of your question, I found a possible solution for you here that does not require ResHacker. Instead, it allows you to modify the icon through code (C# and VB.NET). Here is the link:
http://www.hackforums.net/archive/index.php/thread-422072-1.html
Given code was a part of the code used to run a jar file on c# environment. Complete Code
strArguments = " -jar "+ Argument list;
processJar.StartInfo.FileName = "\"" + #"java" + "\"";
processJar.StartInfo.Arguments = strArguments;
processJar.StartInfo.WorkingDirectory =; \\Give the working directory of the application;
processJar.StartInfo.UseShellExecute = false;
processJar.StartInfo.RedirectStandardOutput = true;
I know that processJar.StartInfo.FileName should contain the jave.exe so that the respective file will be triggered when the process gets started. But the above given code also runs successfully.
Question:
What does "\"" + #"java" + "\"" here? If I provide such input will the system itself will search java.exe?
They simply ensure that the string will be "java" (with the quotes).
This is normally needed when you have a path that contains spaces.
Windows requires the path to be quoted if it contains spaces (for example "C:\Program Files").
As for finding the executable - if the path to the java executable is in the %PATH% environment variable, it will be found.
In this case they seem superfluous.
its the exe name which needs to be launched