Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Security.Principal;
  11. using IWshRuntimeLibrary;
  12. using System.IO;
  13.  
  14. // decrypted = CryptorEngine.Decrypt(encrypted, true);
  15.  
  16. namespace runv2
  17. {
  18. public partial class Form1 : Form
  19. {
  20. bool isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
  21. string DesktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  22. runv2.Login pLogin = new Login();
  23. private string pUser = string.Empty, pPass = string.Empty;
  24. public Form1()
  25. {
  26. getLoginFromFile();
  27. LoadAll();
  28. //pLogin.ShowDialog();
  29. InitializeComponent();
  30. this.Refresh();
  31. //FileDialog();
  32. }
  33.  
  34. void Start(string fPath)
  35. {
  36. StreamReader sr = new StreamReader(@".\login.txt");
  37. string domain = "";
  38. try
  39. {
  40. Process p = RunAs.StartProcess(pUser, domain, pPass, "\"" + fPath);
  41. }
  42. catch (Win32Exception w32e)
  43. {
  44. MessageBox.Show(w32e.ToString());// The process didn't start.
  45. }
  46. }
  47.  
  48. void FileDialog()
  49. {
  50. string fPath = string.Empty;
  51. string fFilename = string.Empty;
  52. string decrypted = string.Empty;
  53. string encrypted = string.Empty;
  54.  
  55. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  56. openFileDialog1.Title = "Anwendung aussucheN";
  57. openFileDialog1.InitialDirectory = @"D:\";
  58. openFileDialog1.Filter = "Anwendungen (*.exe)|*.exe";
  59. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  60. fPath = openFileDialog1.FileName;
  61. fFilename = Path.GetFileNameWithoutExtension(fPath);
  62. if (fFilename != "")
  63. createLink(fPath, fFilename);
  64.  
  65. }
  66.  
  67. void createLink(string fPath,string fFilename)
  68. {
  69. if (!Directory.Exists(Application.StartupPath + "\\Links\\"))
  70. {
  71. Directory.CreateDirectory(Application.StartupPath + "\\Links\\");
  72. }
  73. WshShell shell = new WshShell();
  74. IWshShortcut link = (IWshShortcut)shell.CreateShortcut(Application.StartupPath+"\\Links\\"+fFilename+".lnk");
  75. link.TargetPath = fPath;
  76. link.Save();
  77. }
  78.  
  79. string[] getLogin()
  80. {
  81. string account, password;
  82. string[] login = new string[2];
  83. account = pLogin.Acc;
  84. password = pLogin.Pw;
  85. login[0] = account;
  86. login[1] = password;
  87. return login;
  88. }
  89.  
  90. string[] encrypt()
  91. {
  92. string encrypted_acc = string.Empty, encrypted_pw = string.Empty;
  93. string[] encrypted_array = new string[2];
  94. string[] login_array = new string[2];
  95.  
  96. login_array = getLogin();
  97. if (encrypted_acc != null && encrypted_pw != null)
  98. {
  99. encrypted_acc = CryptorEngine.Encrypt(login_array[0], true);
  100. encrypted_pw = CryptorEngine.Encrypt(login_array[1], true);
  101. encrypted_array[0] = encrypted_acc;
  102. encrypted_array[1] = encrypted_pw;
  103. }
  104. return encrypted_array;
  105. }
  106.  
  107. private void button1_Click(object sender, EventArgs e)
  108. {
  109. string[] encrypted = encrypt();
  110. StreamWriter sw = new StreamWriter(@".\login.txt");
  111. foreach (string pEnc in encrypted)
  112. {
  113. sw.WriteLine(pEnc);
  114. }
  115. sw.Close();
  116. MessageBox.Show("Login-Daten gespeichert!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  117. }
  118. void getLoginFromFile()
  119. {
  120. if (!System.IO.File.Exists(@".\login.txt"))
  121. {
  122. StreamReader sr = new StreamReader(@".\login.txt");
  123. pUser = sr.ReadLine();
  124. pPass = sr.ReadLine();
  125. }
  126. }
  127.  
  128. private void button2_Click(object sender, EventArgs e)
  129. {
  130. Start("as");
  131. }
  132. void LoadAll()
  133. {
  134. string[] filePaths = Directory.GetFiles(@".\Links\", "*.lnk");
  135. listBox1.Items = new List<string>();
  136. foreach(string Path in filePaths)
  137. {
  138. listBox1.Items.Add(Path);
  139. }
  140. //foreach()
  141. }
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement