且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PowerShell:如何使用标准输出代替文件名

更新时间:2022-04-11 08:42:51

如果您必须使用 REG 程序(而不是使用 PowerShell 查询/转储注册表 - 甚至只是在 C# 程序本身中执行),可能***的办法是允许它转储到一个临时文件,然后将文件的内容通过管道传输回标准输出,并以这种方式在 C# 程序中捕获它:

If you have to use the REG program (rather than use PowerShell to query/dump the registry - or even just do it in the C# program itself), Probably the best you are going to get is to allow it to dump out to a temporary file, then pipe the contents of the file back to standard out and capture it in your C# program that way:

$guid = [Guid]::NewGuid().ToString("N")
REG EXPORT HKCU\Software\Microsoft\Windows "$env:temp\$guid" | Out-Null
Get-Content "$env:temp\$guid"
Remove-Item "$env:temp\$guid"

如果您不知道:使用 PowerShell,您可以导航注册表,就像它是文件系统的一部分一样.也许这在其他方面有帮助?

In case you were not aware: Using PowerShell, you can navigate the registry as though it were part of the file system. Perhaps this is helpful in some other regard?

cd HKCU:\Software\Microsoft\Windows
dir