private void ShowRunAs(int ErrorCode = 0, ConfigHelper configHelper = null) { VistaPrompt prompt = new VistaPrompt(); prompt.ErrorCode = ErrorCode; prompt.Title = "Super Launcher - Run-As"; prompt.Message = "Please enter the credentials you would like Super Launcher to run as..."; if (configHelper != null && configHelper.HasRunAsCredential()) { prompt.Username = configHelper.UserName; prompt.Domain = configHelper.Domain; } if (prompt.ShowDialog() == CredentialManagement.DialogResult.OK) { CredentialParser.ParseUserName(prompt.Username, out string username, out string domain); Process process = new Process(); ProcessStartInfo startInfo = process.StartInfo; startInfo.FileName = Application.ExecutablePath; startInfo.WorkingDirectory = Application.StartupPath; startInfo.Domain = domain; startInfo.UserName = username; startInfo.Password = prompt.SecurePassword; startInfo.UseShellExecute = false; process.StartInfo = startInfo; try { process.Start(); fakeClose = false; Close(); } catch (Win32Exception e) { if (e.NativeErrorCode == 267) { int result = (int)MessageBox.Show("The credentials supplied do not have access to the currently running \"Super Launcher\" executable file.\n\nConsider moving Super Launcher to a location that this account has access too.", "Super Launcher: Permission Error.", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning); if (result == 2) { return; //If result equals "Cancel". https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.dialogresult?view=net-5.0 } } ShowRunAs(e.NativeErrorCode); } } }
private void ShowRunAs(int ErrorCode = 0) { VistaPrompt prompt = new VistaPrompt(); prompt.ErrorCode = ErrorCode; prompt.Title = "Run As - Super Launcher"; prompt.Message = "Please enter the credentials you would like Super Launcher to run as..."; if (prompt.ShowDialog() == CredentialManagement.DialogResult.OK) { string username, domain; CredentialParser.ParseUserName(prompt.Username, out username, out domain); Process process = new Process(); ProcessStartInfo startInfo = process.StartInfo; startInfo.FileName = Application.ExecutablePath; startInfo.WorkingDirectory = Application.StartupPath; startInfo.Domain = domain; startInfo.UserName = username; startInfo.Password = prompt.SecurePassword; startInfo.UseShellExecute = false; process.StartInfo = startInfo; try { process.Start(); Application.ExitThread(); } catch (System.ComponentModel.Win32Exception e) { if (e.NativeErrorCode == 267) { TrayIcon.BalloonTipIcon = ToolTipIcon.Warning; TrayIcon.BalloonTipText = "The credentials supplied does not have access to the currently running \"SuperLauncher\" executable file."; TrayIcon.ShowBalloonTip(10000); } ShowRunAs(e.NativeErrorCode); } } }