Guest User

Untitled

a guest
Jan 17th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Diagnostics;
  4. using System.Security;
  5. using System.Reflection;
  6. using System.IO;
  7.  
  8. namespace ConsoleApplication6 {
  9. class Program {
  10.  
  11. unsafe static void Main(string[] args) {
  12.  
  13. Process process = new Process();
  14. String dir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
  15.  
  16. String txtFile = Path.Combine(dir, "example.txt");
  17. if (!File.Exists(txtFile)) {
  18. StreamWriter sw = File.CreateText(txtFile);
  19. sw.Close();
  20. sw.Dispose();
  21. }
  22.  
  23. ProcessStartInfo info = new ProcessStartInfo();
  24.  
  25. info.Domain = "myDomainName";
  26. info.UserName = "userName";
  27. String pass = "userPassword";
  28.  
  29. fixed (char* password = pass) {
  30. info.Password = new SecureString(password, pass.Length);
  31. }
  32.  
  33. // Will be run notepad.exe
  34. info.FileName = Environment.ExpandEnvironmentVariables(@"%winDir%NOTEPAD.EXE");
  35. // in notepad.exe will be open example.txt file.
  36. info.Arguments = txtFile;
  37. info.LoadUserProfile = false;
  38. info.UseShellExecute = false;
  39. info.WorkingDirectory = dir;
  40.  
  41. process.StartInfo = info;
  42. process.Start();
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment