这是 C# 代码。你能帮我把它翻译成powershell吗?
private static void Main(string[] args)
{
byte[] buffer = (byte[]) Registry.LocalMachine.OpenSubKey(@"HARDWARE\ACPI\DSDT\HP____\8510x\00010000").GetValue("00000000");
if (File.Exists("8510x.orig"))
{
Console.WriteLine("File 8510x.orig already exists.");
}
else
{
using (FileStream stream = new FileStream("8510x.orig", FileMode.CreateNew))
{
stream.Write(buffer, 0, buffer.Length);
stream.Flush();
stream.Close();
}
Console.WriteLine("Wrote 8510x.orig.");
}
}
最佳答案
您不想使用 Out-File,因为它以字符串形式输出并使用 unicode 启动。以下基于类似的注册表项工作:
$b = Get-ItemProperty HKLM:\HARDWARE\ACPI\DSDT\A7546\A7546011\00000011 00000000
$b.'00000000' | Set-Content foo.txt -enc byte
请注意,当您想要更直接地控制写入文件的内容时,尤其是在您想写入原始字节时,Set-Content 很有用。
关于.net - 我可以在 powershell 中执行此操作吗?读取注册表,将二进制内容写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1282138/