The scenario is to start elevated cmd which calls a bat file and right after starting the process the app quits. The code from the wpf app:
private static void CmdCommand(string filename, string workingDir)
{
var processInfo = new ProcessStartInfo(workingDir + filename);
processInfo.UseShellExecute = true;
processInfo.Verb = "runas";
processInfo.WorkingDirectory = workingDir;
processInfo.Arguments = "\""+workingDir+"\"" ;
Thread t1 = new Thread(new ThreadStart(
delegate
{
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
Process.Start(processInfo);
}));
}));
t1.Start();
Thread t2 = new Thread(new ThreadStart(
delegate
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
System.Windows.Application.Current.Shutdown();
}));
}));
t2.Start();
}
The code in the bat file:
set Path1=%~1
ping 127.0.0.1 -n 6 > nul
copy /Y "%Path1%dbg\lib.dll" "%Path1%lib.dll"
pause
ping 127.0.0.1 -n 6 > nul
call "%Path1%wpf.exe"
The result is that the cmd appears for a moment and disappears and no result. This works when not elevated. But I need it to be elevated as there are no rights to copy in the working dir. I tried recording screen to pause when the cmd appears but the recorder scips this part. So how can I debbug it?
EDIT
Actually it is working but without one line
processInfo.Arguments = "\""+workingDir+"\"" ;
and I need to pass the arguments
EDIT 2
Apparently the problem is """ but if I don't add those I'll have a bug with paths containing spaces.