关于注册表:PowerShell:如何使用标准输出代替文件名 | 珊瑚贝

PowerShell: How To Use Standard Output In Place of Filename


我正在编写一个运行进程 (REG) 以导出注册表项的 C# 类。 REG 要求您指定要导出到的文件名,但我宁愿将 REG 的输出定向到标准输出,以便可以直接在我的 C# 代码中捕获它(使用 Process.StandardOutput)。 PowerShell 中有没有办法将标准输出指定为文件名?


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

1
2
3
4
$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,您可以导航注册表,就像它是文件系统的一部分一样。也许这在其他方面有帮助?

1
2
cd HKCU:\\Software\\Microsoft\\Windows
dir

只需使用 ‘CONOUT$’ 作为文件名(正如注释中指出的那样,这仅适用于 Windows XP):

1
2
3
4
5
6
7
8
PS C:\\> reg export HKLM\\SOFTWARE\\FileZilla ‘CONOUT$’
 W i n d o w s   R e g i s t r y   E d i t o r   V e r s i o n   5 . 0 0

 [ H K E Y _ L O C A L _ M A C H I N E \\ S O F T W A R E \\ F i l e Z i l l a ]
” I n s t a l l _ D i r” =” C : \\ \\ P r o g r a m   F i l e s \\ \\ F i l e Z i l l a”
” R u n   i n   S e c u r e   M o d e” =” 0″
” U s e   R e g i s t r y” =” 0″
” L a n g u a g e” =” E n g l i s h”

这里显示的输出中有一些 UNICODE 编码问题,但是当您解析它时,您应该能够在缓冲区中处理它。

  • 有趣的提示,但它在 Win7 或 Server2003 上对我不起作用(我可以测试所有这些)。我收到此错误… 错误:无法写入文件。可能存在磁盘或文件系统错误。
  • 也不为我工作。我收到与上面相同的消息(错误:无法写入文件。可能存在磁盘或文件系统错误)。
  • 当我在 XP (SP3) 上进行测试时,它似乎工作正常。我在 Server2003 上也失败了。看起来 Reg 已更新,这打破了窍门。


来源:https://www.codenong.com/3885505/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9130.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?