System.IO未找到通过subst命令生成的路径 [英] Path generated via subst-command not found by System.IO
问题描述
上下文:
- 系统有一个硬盘和一个驱动器("C:\")
- 所需的路径位于F:\ eventlogging
我做了什么:
-
我执行了subst cmd来生成F:\驱动器(从C:\)
I executed the subst cmd in order to generate the F:\ drive (from C:\)
添加了目录"eventlogging"
Added the directory "eventlogging"
问题:
- 在代码中,某些部分将其写入F:\ eventlogging内部的文件中
- 引发异常:System.IO.DirectoryNotFoundException:System.IO.DirectoryNotFoundException:无法找到路径的一部分"F:\ eventlogging \" ..
我尝试过的事情:
- 在浏览器中输入路径即可(进入路径)
- 以cmd格式显示到此路径的效果也很好
其他信息:
- 代码无法更改(许多项目的通用基础)
推荐答案
如果使用提升的提示映射驱动器,则在非管理员帐户下该驱动器将不可见.
If you mapped the drive with an elevated prompt, it will be invisible under non-admin accounts.
您可以以管理员身份运行程序,也可以使用对管理员和非管理员帐户均可见的其他方法.这涉及将以下项添加到注册表中(将以下行复制/粘贴到"temp.reg"
文件中,然后双击它):
You can either run your program as an adminstrator, or use a different method which is visible to both admin and non-admin accounts. This involves adding the following key to the registry (copy/paste the following line into a "temp.reg"
file, and double-click it):
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]
"F:"="\\??\\C:"
其他好处是,这种方法在重新启动后是持久的.
Additional benefit is that this approach is persistent across reboots.
注意:如果您打算使用regedit.exe手动添加密钥,请不要转义反斜杠(即,将每个 \\
替换为 \
中的表达式),并且在这种情况下也没有引号(您可以在 DOS Devices
键中添加一个新的 String Value
,将名称设置为 F:
,并将数据存储到 \ ?? \ C:
)
Note: If you are planning to add the key manually using regedit.exe, do not escape the backslashes (i.e. replace each \\
with \
in the expression above), and there are no quotes in that case too (you would add a new String Value
to the DOS Devices
key, set name to F:
, and data to \??\C:
)
您还需要重新启动系统才能使它生效.
You also need to restart the system for this to take effect.
另外:我知道您写过代码无法更改,但是仍然要强调:使用配置文件而不是硬编码路径显然是任何应用程序的正确方法(或更简单的是放置日志)当前用户 AppData \ Local
文件夹中的某个位置).使用默认设置为 f:\ eventlogging
重建此公共基础不会破坏其他应用程序,但可以让您拥有这种灵活性.所有其他硬编码设置和整个代码中的幻数也是如此.所有日志记录框架都使用配置文件来配置其输出.
Also: I am aware you wrote that the code cannot be changed, but it should be emphasized nevertheless: using a config file instead of hard-coded paths would obviously be the right approach with any application (or even simpler, placing logs somewhere inside current users AppData\Local
folder). Rebuilding this common base with a default set to f:\eventlogging
wouldn't break other apps, but would allow you to have this flexibility. Same goes for all other hard-coded settings and magic numbers across your code. All logging frameworks use config files to configure their outputs.
这篇关于System.IO未找到通过subst命令生成的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!