Windows 10 在使用可执行文件的完整路径时无法访问指定的设备、路径或文件,运行 作为管理员
Windows 10 cannot access the specified device, path, or file when using full path to executable, running as Administrator
注意 :我用 a
替换了目录,用 b.exe
替换了 exe 并且我重复了我所做的每一个测试确定这不是打字语法。
我有一段非常简单的代码,从 Windows XP 到 Windows 7 都能完美运行。
var processPath = @"c:\a\b.exe" ; // this exe exists on my computer
Process.Start(processPath);
还有
Directory.Exists(@"c:\a\") returns false on Windows 10.
因为 Windows 10(我还没有测试 8 和 8.1),第一个代码将抛出 System.ComponentModel.Win32Exception
("Specified file not found"),第二个将 return false。 .
我还注意到,当我 运行 "c:\a\b.exe" 与 windows 运行 window 时,这是相同的行为( Windows 键 + R).
是否有解决此问题的解决方法?优选地,一种不暗示重新编译的解决方案。
注意事项 :
- 我是 运行宁 windows 管理员
- 用户有权访问该文件(为计算机中的每个人启用安全属性)。
c:\b.exe
有效!!
- 我不是在寻找像更改应用程序工作目录和 运行 Process.Start("b.exe") 这样的解决方案。
谢谢大家,
编辑:
- 指定的路径没有错,文件也没有丢失。
- 计算机的每个用户作为总控制级别访问文件夹和文件(
a
目录和 b.exe
)
- 当我将 exe 放在根目录时工作:"c:\b.exe"
- 与 .bat 文件的行为相同,只有 "echo Hello inside"
Console.WriteLine(String.Join("\r\n", Directory.GetDirectories(@"c:\")))
显示目录c:\a
更新:
icalcs c:\a\
的结果:
c:\a\ Tout le monde:(OI)(CI)(F)
BUILTIN\Administrateurs:(I)(OI)(CI)(F)
AUTORITE NT\SystŠme:(I)(OI)(CI)(F)
BUILTIN\Utilisateurs:(I)(OI)(CI)(RX)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(M)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(OI)(CI)(IO)(M)
icalcs c:\a\b.exe
的结果:
c:\a\b.exe Tout le monde:(I)(F)
BUILTIN\Administrateurs:(I)(F)
AUTORITE NT\SystŠme:(I)(F)
BUILTIN\Utilisateurs:(I)(RX)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(M)
"Tout le monde" 表示所有人。
更新 :
根据最新消息,我可以做到:
File.WriteAllBytes(@"c:\a\b.exe", somebinaries) ;
但是我做不到
FileInfo fileInfo = new FileInfo(@"c:\a\b.exe") ;
投掷'System.NotSupportedException'。 StackTrace如下:
à System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
à System.IO.FileInfo.Init(String fileName, Boolean checkHost)
à System.IO.FileInfo..ctor(String fileName)
à ConsoleApplication1.Program.Main(String[] args) dans F:\MAPW10\Development\Sources\Tools\ConsoleApplication1\Program.cs:ligne 22
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
...SystŠme
...authentifi‚s
混淆目录和文件名很难帮到你。但是有一块明显的石头需要看,让重音字符如此严重地被破坏,这样的事情永远不会发生。该机器说法语,但似乎使用的编码是 1250,仅在东欧使用。非常奇怪的不匹配,尤其是对于控制台模式应用程序。
如果 real a
目录同样包含带有变音符号的字符,那么损坏 icalcs.exe 程序输出背后的任何根本原因都可能影响文件系统名称编码以及。粗略的结论是这台机器很糟糕,需要极客小队的帮助才能变得更好。
找到了!!
从Windows10 explorer.
中的一些标签复制/粘贴时,文件路径中添加了一些额外的不可打印字节
考虑这段代码:
Console.WriteLine(new DirectoryInfo(@"c:\a\"));
Console.WriteLine(new DirectoryInfo(@"c:\a\"));
这些行看起来相同,不应引发任何异常(即使目录 c:\a
不存在)但实际上如果您 copy/paste 在应用程序中使用上面的代码,第二行将提高 NotSupportedException
字词:“不支持给定路径的格式”。
我最终检查了 .NET 源代码并找到了引发 NotSupportedException 的方法 StringExpressionSet.Canonicalize:
...
if (path.IndexOf( ':', 2 ) != -1)
throw new NotSupportedException( Environment.GetResourceString( "Argument_PathFormatNotSupported" ) );
...
实际上:
Console.WriteLine(@"c:\a\".IndexOf( ':', 2 )); // results -1
Console.WriteLine(@"c:\a\".IndexOf( ':', 2 )); // result 2
// Copy/Paste to test
我在哪里抓到的?
为了不犯任何打字错误,我习惯将目录路径从右键单击复制到文件 -> Properties
-> Security
你现在被警告 !
注意 :我用 a
替换了目录,用 b.exe
替换了 exe 并且我重复了我所做的每一个测试确定这不是打字语法。
我有一段非常简单的代码,从 Windows XP 到 Windows 7 都能完美运行。
var processPath = @"c:\a\b.exe" ; // this exe exists on my computer
Process.Start(processPath);
还有
Directory.Exists(@"c:\a\") returns false on Windows 10.
因为 Windows 10(我还没有测试 8 和 8.1),第一个代码将抛出 System.ComponentModel.Win32Exception
("Specified file not found"),第二个将 return false。 .
我还注意到,当我 运行 "c:\a\b.exe" 与 windows 运行 window 时,这是相同的行为( Windows 键 + R).
是否有解决此问题的解决方法?优选地,一种不暗示重新编译的解决方案。
注意事项 :
- 我是 运行宁 windows 管理员
- 用户有权访问该文件(为计算机中的每个人启用安全属性)。
c:\b.exe
有效!!- 我不是在寻找像更改应用程序工作目录和 运行 Process.Start("b.exe") 这样的解决方案。
谢谢大家,
编辑:
- 指定的路径没有错,文件也没有丢失。
- 计算机的每个用户作为总控制级别访问文件夹和文件(
a
目录和b.exe
) - 当我将 exe 放在根目录时工作:"c:\b.exe"
- 与 .bat 文件的行为相同,只有 "echo Hello inside"
Console.WriteLine(String.Join("\r\n", Directory.GetDirectories(@"c:\")))
显示目录c:\a
更新:
icalcs c:\a\
的结果:
c:\a\ Tout le monde:(OI)(CI)(F)
BUILTIN\Administrateurs:(I)(OI)(CI)(F)
AUTORITE NT\SystŠme:(I)(OI)(CI)(F)
BUILTIN\Utilisateurs:(I)(OI)(CI)(RX)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(M)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(OI)(CI)(IO)(M)
icalcs c:\a\b.exe
的结果:
c:\a\b.exe Tout le monde:(I)(F)
BUILTIN\Administrateurs:(I)(F)
AUTORITE NT\SystŠme:(I)(F)
BUILTIN\Utilisateurs:(I)(RX)
AUTORITE NT\Utilisateurs authentifi‚s:(I)(M)
"Tout le monde" 表示所有人。
更新 :
根据最新消息,我可以做到:
File.WriteAllBytes(@"c:\a\b.exe", somebinaries) ;
但是我做不到
FileInfo fileInfo = new FileInfo(@"c:\a\b.exe") ;
投掷'System.NotSupportedException'。 StackTrace如下:
à System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
à System.IO.FileInfo.Init(String fileName, Boolean checkHost)
à System.IO.FileInfo..ctor(String fileName)
à ConsoleApplication1.Program.Main(String[] args) dans F:\MAPW10\Development\Sources\Tools\ConsoleApplication1\Program.cs:ligne 22
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
...SystŠme
...authentifi‚s
混淆目录和文件名很难帮到你。但是有一块明显的石头需要看,让重音字符如此严重地被破坏,这样的事情永远不会发生。该机器说法语,但似乎使用的编码是 1250,仅在东欧使用。非常奇怪的不匹配,尤其是对于控制台模式应用程序。
如果 real a
目录同样包含带有变音符号的字符,那么损坏 icalcs.exe 程序输出背后的任何根本原因都可能影响文件系统名称编码以及。粗略的结论是这台机器很糟糕,需要极客小队的帮助才能变得更好。
找到了!!
从Windows10 explorer.
中的一些标签复制/粘贴时,文件路径中添加了一些额外的不可打印字节考虑这段代码:
Console.WriteLine(new DirectoryInfo(@"c:\a\"));
Console.WriteLine(new DirectoryInfo(@"c:\a\"));
这些行看起来相同,不应引发任何异常(即使目录 c:\a
不存在)但实际上如果您 copy/paste 在应用程序中使用上面的代码,第二行将提高 NotSupportedException
字词:“不支持给定路径的格式”。
我最终检查了 .NET 源代码并找到了引发 NotSupportedException 的方法 StringExpressionSet.Canonicalize:
...
if (path.IndexOf( ':', 2 ) != -1)
throw new NotSupportedException( Environment.GetResourceString( "Argument_PathFormatNotSupported" ) );
...
实际上:
Console.WriteLine(@"c:\a\".IndexOf( ':', 2 )); // results -1
Console.WriteLine(@"c:\a\".IndexOf( ':', 2 )); // result 2
// Copy/Paste to test
我在哪里抓到的?
为了不犯任何打字错误,我习惯将目录路径从右键单击复制到文件 -> Properties
-> Security
你现在被警告 !