@@ -405,9 +405,9 @@ public static string ExtractStringFromDLL(string file, int number)
405405 }
406406 }
407407
408- public static async Task < bool > RunPowershellCommandAsync ( string command , PowerShellExecutionOptions options )
408+ public static async Task < bool > RunPowershellCommandAsync ( string command , PowerShellExecutionOptions options , string ? workingDirectory = null )
409409 {
410- using Process process = CreatePowershellProcess ( command , options ) ;
410+ using Process process = CreatePowershellProcess ( command , options , workingDirectory ) ;
411411 using var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 30 * 1000 ) ) ;
412412
413413 try
@@ -432,11 +432,11 @@ public static async Task<bool> RunPowershellCommandAsync(string command, PowerSh
432432 }
433433 }
434434
435- public static bool RunPowershellCommand ( string command , PowerShellExecutionOptions options )
435+ public static bool RunPowershellCommand ( string command , PowerShellExecutionOptions options , string ? workingDirectory = null )
436436 {
437437 try
438438 {
439- using Process process = CreatePowershellProcess ( command , options ) ;
439+ using Process process = CreatePowershellProcess ( command , options , workingDirectory ) ;
440440
441441 process . Start ( ) ;
442442
@@ -867,7 +867,7 @@ public static async Task InstallFontsAsync(string[] fontFilePaths, bool forAllUs
867867 await RunPowershellCommandAsync ( psCommand . Append ( "\" " ) . ToString ( ) , PowerShellExecutionOptions . Elevated | PowerShellExecutionOptions . Hidden ) ;
868868 }
869869
870- private static Process CreatePowershellProcess ( string command , PowerShellExecutionOptions options )
870+ private static Process CreatePowershellProcess ( string command , PowerShellExecutionOptions options , string ? workingDirectory = null )
871871 {
872872 Process process = new ( ) ;
873873
@@ -883,6 +883,10 @@ private static Process CreatePowershellProcess(string command, PowerShellExecuti
883883 process . StartInfo . CreateNoWindow = true ;
884884 process . StartInfo . WindowStyle = ProcessWindowStyle . Hidden ;
885885 }
886+
887+ if ( workingDirectory is not null )
888+ process . StartInfo . WorkingDirectory = workingDirectory ;
889+
886890 process . StartInfo . Arguments = command ;
887891
888892 return process ;
0 commit comments