using System;
using System.IO;
using System.Linq;
namespace CreateDirectoryTest {
internal class Program {
public static void Main(string[] args) {
if (!args.Any()) {
Console.WriteLine("Error: Usage: CreateDirectoryTest.exe {paths}");
}
foreach (var arg in args) {
try {
Console.WriteLine("Need to create the folder? " + arg + " (y/n)");
var input = Console.ReadLine();
if (input != null && input.Equals("n")) {
continue;
}
Directory.CreateDirectory(arg);
} catch (Exception e) {
Console.WriteLine("Error Creating directory: " + arg);
Console.WriteLine(e);
}
}
}
}
}
上面的代码创建一个可执行文件CreateDirectoryTest.exe,并分别在Win 2016服务器和Win 10台式机上进行了测试。
例如:CreateDirectoryTest.exe \\\ip-address\data\testFolder
\\ ip-address \ data \ testFolder是Linux文件系统上的网络共享,并且使用SMB协议进行通信。
以上过程分别在两个操作系统上的管理员和系统(NT Authority / SYSTEM)用户下执行,但是对于系统用户执行方案,在Win 2016服务器上此操作失败,并出现以下错误:
Error Creating directory: \\ip-address\data\testFolder
System.IO.IOException: The specified server cannot perform the requested operation.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
at CreateDirectoryTest.Program.Main(String[] args)
有人可以建议解决方案以解决Win Server 2016上的此问题吗?
注意:Windows 2016服务器未在域中注册,而Windows 10已注册并具有域名