コード例 #1
0
        private static bool GetCredentialsOldSchool(string captionText, string messageText, string userName, out NetworkCredential networkCredential)
        {
            StringBuilder stringBuilder  = new StringBuilder();
            StringBuilder stringBuilder2 = new StringBuilder(userName);

            PromptForCredentials.CREDUI_INFO cREDUI_INFO = default(PromptForCredentials.CREDUI_INFO);
            cREDUI_INFO.cbSize = Marshal.SizeOf(cREDUI_INFO);
            bool flag = false;

            cREDUI_INFO.pszCaptionText = captionText;
            PromptForCredentials.CREDUI_FLAGS flags = PromptForCredentials.CREDUI_FLAGS.ALWAYS_SHOW_UI | PromptForCredentials.CREDUI_FLAGS.GENERIC_CREDENTIALS;
            if (PromptForCredentials.CredUIPromptForCredentials(ref cREDUI_INFO, messageText, IntPtr.Zero, 0, stringBuilder2, 100, stringBuilder, 100, ref flag, flags) == PromptForCredentials.CredUIReturnCodes.NO_ERROR)
            {
                string userName2 = stringBuilder2.ToString();
                string password  = stringBuilder.ToString();
                networkCredential = new NetworkCredential(userName2, password);
                return(true);
            }
            networkCredential = null;
            return(false);
        }
コード例 #2
0
 private static extern PromptForCredentials.CredUIReturnCodes CredUIPromptForCredentials(ref PromptForCredentials.CREDUI_INFO creditUR, string targetName, IntPtr reserved1, int iError, StringBuilder userName, int maxUserName, StringBuilder password, int maxPassword, [MarshalAs(UnmanagedType.Bool)] ref bool pfSave, PromptForCredentials.CREDUI_FLAGS flags);