Guest User

Untitled

a guest
Aug 5th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. How to run bat file with required permissions in C#
  2. SET SRC=%1
  3. SET DEST=%2
  4.  
  5. xcopy /Y/I %SRC%*.txt %DEST%temp
  6. echo Done!
  7.  
  8. var psi = new ProcessStartInfo(fileToRun);
  9. psi.Arguments = args;
  10. psi.RedirectStandardOutput = true;
  11. psi.RedirectStandardError = true;
  12. psi.WindowStyle = ProcessWindowStyle.Hidden;
  13. psi.UseShellExecute = false;
  14. psi.CreateNoWindow = true;
  15.  
  16. Process cmdProc = Process.Start(psi);
  17.  
  18. StreamReader output = cmdProc.StandardOutput;
  19. StreamReader errors = cmdProc.StandardError;
  20. cmdProc.WaitForExit();
  21.  
  22. psi.UseShellExecute = true;
  23.  
  24. psi.RedirectStandardOutput = false;
  25. psi.RedirectStandardError = false;
  26.  
  27. psi.UserName = username;
  28. psi.Password = password;
  29.  
  30. psi.RedirectStandardInput = true;
Add Comment
Please, Sign In to add comment