【发布时间】:2017-07-31 13:31:49
【问题描述】:
现在 SMB 3.0 的所有内容都已针对 Azure 文件共享进行设置,只需打开一个新的资源管理器窗口并导航到 \\myfileshare.file.core.windows.net\myfileshare 即可。我已经构建了一个 c# 应用程序,它将用户名和密码保存到一个 azure 文件共享中,以供以后使用。
为了使应用程序对用户更加友好(主要由系统管理员使用),我想添加一个文件 > 打开 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 文件共享的最佳方式是什么?
【问题讨论】:
标签: c# azure process process.start