1
Excel 파일을 실행하기 위해 사용자가 현재 Windows 사용자 이름과 암호를 입력하도록 요구하는 코드를 작성하려고합니다. 그러나 process.start 부분에 문제가 있습니다. 내가 무엇을 놓치고 있는지 잘 모르겠다.성공적인 Windows 인증 후 Excel 파일 실행
코드 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestApp
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("advapi32.dll")]
public static extern bool LogonUser(string userName, string domainName, string password, int LogonType, int LogonProvider, ref IntPtr phToken);
public Form1()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
bool issuccess = false;
string username = GetloggedinUserName();
if (username.ToLowerInvariant().Contains(txtUserName.Text.Trim().ToLowerInvariant()) && username.ToLowerInvariant().Contains(txtDomain.Text.Trim().ToLowerInvariant()))
{
issuccess = IsValidateCredentials(txtUserName.Text.Trim(), txtPwd.Text.Trim(), txtDomain.Text.Trim());
}
if (issuccess)
MessageBox.Show("Successfuly Login !!!");
// Here is where I am having trouble. I cannot get this file to run.
Process.Start("Z:\\FolderA\\Test.xlsx");
else
MessageBox.Show("Invalid Username and/or Password Combination. Please try again. ");
}
private string GetloggedinUserName()
{
System.Security.Principal.WindowsIdentity currentUser = System.Security.Principal.WindowsIdentity.GetCurrent();
return currentUser.Name;
}
private bool IsValidateCredentials(string userName, string password, string domain)
{
IntPtr tokenHandler = IntPtr.Zero;
bool isValid = LogonUser(userName, domain, password, 2, 0, ref tokenHandler);
return isValid;
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
- 비주얼 스튜디오 오류 메시지 :
심각도 코드 설명
이 오류 CS0103 이름 '프로세스'는 현재 컨텍스트 TestApp가 C에 존재하지 않습니다 : \ C# \ Windows 인증 \ C# \ TestApp \ Form1.cs
오류 CS1513} 예상 된 TestApp C : \ C# \ Windows Authe ntication \ C# \ TestApp가 \ Form1.cs를 당신은 당신의IF
문에 괄호를 누락
정확한 오류 메시지/예외 사항을 추가하십시오. 또한 실제 코드가 컴파일되는지 여부를 명확히하고 질문에 게시 한 [MCVE]가 실제 문제를 반영하는지 확인하십시오. 지금까지 코드는 구문 상 올바르지 않습니다. –
사이드 노트 : SO에 게시물을 만들 때 "감사합니다"메모, 삶의 이야기 (새로운 내용/새로운 언어) 및 제목의 태그를 추가하지 마십시오. –
@AlexeiLevenkov - 우선, 나는 사전 감사를 면제하는 것이 타당하다고 생각합니다. 우발적으로, 성명서의 전 부분 : 나는 오류 메시지를 제공하기 위해 나의 이전 게시물 중 하나에서 비난을 받았다. 그래서 나는 약간 혼란 스럽다. 모든 솔직함에서 경의를 표하며, 제 코드가 "구문 상 부정확"하다는 사실을 알고 있습니다. 그래서 제가 도움을 청합니다. 어쨌든 건설적인 비판에 감사드립니다. 경이로운 날이있어 –