現在SMB 3.0的所有內容都爲Azure文件共享設置,只需打開一個新的資源管理器窗口並導航到\\ myfileshare.file.core.windows.net \ myfileshare即可。我已經構建了一個c#應用程序,它將用戶名和密碼保存到一個天藍色的文件共享中,以備後用。Process.Start Azure文件共享
爲了使應用程序更加用戶友好(大部分將由SysAdmins使用)我想添加文件>打開Azure文件共享按鈕。這是我遇到麻煩的地方。
我將從一些給定的信息開始:uncPath是文件共享的全部內容。這裏是我試過的代碼:
Process.Start(uncPath, username, password.ToSecureString(), ".");
--> Throws a Win32Exception, Username or Password incorrect
--> (They are both correct, The Domain is throwing this off.)
我永遠無法解決這個問題,所以我去了另一條路線。 NET使用文件共享,然後打開它。這工作,但我想在用戶存在的過程中取消映射共享。 (我不想離開映射驅動器周圍鋪設。)下面是代碼我曾嘗試:
/* --- MAP THE DRIVE --- */
Process p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "net.exe",
Arguments = $"use {uncPath} /u:{username} {password}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
}
};
p.Start();
/* --- OPEN THE UNC PATH --- */
Process azureP = new Process
{
StartInfo =
{
FileName = "explorer.exe",
Arguments = uncPath,
UseShellExecute = false,
},
EnableRaisingEvents = true,
};
azureP.Start();
/* -- UNMAP THE DRIVE ON EXIT --- */
azureP.Exited += ((object proc, EventArgs procE) =>
{
Process azurePExit = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "net.exe",
Arguments = $"use {uncPath} /delete",
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
});
正如預期的那樣,立即azureP.Exited火災,我理解爲什麼。
什麼是打開azure文件共享的最佳方式?