When i am adding service to windows manually by typing in CMD something like this:
"C:\Program Files (x86)\Windows Resource Kits\Tools\instsrv.exe" "some-pl-char-ąźńćńół" "C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe"
... everything is good with service name, but when i try do that in c#:
ProcessStartInfo startInfo = new ProcessStartInfo();
Process myprocess = new Process();
startInfo.FileName = "cmd";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
myprocess.StartInfo = startInfo;
myprocess.Start();
StreamWriter sw = myprocess.StandardInput;
StreamReader sr = myprocess.StandardOutput;
Thread.Sleep(200);
string command = ...
^ "C:\Program Files (x86)\Windows Resource Kits\Tools\instsrv.exe" "some-pl-char-ąźńćńół" "C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe"
sw.WriteLine(command);
sw.WriteLine("exit");
Thread.Sleep(200);
sw.Close();
sr.Close();
then name of created service is: some-pl-char-¦č˝Š˝ˇ-
Why there is problem with code page?
There is something like StandardInputEncoding for ProcessStartInfo?
My active code page in CMD (using chcp) is 852. (Polish)
Arguments belongs assigned to the Arguments property and backslashes needs to be escaped by another one. \
-> \\
Updated:
using (var process = new Process())
{
var encoding = Encoding.GetEncoding(852);
var psi = new ProcessStartInfo();
psi.FileName = "cmd";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.StandardOutputEncoding = encoding;
process.StartInfo = psi;
process.Start();
using (var sr = process.StandardOutput)
using (var sw = new StreamWriter(process.StandardInput.BaseStream, encoding))
{
var command = "....";
sw.WriteLine(command);
// etc..
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With