使用PowerShell,您可以运行这样的命令
ni c:/foo/bar -type directory
它将根据需要创建foo
和bar
。但是,如果您运行
ni hklm:software/classes/firefoxhtml/shell/edit/command -type directory
除最后一个密钥外的所有密钥都必须存在,否则将生成错误。PowerShell 能否根据需要生成父密钥?
我只是缺少-force
参数
New-Item hklm:software/classes/firefoxhtml/shell/edit/command -Force
使用-Force
还将删除密钥下的所有内容(如果它已经存在),因此更好的选择
if(!(Test-Path $path)){
New-Item $path -Force;
}