コード例 #1
0
        public void VistaPrompt_ShowDialog_WithParent_ShouldNotThrowError()
        {
            VistaPrompt prompt = GetDefaultPrompt();

            prompt.ShowDialog(IntPtr.Zero);
            prompt.Dispose();
        }
コード例 #2
0
        protected override bool Execute(CodeActivityContext context)
        {
            var credPrompt = new VistaPrompt
            {
                GenericCredentials = true
            };
            var message = Message.Get(context);
            if (message != null)
            {
                credPrompt.Message = message;
            }

            var title = Title.Get(context);
            if (title != null)
            {
                credPrompt.Title = title;
            }

            var res = credPrompt.ShowDialog();
            if (res != DialogResult.OK) return false;

            Username.Set(context, credPrompt.Username);
            Password.Set(context, credPrompt.Password);
            return true;
        }
コード例 #3
0
        public void VistaPrompt_ShowDialog_ShouldNotThrowError()
        {
            VistaPrompt prompt = GetDefaultPrompt();

            prompt.ShowDialog();
            prompt.Dispose();
        }
コード例 #4
0
        public void VistaPrompt_ShowDialog_ShowSaveCheckBox()
        {
            VistaPrompt prompt = GetDefaultPrompt();

            prompt.ShowSaveCheckBox = true;
            prompt.ShowDialog(IntPtr.Zero);
            prompt.Dispose();
        }
コード例 #5
0
        public void VistaPrompt_ShowDialog_With_Username()
        {
            VistaPrompt prompt = GetDefaultPrompt();

            prompt.Username = "******";
            prompt.ShowDialog().ShouldEqual(DialogResult.OK);
            prompt.Dispose();
        }
コード例 #6
0
        public void VistaPrompt_ShowDialog_GenericCredentials()
        {
            VistaPrompt prompt = GetDefaultPrompt();

            prompt.Title = "Please provide credentials";
            prompt.GenericCredentials = true;
            prompt.ShowDialog(IntPtr.Zero);
            prompt.Dispose();
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: stjordanis/ServiceBouncer
        private async Task <bool> Reload()
        {
            try
            {
                var systemServices = await Task.Run(() => ServiceController.GetServices(machineHostname));

                services.Clear();

                foreach (var model in systemServices.Select(service => new ServiceViewModel(service)))
                {
                    services.Add(model);
                }

                await PerformBackgroundOperation(x => x.Refresh(
                                                     ServiceViewModel.RefreshData.DisplayName,
                                                     ServiceViewModel.RefreshData.ServiceName,
                                                     ServiceViewModel.RefreshData.Description,
                                                     ServiceViewModel.RefreshData.Status,
                                                     ServiceViewModel.RefreshData.Startup,
                                                     ServiceViewModel.RefreshData.LogOnAs));

                PopulateFilteredDataview();
                SetTitle();
                return(true);
            }
            catch (Exception e) when(ExceptionIsAccessDenied(e))
            {
                var prompt = new VistaPrompt
                {
                    Title   = "Access denied",
                    Message = $"Enter administrator credentials for {machineHostname}"
                };

                if (prompt.ShowDialog() == CredentialManagement.DialogResult.OK)
                {
                    StartNewProcess(prompt);
                    return(false);
                }

                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: smiech/TestProject
        public static System.Net.NetworkCredential GetCredential(string serverip)
        {
            System.Net.NetworkCredential credentials = null;
            BaseCredentialsPrompt        prompt      = null;

            if (IsWinVistaOrHigher())
            {
                prompt = new VistaPrompt();
                Console.WriteLine("win7");
            }
            else
            {
                prompt = new XPPrompt()
                {
                    Target = serverip
                };

                Console.WriteLine("xp");
            }
            prompt.SaveChecked      = true;
            prompt.ShowSaveCheckBox = true;
            prompt.Title            = @"指定已授权的 域(计算机)\用户";
            try
            {
                if (prompt.ShowDialog() == DialogResult.OK)
                {
                    credentials = new System.Net.NetworkCredential(prompt.Username, prompt.SecurePassword);
                    if (prompt.SaveChecked)
                    {
                        var cm = new Credential()
                        {
                            Target          = serverip,
                            Type            = CredentialType.DomainPassword, //windows 凭证 Generic 普通凭证
                            PersistanceType = PersistanceType.Enterprise,    //永久
                            Username        = prompt.Username,
                            SecurePassword  = prompt.SecurePassword
                        };
                        cm.Save();
                    }
                    return(credentials);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException());
            }

            return(null);
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
        private static string GetPassword(string key)
        {
            using (var cred = new Credential())
            {
                cred.Target = key;
                if (!cred.Load())
                {
                    var prompt = new VistaPrompt();
                    prompt.GenericCredentials = true;
                    prompt.ShowDialog();

                    var password = prompt.Password;
                    SavePassword(key, password);
                    return(password);
                }
                else
                {
                    return(cred.Password);
                }
            }
        }
コード例 #11
0
ファイル: Launcher.cs プロジェクト: goofwear/SuperLauncher
        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);
                }
            }
        }
