3
用戶需要在我們的應用程序啓動時用他的Windows憑據登錄。這些憑據用於模擬用戶並在提供的登錄名下運行主窗體。我們現在有一個OpenFileDialog
用戶可以選擇文件。假冒時使用OpenFileDialog訪問映射的驅動器
現在的問題出現在用戶訪問映射的網絡驅動器時(顯示的是登錄到機器的用戶而不是我的程序)。按OK按鈕時,OpenFileDialog
會顯示一條錯誤消息(路徑無法找到/訪問,請確保它存在)。
正如我在其他帖子中看到的,可以將這些路徑映射回UNC路徑,但對話框甚至不會返回,因此我可以這樣做。除了製作我自己的打開文件對話框之外,是否還有一些解決方法?
模擬部分:顯示對話框之前
bool success = NativeMethods.LogonUser(userName, domain, password, (int)LogonType.Logon32LogonNewCredentials, (int)LogonProvider.Logon32ProviderWinnt50, ref pExistingTokenHandle);
if (success)
{
success = NativeMethods.DuplicateToken(pExistingTokenHandle, (int)SecurityImpersonationLevel.SecurityImpersonation, ref pDuplicateTokenHandle);
if (success)
{
// Return the impersonation context
WindowsIdentity identity = new WindowsIdentity(pDuplicateTokenHandle);
impersonationContext = identity.Impersonate();
return impersonationContext;
}
}
打開對話框部分
OpenFileDialog openFileDialog = new OpenFileDialog
{
Multiselect = true,
InitialDirectory = Environment.CurrentDirectory,
Title = "Select file"
};
bool? dialogResult = openFileDialog.ShowDialog(this);
if (dialogResult.Value)
{
openFileDialog.FileNames.ToList().ForEach(t => MessageBox.Show("File: " + t));
}
已嘗試運行您的應用程序與提高privledges? – Kcvin
是的,但這不會給我驅動器映射 – Scoregraphic