REGEDIT.exe

来源:互联网 发布:译林出版社知乎 编辑:程序博客网 时间:2024/04/28 22:15
 

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

    REGEDIT.EXE

Import (merge) a .REG file:

    REGEDIT.EXE  [ /L:system ¦ /R:user ]  [ /S ]  importfile.REG

    REGEDIT.EXE  [ /L:system ¦ /R:user ]  [ /S ]  importfile.REG

Export to a (.REG) file:

    REGEDIT.EXE  [ /L:system ¦ /R:user ]    /E    exportfile   "registry_key"

    REGEDIT.EXE  [ /L:system ¦ /R:user ]    /E    exportfile   "registry_key"

Compress the registry (Windows 98 only):

    REGEDIT.EXE  [ /L:system ¦ /R:user ]    /C

    REGEDIT.EXE  [ /L:system ¦ /R:user ]    /C

Parameters:

    importfile.REG     .REG file to be imported (or "merged")    exportfile         File name the information should be written to    "registry_key"     Registry key to be exported                       e.g. "HKEY_CLASSES/ROOT/*/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)

    importfile.REG     .REG file to be imported (or "merged")    exportfile         File name the information should be written to    "registry_key"     Registry key to be exported                       e.g. "HKEY_CLASSES/ROOT/*/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 and later, REG.EXE is a native command.
REG.EXE can read a single key and value directly, without the need for a temporary file.
Click here to 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

REGEDIT /S addsome.REG
The /S swith is optional, it skips the message dialogs before and after the import of the *.REG file.

Since .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.

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_USER/DummyTree]

REGEDIT4[-HKEY_CURRENT_USER/DummyTree]
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_USER/DummyTree]"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.

More info can be found at Regedit.com's Registry FAQ.

How to remove an individual registry key or value using *.INF files and RUNDLL is explained here 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:/path/filename.REG "HKEY_XXXX/Whatever Key"

REGEDIT /E d:/path/filename.REG "HKEY_XXXX/Whatever Key"
This will write the registry key "HKEY_XXXX/Whatever Key" and its subkeys to a file named d:/path/filename.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.

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_XXXX/Whatever Key"

REGEDIT /E PRN "HKEY_XXXX/Whatever 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.

Examples

Windows 95/98

A fine example of reading the registry in Windows 95/98 is CDROM.BAT, which also demonstrates the use of CHOICE to strip characters (in this case the quotes) from a string.

All Win32 Versions

The following batch file, DEFOPEN.BAT, will create a temporary .REG file and then use REGEDIT to merge it.
Running this batch file once (!) will create a default association to Notepad.exe (double-clicking a file without a file association will open the file in Notepad) and add three menu entries to the right mouse button menu: "Open with Notepad", "Print with Notepad" and "Command Prompt Here". The latter will be shown, no matter wether a file or directory is clicked.
[Notepad registry tip courtesy of Regedit.com]

@ECHO OFF:: No parameters requiredIF NOT [%1]==[] GOTO Syntax:: Choose the correct command processor for the current operating systemSET _cmd=:: Variable to add shortcut to menu entry (NT only,:: since COMMAND.COM cannot echo an ampersand)SET _=ECHO.%COMSPEC% ¦ FIND /I "command.com" >NULIF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096ECHO.%COMSPEC% ¦ FIND /I "cmd.exe" >NULIF NOT ERRORLEVEL 1 SET _cmd=cmd.exeIF [%_cmd%]==[cmd.exe] SET _=^&:: Create a temporary .REG file> "%Temp%./DefOpen.reg" ECHO REGEDIT4>>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Open with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open]>>"%Temp%./DefOpen.reg" ECHO @="%_%Open with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Print with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print]>>"%Temp%./DefOpen.reg" ECHO @="%_%Print with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /p /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: If neither COMMAND.COM nor CMD.EXE then skip this stepIF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entryIF [%_cmd%]==[] GOTO MergeECHO Adding "Command Prompt Here" entry:: Add Command Prompt Here for files>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1//../"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for directories>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for drives>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Merge the temporary .REG file:MergeSTART /WAIT REGEDIT /S "%Temp%./DefOpen.reg":: Delete the temporary .REG fileDEL "%Temp%./DefOpen.reg":: ReadyGOTO End:SyntaxECHO.ECHO DefOpen.bat,  Version 3.00 for Windows 95/98/NT 4/2000/XPECHO Adds a default association: when a file without a file associationECHO is double-clicked, it will be opened with Notepad.ECHO Adds three new entries to the right mouse button menu as well:ECHO "Open with Notepad", "Print with Notepad" and "Command Prompt Here".ECHO.ECHO Usage:  DEFOPENECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.comECHO Notepad registry tip courtesy of Regedit.comECHO http://www.regedit.com:: Clean up variables and quit:EndSET _cmd=SET _=

