Question

In our project we are installing windows service using windows application where user enters username and password. when they click on submit we are running batch file where we are replacing username and password and running the batch file

Problem:The installation failed when password contains % character

My batch file content

@ECHO OFF


set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing TestPrint Win Service...
echo ---------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /username=domain\112233/password=5one0one4%  "%~dp0TestPrint.exe"
echo ---------------------------------------------------
Was it helpful?

Solution

For the c# part. Just remember the arguments must be quoted for it to work

string _userName = @"xrxodc\394657";
string _password = @"5one0one4%";
Process proc = new Process();
proc.StartInfo.FileName = @"C:\somewhere\batchFile.cmd";
proc.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"", _userName, _password)
proc.Start();

For the batch part

....
set "userName=%~1"
set "password=%~2"
....
.... InstallUtil /username=%userName% /password=%password%  "%~dp0TestPrint.exe"

And, i can not test it, but if it is allowed, you will need to change the syntax to

.... InstallUtil /username="%userName%" /password="%password%"  "%~dp0TestPrint.exe"

to avoid problems with special characters in passwords

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top