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();
}
}
}
- のVisual Studioエラーメッセージ:CS0103名 'プロセスは' は現在のコンテキストでTestApp Cには存在しません
重大度コード説明
エラー: \ C#\ Windows認証\ C#\ TestApp \ Form1.cs
エラーCS1513}期待されるTestApp C:\ C#\ Windows Authe ntication \ C#\でTestApp \ Form1.csのあなたのIF
文で括弧が欠落している
正確なエラーメッセージ/例外を追加してください。また、あなたの実際のコードがコンパイルされているかどうかを明確にし、質問に投稿した[MCVE]があなたの実際の問題を反映していることを確認してください。今のところコードは構文的に正しくありません。 –
サイドノート:「ありがとうございました」メモ、あなたの人生の物語(ここでは新しく/言語には新しい)、そしてSOで投稿を作成するときはタイトルのタグを追加しないでください。 –
@AlexeiLevenkov - 一番最初に、私は先の謝辞を却下することに妥当性を認めます。偶然、あなたの声明の前の部分に:私はエラーメッセージを提供するために私の以前の投稿の1つで叱られたので、...私はちょっと混乱しています。私のコードは「構文的に間違っている」という事実を認識しています。それが私が助けを求めている理由です。それにもかかわらず、あなたの建設的な批判に感謝します。不思議の国のアリス –