【发布时间】:2021-08-12 07:03:38
【问题描述】:
此技术的标准实现在:https://docs.microsoft.com/en-us/troubleshoot/windows-client/printing/add-print-directory-feature
不幸的是,它对我不起作用。 Printdir.bat 文件是:
@echo off
dir %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit
我的实现在 cmd 级别失败并出现错误:
文件名、目录名或卷标语法不正确”。 (程序继续执行,结果没有创建任何文件,因为没有向记事本传递任何内容)。
如果在 Windows 目录下运行,它运行良好。
在"%1" 周围添加引号没有帮助,"%~1" 也没有
【问题讨论】:
-
删除
@echo off并将exit替换为pause,然后在命令提示符窗口中查看%1扩展为... -
也应该将
start /w notepad替换为%SystemRoot%\notepad.exe。 -
我得到的是:\"C:\Users\Roger\Documents|自定义 Office 模板\"
-
我得到的是:C:WINDOWS\system32>dir \"C:\Users\Roger\Documents\Custom Office Templates\" /-p /o:gn 1>"C:\Users \Roger\AppData\Local\Temp\Listing" 则报错文件名、目录名或卷标语法不正确。那是我试图打印的目录。
-
看来问题是dir之后的\。也就是说, dir \"C:\Users\.... 应该是 dir "C:\Users\.... 但是,我不知道它来自哪里以及如何修复它。
标签: batch-file cmd windows-10 regedit