コード例 #12
0
ファイル: CredentialManager.cs プロジェクト: evilz/sonet-cra
        public UserPass GetOrCreateCredential()
        {
            var           credentialKey = "sonet.soat.fr";
            CredentialSet set           = new CredentialSet(credentialKey);

            Credential credential = null;

            set = set.Load();
            if (set.Count == 0)
            {
                var prompt = new VistaPrompt();
                prompt.ShowDialog();
                credential = new Credential(prompt.Username.Split('\\').Last(), prompt.Password, credentialKey, CredentialType.Generic);
                credential.Save();
            }
            else
            {
                credential = set[0];
                Console.Write($"User and password found ! ", Color.Gainsboro);
                Console.WriteLine(credential.Username, Color.DarkKhaki);
            }

            return(new UserPass(credential.Username, credential.Password));
        }
コード例 #13
0
        private static SecureString PromptForPassword(string email)
        {
            var prompt = new VistaPrompt
            {
                Message            = $"Please enter password for {email}",
                Username           = email,
                Title              = "Sender email password",
                ShowSaveCheckBox   = true,
                GenericCredentials = true
            };

            if (prompt.ShowDialog() == DialogResult.OK)
            {
                using (var credential = new Credential(email, prompt.Password, email, CredentialType.Generic))
                {
                    if (prompt.SaveChecked)
                    {
                        credential.Save();
                    }
                    return(credential.SecurePassword);
                }
            }
            return(null);
        }
コード例 #14
0
        private async Task <bool> Reload()
        {
            try
            {
                ManagementObjectCollection win32Services = null;

                await Task.Run(() =>
                {
                    ManagementObjectSearcher searcher;

                    if (!string.IsNullOrEmpty(machineHostname) && machineHostname != Environment.MachineName)
                    {
                        var options = new ConnectionOptions {
                            Impersonation = ImpersonationLevel.Impersonate
                        };

                        var scope = new ManagementScope("\\\\" + machineHostname + "\\root\\cimv2", options);
                        scope.Connect();

                        var query = new ObjectQuery("SELECT * FROM Win32_Service");
                        searcher  = new ManagementObjectSearcher(scope, query);
                    }
                    else
                    {
                        searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Service");
                    }

                    win32Services = searcher.Get();

                    modificationEventWatcher?.Dispose();
                    modificationEventWatcher = new ManagementEventWatcher(searcher.Scope, new EventQuery("SELECT * FROM __InstanceModificationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Service'"));
                    modificationEventWatcher.EventArrived += ModificationEventWatcher_EventArrived;
                    modificationEventWatcher.Start();

                    creationEventWatcher?.Dispose();
                    creationEventWatcher = new ManagementEventWatcher(searcher.Scope, new EventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Service'"));
                    creationEventWatcher.EventArrived += CreationEventWatcher_EventArrived;
                    creationEventWatcher.Start();

                    deletionEventWatcher?.Dispose();
                    deletionEventWatcher = new ManagementEventWatcher(searcher.Scope, new EventQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_Service'"));
                    deletionEventWatcher.EventArrived += DeletionEventWatcher_EventArrived;
                    deletionEventWatcher.Start();
                });

                services.Clear();

                foreach (var model in win32Services)
                {
                    services.Add(new ServiceViewModel(machineHostname, model));
                }

                PopulateFilteredDataview();
                SetTitle();
                return(true);
            }
            catch (Exception e) when(ExceptionIsAccessDenied(e))
            {
                var prompt = new VistaPrompt
                {
                    Title   = "Access denied",
                    Message = $"Enter administrator credentials for {machineHostname}"
                };

                if (prompt.ShowDialog() == CredentialManagement.DialogResult.OK)
                {
                    StartNewProcess(prompt);
                    return(false);
                }

                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                Disconnect();
                MessageBox.Show($@"Unable to retrieve the services from {toolStripConnectToTextBox.Text}.{Environment.NewLine}Message: {e.Message}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }