virt-win-reg(1) | Virtualization Support | virt-win-reg(1) |
virt-win-reg - Windows 仮想マシンからの Windows レジストリエントリーのエクスポートおよびマージ
virt-win-reg domname 'HKLM\Path\To\Subkey' virt-win-reg domname 'HKLM\Path\To\Subkey' name virt-win-reg domname 'HKLM\Path\To\Subkey' @ virt-win-reg --merge domname [input.reg ...] virt-win-reg [--options] disk.img ... # 仮想マシン名の代わり
You must not use "virt-win-reg" with the --merge option on live virtual machines. If you do this, you will get irreversible disk corruption in the VM. "virt-win-reg" tries to stop you from doing this, but doesn't catch all cases.
Modifying the Windows Registry is an inherently risky operation. The format is deliberately obscure and undocumented, and Registry changes can leave the system unbootable. Therefore when using the --merge option, make sure you have a reliable backup first.
このプログラムは Windows 仮想マシンから Windows レジストリのエントリーをエクスポートおよびマージできます。
第一パラメーターは Windows 仮想マシンの libvirt 仮想マシン名または生のディスクイメージです。
If --merge is not specified, then the chosen registry key is displayed/exported (recursively). For example:
$ virt-win-reg Windows7 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft'
You can also display single values from within registry keys, for example:
$ cvkey='HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion' $ virt-win-reg Windows7 $cvkey ProductName Windows 7 Enterprise
--merge を用いると、テキストの regedit ファイルを Windows レジストリーの中に結合できます:
$ virt-win-reg --merge Windows7 changes.reg
This program is only meant for simple access to the registry. If you want to do complicated things with the registry, we suggest you download the Registry hive files from the guest using libguestfs(3) or guestfish(1) and access them locally, eg. using hivex(3), hivexsh(1) or hivexregedit(1).
仮想マシンのブロックデバイスを直接指定すると、libvirt はまったく使用されません。
If disk images are requested from libvirt, then this program asks libvirt for this information. In this case, the value of the format parameter is ignored.
If working with untrusted raw-format guest disk images, you should ensure the format is always specified.
Note that --merge is unsafe to use on live virtual machines, and will result in disk corruption. However exporting (without this flag) is always safe.
The default is to use UTF-16LE, which should work with recent versions of Windows.
This is unsafe and does not preserve the fidelity of strings in the original Registry for various reasons:
This all happens because the Registry itself contains no information about how strings are encoded (see "ENCODING STRINGS" in Win::Hivex::Regedit(3)).
You should only use this option for quick hacking and debugging of the Registry contents, and never use it if the output is going to be passed into another program or stored in another Registry.
The program currently supports Windows NT-derived guests starting with Windows XP through to at least Windows 8.
以下のレジストリキーがサポートされます:
You can use "HKLM" as a shorthand for "HKEY_LOCAL_MACHINE", and "HKU" for "HKEY_USERS".
The literal keys "HKEY_USERS\$SID" and "HKEY_CURRENT_USER" are not supported (there is no "current user").
Windows 8 "fast startup" can prevent virt-win-reg from being able to edit the Registry. See "WINDOWS HIBERNATION AND WINDOWS 8 FAST STARTUP" in guestfs(3).
"virt-win-reg" expects that regedit files have already been reencoded in the local encoding. Usually on Linux hosts, this means UTF-8 with Unix-style line endings. Since Windows regedit files are often in UTF-16LE with Windows-style line endings, you may need to reencode the whole file before or after processing.
To reencode a file from Windows format to Linux (before processing it with the --merge option), you would do something like this:
iconv -f utf-16le -t utf-8 < win.reg | dos2unix > linux.reg
To go in the opposite direction, after exporting and before sending the file to a Windows user, do something like this:
unix2dos linux.reg | iconv -f utf-8 -t utf-16le > win.reg
エンコーディングの詳細は Win::Hivex::Regedit(3) を参照してください。
If you are unsure about the current encoding, use the file(1) command. Recent versions of Windows regedit.exe produce a UTF-16LE file with Windows-style (CRLF) line endings, like this:
$ file software.reg software.reg: Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminators
This file would need conversion before you could --merge it.
Registry keys like "CurrentControlSet" don’t really exist in the Windows Registry at the level of the hive file, and therefore you cannot modify these.
"CurrentControlSet" is usually an alias for "ControlSet001". In some circumstances it might refer to another control set. The way to find out is to look at the "HKLM\SYSTEM\Select" key:
# virt-win-reg WindowsGuest 'HKLM\SYSTEM\Select' [HKEY_LOCAL_MACHINE\SYSTEM\Select] "Current"=dword:00000001 "Default"=dword:00000001 "Failed"=dword:00000000 "LastKnownGood"=dword:00000002
"Current" is the one which Windows will choose when it boots.
Similarly, other "Current..." keys in the path may need to be replaced.
レジストリキー全体を削除するには、この構文を使用します:
[-HKEY_LOCAL_MACHINE\Foo]
キーにある単一の値を削除するには、この構文を使用します:
[HKEY_LOCAL_MACHINE\Foo] "Value"=-
Note that some of these tips modify the guest disk image. The guest must be shut off, else you will get disk corruption.
Prepare a DOS batch script, VBScript or executable. Upload this using guestfish(1). For this example the script is called "test.bat" and it is uploaded into "C:\":
guestfish -i -d WindowsGuest upload test.bat /test.bat
Prepare a regedit file containing the registry change:
cat > test.reg <<'EOF' [HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce] "Test"="c:\\test.bat" EOF
In this example we use the key "RunOnce" which means that the script will run precisely once when the first user logs in. If you want it to run every time a user logs in, replace "RunOnce" with "Run".
Now update the registry:
virt-win-reg --merge WindowsGuest test.reg
This section assumes you are familiar with Windows services, and you either have a program which handles the Windows Service Control Protocol directly or you want to run any program using a service wrapper like SrvAny or the free RHSrvAny.
First upload the program and optionally the service wrapper. In this case the test program is called "test.exe" and we are using the RHSrvAny wrapper:
guestfish -i -d WindowsGuest <<EOF upload rhsrvany.exe /rhsrvany.exe upload test.exe /test.exe EOF
Prepare a regedit file containing the registry changes. In this example, the first registry change is needed for the service itself or the service wrapper (if used). The second registry change is only needed because I am using the RHSrvAny service wrapper.
cat > service.reg <<'EOF' [HKLM\SYSTEM\ControlSet001\services\RHSrvAny] "Type"=dword:00000010 "Start"=dword:00000002 "ErrorControl"=dword:00000001 "ImagePath"="c:\\rhsrvany.exe" "DisplayName"="RHSrvAny" "ObjectName"="NetworkService" [HKLM\SYSTEM\ControlSet001\services\RHSrvAny\Parameters] "CommandLine"="c:\\test.exe" "PWD"="c:\\Temp" EOF
注:
レジストリを更新します:
virt-win-reg --merge WindowsGuest service.reg
シェルにおいて "\" (backslash) を含むパラメーターを渡すとき、注意する必要があります。通常シェルからそれらを保護するには、'単一引用符' または二つのバックスラッシュ (しかし、両方ではない) を使用する必要があります。
パスおよび値の名前は大文字小文字を区別します。
hivex(3), hivexsh(1), hivexregedit(1), guestfs(3), guestfish(1), virt-cat(1), virt-tail(1), Sys::Guestfs(3), Win::Hivex(3), Win::Hivex::Regedit(3), Sys::Virt(3), http://libguestfs.org/.
Richard W.M. Jones http://people.redhat.com/~rjones/
Copyright (C) 2010 Red Hat Inc.
To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
When reporting a bug, please supply:
2022-05-26 | guestfs-tools-1.48.2 |