Regedit.com]
@ECHO OFF:: No parameters requiredIF NOT [%1]==[] GOTO Syntax:: Choose the correct command processor for the current operating systemSET _cmd=:: Variable to add shortcut to menu entry (NT only,:: since COMMAND.COM cannot echo an ampersand)SET _=ECHO.%COMSPEC% ¦ FIND /I "command.com" >NULIF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096ECHO.%COMSPEC% ¦ FIND /I "cmd.exe" >NULIF NOT ERRORLEVEL 1 SET _cmd=cmd.exeIF [%_cmd%]==[cmd.exe] SET _=^&:: Create a temporary .REG file> "%Temp%./DefOpen.reg" ECHO REGEDIT4>>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Open with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open]>>"%Temp%./DefOpen.reg" ECHO @="%_%Open with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Print with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print]>>"%Temp%./DefOpen.reg" ECHO @="%_%Print with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /p /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: If neither COMMAND.COM nor CMD.EXE then skip this stepIF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entryIF [%_cmd%]==[] GOTO MergeECHO Adding "Command Prompt Here" entry:: Add Command Prompt Here for files>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1//../"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for directories>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for drives>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Merge the temporary .REG file:MergeSTART /WAIT REGEDIT /S "%Temp%./DefOpen.reg":: Delete the temporary .REG fileDEL "%Temp%./DefOpen.reg":: ReadyGOTO End:SyntaxECHO.ECHO DefOpen.bat,  Version 3.00 for Windows 95/98/NT 4/2000/XPECHO Adds a default association: when a file without a file associationECHO is double-clicked, it will be opened with Notepad.ECHO Adds three new entries to the right mouse button menu as well:ECHO "Open with Notepad", "Print with Notepad" and "Command Prompt Here".ECHO.ECHO Usage:  DEFOPENECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.comECHO Notepad registry tip courtesy of Regedit.comECHO http://www.regedit.com:: Clean up variables and quit:EndSET _cmd=SET _=
^&:: Create a temporary .REG file> "%Temp%./DefOpen.reg" ECHO REGEDIT4>>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Open with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open]>>"%Temp%./DefOpen.reg" ECHO @="%_%Open with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/open/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.ECHO Adding "Print with Notepad" entry>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print]>>"%Temp%./DefOpen.reg" ECHO @="%_%Print with Notepad">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/print/command]>>"%Temp%./DefOpen.reg" ECHO @="notepad.exe /p /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: If neither COMMAND.COM nor CMD.EXE then skip this stepIF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entryIF [%_cmd%]==[] GOTO MergeECHO Adding "Command Prompt Here" entry:: Add Command Prompt Here for files>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/*/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1//../"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for directories>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Directory/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Add Command Prompt Here for drives>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt]>>"%Temp%./DefOpen.reg" ECHO @="Command Prompt Here">>"%Temp%./DefOpen.reg" ECHO.>>"%Temp%./DefOpen.reg" ECHO [HKEY_CLASSES_ROOT/Drive/shell/prompt/command]>>"%Temp%./DefOpen.reg" ECHO @="%_cmd% /k cd /"%%1/"">>"%Temp%./DefOpen.reg" ECHO.:: Merge the temporary .REG file:MergeSTART /WAIT REGEDIT /S "%Temp%./DefOpen.reg":: Delete the temporary .REG fileDEL "%Temp%./DefOpen.reg":: ReadyGOTO End:SyntaxECHO.ECHO DefOpen.bat, Version 3.00 for Windows 95/98/NT 4/2000/XPECHO Adds a default association: when a file without a file associationECHO is double-clicked, it will be opened with Notepad.ECHO Adds three new entries to the right mouse button menu as well:ECHO "Open with Notepad", "Print with Notepad" and "Command Prompt Here".ECHO.ECHO Usage: DEFOPENECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.comECHO Notepad registry tip courtesy of Regedit.comECHO http://www.regedit.com:: Clean up variables and quit:EndSET _cmd=SET _=

 

The following example deletes a file and a registry entry to force Intel LANDesk agent software to create a new unique ID.
Run it once on any PC containing Intel's LANDesk agent software that was installed using any "disk cloning" technique (like Norton Ghost, PowerQuest's Drive Image, or tape backups).

@ECHO OFF:: No command line parameters requiredIF NOT "%1"=="" GOTO Syntax:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :::: Adjust the LANDesk server name and the drive and directory if necessary :::: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::SET LANDeskServer=MyLDServerC:CD/LDClientECHO Removing old LANDesk agent ID:: Delete old ID file (adjust drive if necessary)IF EXIST C:/LDIScan.cfg ATTRIB -h -r -s C:/LDIScan.cfgIF EXIST C:/LDIScan.cfg DEL C:/LDIScan.cfg:: Delete old ID from the registry (Local Machine):: Create a temporary REG file> %TEMP%./UniqueID.reg ECHO REGEDIT4>>%TEMP%./UniqueID.reg ECHO.>>%TEMP%./UniqueID.reg ECHO [HKEY_LOCAL_MACHINE/SOFTWARE/Intel/LANDesk/Common Api]>>%TEMP%./UniqueID.reg ECHO "UniqueID"=->>%TEMP%./UniqueID.reg ECHO.:: Check if previous ID was stored for Current User and if so, delete itIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGREGEDIT /E %TEMP%./_Unique_.REG "HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1IF ERRORLEVEL 1 GOTO Next>>%TEMP%./UniqueID.reg ECHO [HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32]>>%TEMP%./UniqueID.reg ECHO "Last Device ID"=->>%TEMP%./UniqueID.reg ECHO.:: Repeat for Default User:NextIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGREGEDIT /E %TEMP%./_Unique_.REG "HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1IF ERRORLEVEL 1 GOTO MergeDEL %TEMP%./_Unique_.REG>>%TEMP%./UniqueID.reg ECHO [HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32]>>%TEMP%./UniqueID.reg ECHO "Last Device ID"=->>%TEMP%./UniqueID.reg ECHO.:: Merge (import) the REG file to delete the UniqueID entry:MergeREGEDIT /S %TEMP%./UniqueID.reg:: Delete the temporary REG fileDEL %TEMP%./UniqueID.regECHO Creating new LANDesk agent ID:: Start inventory scan to create new IDLDISCN32.EXE /NTT=%LANDeskServer%:5007 /S="%LANDeskServer%" /I=//%LANDeskServer%/LDLOGON/ldappl.ini /VECHO DoneIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGSET LANDeskServer=CD/GOTO End:SyntaxECHO UniqueID.bat,  Version 2.00 for 32-bit WindowsECHO Create a new unique ID for Intel LANDesk agentECHO.ECHO If a computer is installed using a harddisk image (like Norton GhostECHO or PowerQuest's Drive Image) all "clones" will have the same LANDeskECHO agent ID if LANDesk agent was installed when the image was created.ECHO However, the LANDesk agent needs a unique ID to function properly.ECHO You can force a new ID by reinstalling the LANDesk agent software,ECHO but running this batch file can force a new unique ID just as well.ECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.com:End

@ECHO OFF:: No command line parameters requiredIF NOT "%1"=="" GOTO Syntax:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :::: Adjust the LANDesk server name and the drive and directory if necessary :::: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::SET LANDeskServer=MyLDServerC:CD/LDClientECHO Removing old LANDesk agent ID:: Delete old ID file (adjust drive if necessary)IF EXIST C:/LDIScan.cfg ATTRIB -h -r -s C:/LDIScan.cfgIF EXIST C:/LDIScan.cfg DEL C:/LDIScan.cfg:: Delete old ID from the registry (Local Machine):: Create a temporary REG file> %TEMP%./UniqueID.reg ECHO REGEDIT4>>%TEMP%./UniqueID.reg ECHO.>>%TEMP%./UniqueID.reg ECHO [HKEY_LOCAL_MACHINE/SOFTWARE/Intel/LANDesk/Common Api]>>%TEMP%./UniqueID.reg ECHO "UniqueID"=->>%TEMP%./UniqueID.reg ECHO.:: Check if previous ID was stored for Current User and if so, delete itIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGREGEDIT /E %TEMP%./_Unique_.REG "HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1IF ERRORLEVEL 1 GOTO Next>>%TEMP%./UniqueID.reg ECHO [HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32]>>%TEMP%./UniqueID.reg ECHO "Last Device ID"=->>%TEMP%./UniqueID.reg ECHO.:: Repeat for Default User:NextIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGREGEDIT /E %TEMP%./_Unique_.REG "HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1IF ERRORLEVEL 1 GOTO MergeDEL %TEMP%./_Unique_.REG>>%TEMP%./UniqueID.reg ECHO [HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32]>>%TEMP%./UniqueID.reg ECHO "Last Device ID"=->>%TEMP%./UniqueID.reg ECHO.:: Merge (import) the REG file to delete the UniqueID entry:MergeREGEDIT /S %TEMP%./UniqueID.reg:: Delete the temporary REG fileDEL %TEMP%./UniqueID.regECHO Creating new LANDesk agent ID:: Start inventory scan to create new IDLDISCN32.EXE /NTT=%LANDeskServer%:5007 /S="%LANDeskServer%" /I=//%LANDeskServer%/LDLOGON/ldappl.ini /VECHO DoneIF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REGSET LANDeskServer=CD/GOTO End:SyntaxECHO UniqueID.bat,  Version 2.00 for 32-bit WindowsECHO Create a new unique ID for Intel LANDesk agentECHO.ECHO If a computer is installed using a harddisk image (like Norton GhostECHO or PowerQuest's Drive Image) all "clones" will have the same LANDeskECHO agent ID if LANDesk agent was installed when the image was created.ECHO However, the LANDesk agent needs a unique ID to function properly.ECHO You can force a new ID by reinstalling the LANDesk agent software,ECHO but running this batch file can force a new unique ID just as well.ECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.com:End

NT 4

The following example, COUNTRY3.BAT for Windows NT 4, clearly demonstrates how to read registry settings using REGEDIT:

@ECHO OFF:: Country.bat, Version 3.00 for Windows NT 4:: Displays several country related settings.:: This version uses native NT 4 commands only.:: Written by Rob van der Woude:: http://www.robvanderwoude.com:: Keyboard trick by Tom Lavedas:: http://my.fcc.net/~tglbatch/:: Export International settings from registry to a temporary fileSTART /W REGEDIT /E %Temp%./international.reg "HKEY_CURRENT_USER/Control Panel/International":: Read several lines from the temporary files:: and store these settings as environment variablesFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "iCountry"') DO SET iCountry=%%BSET iCountry=%iCountry:"=%SET iCountryFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sCountry"') DO SET sCountry=%%BSET sCountry=%sCountry:"=%SET sCountryFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sLanguage"') DO SET sLanguage=%%BSET sLanguage=%sLanguage:"=%SET sLanguage:: Remove temporary fileDEL %Temp%./international.reg:: The KEYB trick was posted to the alt.msdos.batch.nt newsgroup by Tom LavedasFOR /F "tokens=1* delims=:" %%A IN ('KEYB ^¦ FIND ":" ^¦ FIND /V "CON"') DO SET Keyboard=%%BSET Keyboard=%Keyboard:~1%SET Keyboard:: Check code page usedFOR /F "tokens=1* delims=:" %%A IN ('CHCP') DO SET /A CodePage = %%BSET CodePage

@ECHO OFF:: Country.bat, Version 3.00 for Windows NT 4:: Displays several country related settings.:: This version uses native NT 4 commands only.:: Written by Rob van der Woude:: http://www.robvanderwoude.com:: Keyboard trick by Tom Lavedas:: http://my.fcc.net/~tglbatch/:: Export International settings from registry to a temporary fileSTART /W REGEDIT /E %Temp%./international.reg "HKEY_CURRENT_USER/Control Panel/International":: Read several lines from the temporary files:: and store these settings as environment variablesFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "iCountry"') DO SET iCountry=%%BSET iCountry=%iCountry:"=%SET iCountryFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sCountry"') DO SET sCountry=%%BSET sCountry=%sCountry:"=%SET sCountryFOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sLanguage"') DO SET sLanguage=%%BSET sLanguage=%sLanguage:"=%SET sLanguage:: Remove temporary fileDEL %Temp%./international.reg:: The KEYB trick was posted to the alt.msdos.batch.nt newsgroup by Tom LavedasFOR /F "tokens=1* delims=:" %%A IN ('KEYB ^¦ FIND ":" ^¦ FIND /V "CON"') DO SET Keyboard=%%BSET Keyboard=%Keyboard:~1%SET Keyboard:: Check code page usedFOR /F "tokens=1* delims=:" %%A IN ('CHCP') DO SET /A CodePage = %%BSET CodePage

  

The following example, GETRES.BAT (Version 3.00) for Windows NT 4/2000, also demonstrates how to read and parse registry settings using REGEDIT:

@ECHO OFF:: No command line parameters pleaseIF NOT [%1]==[] GOTO Syntax:: Verify OS versionIF NOT "%OS%"=="Windows_NT" GOTO Syntax:: Keep variables localSETLOCAL:: Set initial valuesSET VideoCard=SET XResolution=SET YResolution=SET BitsPerPel=SET VRefresh=:: Read relevant registry entries and store them in a temporary REG fileREGEDIT /E "%Temp%./Screen.reg" "HKEY_CURRENT_CONFIG/System/CurrentControlSet/Services":: Process the temporary REG fileFOR /F "tokens=* delims=" %%A IN ('TYPE %Temp%./Screen.reg ^¦ FIND /V "REGEDIT4" ^¦ FIND /V ""') DO CALL :Parse01 %%A:: Display resultsECHO.SET VideoCardSET XResolutionSET YResolutionSET BitsPerPelSET VRefresh:: Remove temporary fileIF EXIST "%Temp%./Screen.reg" DEL "%Temp%./Screen.reg":: DoneENDLOCALGOTO:EOF:Parse01:: If this is the second card's entry, and the:: first one was NOT VGA save mode, then quitIF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF:: Read subroutine's command line parameters as one lineSET Line=%*:: Remove quotes from the lineSET Line=%Line:"=%:: Remove spaces from the lineSET Line=%Line: =%:: Check for and parse video card short nameIF "%Line:~0,6%"=="[HKEY_" FOR /F "tokens=5 delims=/]" %%A IN ('ECHO.%Line%') DO IF NOT "%%A"=="" SET NewCard=%%A:: If this is the second card's entry, and the:: first one was NOT VGA save mode, then quitIF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF:: If not, then save the new video adapter short nameSET VideoCard=%NewCard%:: Parse all "key=value" linesFOR /F "tokens=1* delims==" %%A IN ('ECHO.%Line%') DO CALL :Parse02 %%A %%B:: End of subroutine Parse01GOTO:EOF:Parse02:: Quit if either key or value aren't specifiedIF "%2"=="" GOTO:EOF:: %1 is keySET InKey=%1:: %2 is valueSET InValue=%2:: Remove "Defaultvalue." prefix from keyFOR /F "tokens=2 delims=." %%a IN ('ECHO.%InKey%') DO SET Key=%%a:: Continue only for these 4 keys, quit otherwiseIF /I NOT "%Key%"=="BitsPerPel" IF /I NOT "%Key%"=="XResolution" IF /I NOT "%Key%"=="YResolution" IF /I NOT "%Key%"=="VRefresh" GOTO:EOF:: Parse value to check if it is a dword valueFOR /F "tokens=1,2 delims=:" %%a IN ('ECHO.%InValue%') DO (SET dWord=%%aSET xValue=%%b):: If so, convert hexadecimal value to decimalIF /I "%dWord%"=="dword" (SET /A Value = 0X%xValue%) ELSE (SET Value=%dWord%):: Store the resultSET %Key%=%Value%:: End of subroutine Parse02GOTO:EOF:SyntaxECHO.ECHO GetRes.bat,  Version 3.00 for Windows NT 4 / 2000ECHO Read and display video resolution settings from the registryECHO.ECHO Usage:  GETRESECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.comECHO.

@ECHO OFF:: No command line parameters pleaseIF NOT [%1]==[] GOTO Syntax:: Verify OS versionIF NOT "%OS%"=="Windows_NT" GOTO Syntax:: Keep variables localSETLOCAL:: Set initial valuesSET VideoCard=SET XResolution=SET YResolution=SET BitsPerPel=SET VRefresh=:: Read relevant registry entries and store them in a temporary REG fileREGEDIT /E "%Temp%./Screen.reg" "HKEY_CURRENT_CONFIG/System/CurrentControlSet/Services":: Process the temporary REG fileFOR /F "tokens=* delims=" %%A IN ('TYPE %Temp%./Screen.reg ^¦ FIND /V "REGEDIT4" ^¦ FIND /V ""') DO CALL :Parse01 %%A:: Display resultsECHO.SET VideoCardSET XResolutionSET YResolutionSET BitsPerPelSET VRefresh:: Remove temporary fileIF EXIST "%Temp%./Screen.reg" DEL "%Temp%./Screen.reg":: DoneENDLOCALGOTO:EOF:Parse01:: If this is the second card's entry, and the:: first one was NOT VGA save mode, then quitIF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF:: Read subroutine's command line parameters as one lineSET Line=%*:: Remove quotes from the lineSET Line=%Line:"=%:: Remove spaces from the lineSET Line=%Line: =%:: Check for and parse video card short nameIF "%Line:~0,6%"=="[HKEY_" FOR /F "tokens=5 delims=/]" %%A IN ('ECHO.%Line%') DO IF NOT "%%A"=="" SET NewCard=%%A:: If this is the second card's entry, and the:: first one was NOT VGA save mode, then quitIF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF:: If not, then save the new video adapter short nameSET VideoCard=%NewCard%:: Parse all "key=value" linesFOR /F "tokens=1* delims==" %%A IN ('ECHO.%Line%') DO CALL :Parse02 %%A %%B:: End of subroutine Parse01GOTO:EOF:Parse02:: Quit if either key or value aren't specifiedIF "%2"=="" GOTO:EOF:: %1 is keySET InKey=%1:: %2 is valueSET InValue=%2:: Remove "Defaultvalue." prefix from keyFOR /F "tokens=2 delims=." %%a IN ('ECHO.%InKey%') DO SET Key=%%a:: Continue only for these 4 keys, quit otherwiseIF /I NOT "%Key%"=="BitsPerPel" IF /I NOT "%Key%"=="XResolution" IF /I NOT "%Key%"=="YResolution" IF /I NOT "%Key%"=="VRefresh" GOTO:EOF:: Parse value to check if it is a dword valueFOR /F "tokens=1,2 delims=:" %%a IN ('ECHO.%InValue%') DO (SET dWord=%%aSET xValue=%%b):: If so, convert hexadecimal value to decimalIF /I "%dWord%"=="dword" (SET /A Value = 0X%xValue%) ELSE (SET Value=%dWord%):: Store the resultSET %Key%=%Value%:: End of subroutine Parse02GOTO:EOF:SyntaxECHO.ECHO GetRes.bat,  Version 3.00 for Windows NT 4 / 2000ECHO Read and display video resolution settings from the registryECHO.ECHO Usage:  GETRESECHO.ECHO Written by Rob van der WoudeECHO http://www.robvanderwoude.comECHO.

  

More examples, dealing with printing various file types, can be found here.

printing various file types, can be found here.

A great tool to create VBScript scripts that can modify the registry is the Tweakomatic by the Scripting Guys.

An overview of Registry Entries for Printing.

 

原创粉丝点击