2009年4月11日 星期六

REGEDIT 語法(轉載)

 在網路上剛好找關於 Regedit.exe 參數的文章,為了日後寫批次檔方便,就將它轉貼進來。

REGEDIT


Warning:Before tweaking the registry, make sure you have a full backup of your system. If anything goes wrong, you may end up losing all your data and reinstalling Windows.
As Microsoft states it, editing the registry "... is not supported by Microsoft. Use this method at your own risk."

Windows NT (and 2000) users, read Microsoft's Knowledge Base article Q318149 to learn How to Maintain Current Registry Backups in Windows NT 4.0 and Windows 2000.





General Syntax:


GUI mode:

REGEDIT.EXE
Import (merge) a .REG file:
REGEDIT.EXE [ /L:system | /R:user ] [ /S ] importfile.REG
Export to a (.REG) file:
REGEDIT.EXE [ /L:system | /R:user ] /E exportfile "registry_key"
Compress the registry (Windows 98 only):
REGEDIT.EXE [ /L:system | /R:user ] /C

Parameters:
importfile.REG
.REG file to be imported (or "merged")
exportfile.REG
File name the information should be written to
"registry_key"
Registry key to be exported, e.g. "HKEY_CLASSESROOT*shell"
/S
Silent, i.e. hide confirmation box when importing files
/E
Export registry file
/L:system
Specify the location of the system.dat to use
/R:user
Specify the location of the user.dat to use
/C
Compress [filename] (Windows 98 only)
REGEDIT is usually known as a GUI tool to search or edit the Windows registry.
I would not have mentioned it here, however, if it couldn't be used in unattended mode as well.
This page focuses on reading and editing the registry in unattended mode only.
Microsoft's NT 4 Workstation and Server Resource Kits come with REG.EXE, a utility that makes reading (or editing) NT's registry easier.
In Windows 2000, REG.EXE is available on the installation CD-ROM, but has to be installed manually (on the CD-ROM run "SUPPORTTOOLSSETUP.EXE").
As of Windows XP, REG.EXE is a native command.
REG.EXE can read a single key and value directly, without the need for a temporary file.
Learn more about using REG.EXE.




Adding and editing (importing) registry entries

Adding items to the registry requires a *.REG file:
REGEDIT [ /S ] addsome.REG
The /S swith is optional, it skips the message dialogs before and after the import of the *.REG file.
Since NT 4 .REG files are in readable ASCII, they may be created "on the fly" by our batch files.
This is demonstrated in the DefOpen example in the Examples section.
Owners of a copy of the NT 4 Resource Kit or Windows 2000/XP/Server 2003 can also use REG.EXE to add or edit registry entries.



Removing registry entries

To remove an entire "tree" from the registry using REGEDIT and a .REG file, just add a minus sign before the tree name:
REGEDIT4

[-HKEY_CURRENT_USERDummyTree]
will remove the entire tree "DummyTree".
To remove an individual item from the registry, place the minus sign after the equal sign:
REGEDIT4

[HKEY_CURRENT_USERDummyTree]
"ValueToBeRemoved"=-
will remove the individual value "ValueToBeRemoved" from "DummyTree".
This is demonstrated in the uniqueid.bat example below, a batch file that forces a new LANDesk agent ID.
How to remove an individual registry key or value using *.INF files and RUNDLL is explained by Bill James.
NT 4 users who own a copy of the NT 4 Resource Kit can also use REG.EXE to remove registry entries.
In Windows 2000 and later REG.EXE is a native tool.


Reading (exporting) from the registry


REGEDIT's /E switch can be used to export a registry key:
REGEDIT /E d:pathfilename.REG "HKEY_XXXXWhatever Key"
This will write the registry key "HKEY_XXXXWhatever Key" and its subkeys to a file named d:pathfilename.REG
The resulting (ASCII or UniCode) file will contain the entries in the format "key"="value", which can be stripped and parsed using Laurence Soucy's CHOICE trick (How-to #4, second method) for MS-DOS 6 and Windows 9*, NT's FOR /F or the more generic TYPE and FIND commands.
Instead of a file name, some device names can be used:
REGEDIT /E PRN "HKEY_XXXXWhatever Key"
will print the selected key.
Unfortunately, this won't work for CON (console or display).
NT 4 users who own a copy of the NT 4 Resource Kit can also use REG.EXE to read the registry.
In Windows 2000 and later REG.EXE is a native tool.

資料參考來源:
http://www.robvanderwoude.com/regedit.php

沒有留言:

張貼留言