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

    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 required
IF NOT [%1]==[] GOTO Syntax

:: Choose the correct command processor for the current operating system
SET _cmd=
:: Variable to add shortcut to menu entry (NT only,
:: since COMMAND.COM cannot echo an ampersand)
SET _=
ECHO.%COMSPEC% ¦ FIND /I "command.com" >NUL
IF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096
ECHO.%COMSPEC% ¦ FIND /I "cmd.exe" >NUL
IF NOT ERRORLEVEL 1 SET _cmd=cmd.exe
IF [%_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 step
IF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entry
IF [%_cmd%]==[] GOTO Merge

ECHO 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
:Merge
START /WAIT REGEDIT /S "%Temp%./DefOpen.reg"

:: Delete the temporary .REG file
DEL "%Temp%./DefOpen.reg"

:: Ready
GOTO End

:Syntax
ECHO.
ECHO DefOpen.bat,  Version 3.00 for Windows 95/98/NT 4/2000/XP
ECHO Adds a default association: when a file without a file association
ECHO 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:  DEFOPEN
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Notepad registry tip courtesy of Regedit.com
ECHO http://www.regedit.com

:: Clean up variables and quit
:End
SET _cmd=
SET _=

Regedit.com]
@ECHO OFF
:: No parameters required
IF NOT [%1]==[] GOTO Syntax

:: Choose the correct command processor for the current operating system
SET _cmd=
:: Variable to add shortcut to menu entry (NT only,
:: since COMMAND.COM cannot echo an ampersand)
SET _=
ECHO.%COMSPEC% ¦ FIND /I "command.com" >NUL
IF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096
ECHO.%COMSPEC% ¦ FIND /I "cmd.exe" >NUL
IF NOT ERRORLEVEL 1 SET _cmd=cmd.exe
IF [%_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 step
IF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entry
IF [%_cmd%]==[] GOTO Merge

ECHO 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
:Merge
START /WAIT REGEDIT /S "%Temp%./DefOpen.reg"

:: Delete the temporary .REG file
DEL "%Temp%./DefOpen.reg"

:: Ready
GOTO End

:Syntax
ECHO.
ECHO DefOpen.bat,  Version 3.00 for Windows 95/98/NT 4/2000/XP
ECHO Adds a default association: when a file without a file association
ECHO 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:  DEFOPEN
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Notepad registry tip courtesy of Regedit.com
ECHO http://www.regedit.com

:: Clean up variables and quit
:End
SET _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 step IF [%_cmd%]==[] ECHO Skipping "Command Prompt Here" entry IF [%_cmd%]==[] GOTO Merge ECHO 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 :Merge START /WAIT REGEDIT /S "%Temp%./DefOpen.reg" :: Delete the temporary .REG file DEL "%Temp%./DefOpen.reg" :: Ready GOTO End :Syntax ECHO. ECHO DefOpen.bat, Version 3.00 for Windows 95/98/NT 4/2000/XP ECHO Adds a default association: when a file without a file association ECHO 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: DEFOPEN ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com ECHO Notepad registry tip courtesy of Regedit.com ECHO http://www.regedit.com :: Clean up variables and quit :End SET _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 required
IF NOT "%1"=="" GOTO Syntax

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
:: Adjust the LANDesk server name and the drive and directory if necessary ::
:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
SET LANDeskServer=MyLDServer
C:
CD/LDClient

ECHO Removing old LANDesk agent ID

:: Delete old ID file (adjust drive if necessary)
IF EXIST C:/LDIScan.cfg ATTRIB -h -r -s C:/LDIScan.cfg
IF 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 it
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
REGEDIT /E %TEMP%./_Unique_.REG "HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"
TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1
IF 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
:Next
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
REGEDIT /E %TEMP%./_Unique_.REG "HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"
TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1
IF ERRORLEVEL 1 GOTO Merge
DEL %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
:Merge
REGEDIT /S %TEMP%./UniqueID.reg
:: Delete the temporary REG file
DEL %TEMP%./UniqueID.reg

ECHO Creating new LANDesk agent ID

:: Start inventory scan to create new ID
LDISCN32.EXE /NTT=%LANDeskServer%:5007 /S="%LANDeskServer%" /I=//%LANDeskServer%/LDLOGON/ldappl.ini /V

ECHO Done
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
SET LANDeskServer=
CD/
GOTO End

:Syntax
ECHO UniqueID.bat,  Version 2.00 for 32-bit Windows
ECHO Create a new unique ID for Intel LANDesk agent
ECHO.
ECHO If a computer is installed using a harddisk image (like Norton Ghost
ECHO or PowerQuest's Drive Image) all "clones" will have the same LANDesk
ECHO 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 Woude
ECHO http://www.robvanderwoude.com

:End

@ECHO OFF
:: No command line parameters required
IF NOT "%1"=="" GOTO Syntax

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
:: Adjust the LANDesk server name and the drive and directory if necessary ::
:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
SET LANDeskServer=MyLDServer
C:
CD/LDClient

ECHO Removing old LANDesk agent ID

:: Delete old ID file (adjust drive if necessary)
IF EXIST C:/LDIScan.cfg ATTRIB -h -r -s C:/LDIScan.cfg
IF 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 it
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
REGEDIT /E %TEMP%./_Unique_.REG "HKEY_CURRENT_USER/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"
TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1
IF 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
:Next
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
REGEDIT /E %TEMP%./_Unique_.REG "HKEY_USERS/.Default/SOFTWARE/Intel/LANDesk/LDWM/LDIScan32"
TYPE %TEMP%./_Unique_.REG ¦ FIND /I "Last Device ID" >NUL 2>&1
IF ERRORLEVEL 1 GOTO Merge
DEL %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
:Merge
REGEDIT /S %TEMP%./UniqueID.reg
:: Delete the temporary REG file
DEL %TEMP%./UniqueID.reg

ECHO Creating new LANDesk agent ID

:: Start inventory scan to create new ID
LDISCN32.EXE /NTT=%LANDeskServer%:5007 /S="%LANDeskServer%" /I=//%LANDeskServer%/LDLOGON/ldappl.ini /V

ECHO Done
IF EXIST %TEMP%./_Unique_.REG DEL %TEMP%./_Unique_.REG
SET LANDeskServer=
CD/
GOTO End

:Syntax
ECHO UniqueID.bat,  Version 2.00 for 32-bit Windows
ECHO Create a new unique ID for Intel LANDesk agent
ECHO.
ECHO If a computer is installed using a harddisk image (like Norton Ghost
ECHO or PowerQuest's Drive Image) all "clones" will have the same LANDesk
ECHO 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 Woude
ECHO 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 file
START /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 variables
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "iCountry"') DO SET iCountry=%%B
SET iCountry=%iCountry:"=%
SET iCountry
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sCountry"') DO SET sCountry=%%B
SET sCountry=%sCountry:"=%
SET sCountry
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sLanguage"') DO SET sLanguage=%%B
SET sLanguage=%sLanguage:"=%
SET sLanguage
:: Remove temporary file
DEL %Temp%./international.reg
:: The KEYB trick was posted to the alt.msdos.batch.nt newsgroup by Tom Lavedas
FOR /F "tokens=1* delims=:" %%A IN ('KEYB ^¦ FIND ":" ^¦ FIND /V "CON"') DO SET Keyboard=%%B
SET Keyboard=%Keyboard:~1%
SET Keyboard
:: Check code page used
FOR /F "tokens=1* delims=:" %%A IN ('CHCP') DO SET /A CodePage = %%B
SET 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 file
START /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 variables
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "iCountry"') DO SET iCountry=%%B
SET iCountry=%iCountry:"=%
SET iCountry
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sCountry"') DO SET sCountry=%%B
SET sCountry=%sCountry:"=%
SET sCountry
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%./international.reg ^¦ FIND "sLanguage"') DO SET sLanguage=%%B
SET sLanguage=%sLanguage:"=%
SET sLanguage
:: Remove temporary file
DEL %Temp%./international.reg
:: The KEYB trick was posted to the alt.msdos.batch.nt newsgroup by Tom Lavedas
FOR /F "tokens=1* delims=:" %%A IN ('KEYB ^¦ FIND ":" ^¦ FIND /V "CON"') DO SET Keyboard=%%B
SET Keyboard=%Keyboard:~1%
SET Keyboard
:: Check code page used
FOR /F "tokens=1* delims=:" %%A IN ('CHCP') DO SET /A CodePage = %%B
SET 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 please
IF NOT [%1]==[] GOTO Syntax

:: Verify OS version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax

:: Keep variables local
SETLOCAL

:: Set initial values
SET VideoCard=
SET XResolution=
SET YResolution=
SET BitsPerPel=
SET VRefresh=

:: Read relevant registry entries and store them in a temporary REG file
REGEDIT /E "%Temp%./Screen.reg" "HKEY_CURRENT_CONFIG/System/CurrentControlSet/Services"

:: Process the temporary REG file
FOR /F "tokens=* delims=" %%A IN ('TYPE %Temp%./Screen.reg ^¦ FIND /V "REGEDIT4" ^¦ FIND /V ""') DO CALL :Parse01 %%A

:: Display results
ECHO.
SET VideoCard
SET XResolution
SET YResolution
SET BitsPerPel
SET VRefresh

:: Remove temporary file
IF EXIST "%Temp%./Screen.reg" DEL "%Temp%./Screen.reg"

:: Done
ENDLOCAL
GOTO:EOF


:Parse01
:: If this is the second card's entry, and the
:: first one was NOT VGA save mode, then quit
IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
:: Read subroutine's command line parameters as one line
SET Line=%*
:: Remove quotes from the line
SET Line=%Line:"=%
:: Remove spaces from the line
SET Line=%Line: =%
:: Check for and parse video card short name
IF "%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 quit
IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
:: If not, then save the new video adapter short name
SET VideoCard=%NewCard%
:: Parse all "key=value" lines
FOR /F "tokens=1* delims==" %%A IN ('ECHO.%Line%') DO CALL :Parse02 %%A %%B
:: End of subroutine Parse01
GOTO:EOF


:Parse02
:: Quit if either key or value aren't specified
IF "%2"=="" GOTO:EOF
:: %1 is key
SET InKey=%1
:: %2 is value
SET InValue=%2
:: Remove "Defaultvalue." prefix from key
FOR /F "tokens=2 delims=." %%a IN ('ECHO.%InKey%') DO SET Key=%%a
:: Continue only for these 4 keys, quit otherwise
IF /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 value
FOR /F "tokens=1,2 delims=:" %%a IN ('ECHO.%InValue%') DO (
	SET dWord=%%a
	SET xValue=%%b
)
:: If so, convert hexadecimal value to decimal
IF /I "%dWord%"=="dword" (SET /A Value = 0X%xValue%) ELSE (SET Value=%dWord%)
:: Store the result
SET %Key%=%Value%
:: End of subroutine Parse02
GOTO:EOF


:Syntax
ECHO.
ECHO GetRes.bat,  Version 3.00 for Windows NT 4 / 2000
ECHO Read and display video resolution settings from the registry
ECHO.
ECHO Usage:  GETRES
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.

@ECHO OFF
:: No command line parameters please
IF NOT [%1]==[] GOTO Syntax

:: Verify OS version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax

:: Keep variables local
SETLOCAL

:: Set initial values
SET VideoCard=
SET XResolution=
SET YResolution=
SET BitsPerPel=
SET VRefresh=

:: Read relevant registry entries and store them in a temporary REG file
REGEDIT /E "%Temp%./Screen.reg" "HKEY_CURRENT_CONFIG/System/CurrentControlSet/Services"

:: Process the temporary REG file
FOR /F "tokens=* delims=" %%A IN ('TYPE %Temp%./Screen.reg ^¦ FIND /V "REGEDIT4" ^¦ FIND /V ""') DO CALL :Parse01 %%A

:: Display results
ECHO.
SET VideoCard
SET XResolution
SET YResolution
SET BitsPerPel
SET VRefresh

:: Remove temporary file
IF EXIST "%Temp%./Screen.reg" DEL "%Temp%./Screen.reg"

:: Done
ENDLOCAL
GOTO:EOF


:Parse01
:: If this is the second card's entry, and the
:: first one was NOT VGA save mode, then quit
IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
:: Read subroutine's command line parameters as one line
SET Line=%*
:: Remove quotes from the line
SET Line=%Line:"=%
:: Remove spaces from the line
SET Line=%Line: =%
:: Check for and parse video card short name
IF "%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 quit
IF NOT "%VideoCard%"=="" IF NOT "%VideoCard%"=="%NewCard%" IF /I NOT "%VideoCard%"=="VgaSave" GOTO:EOF
:: If not, then save the new video adapter short name
SET VideoCard=%NewCard%
:: Parse all "key=value" lines
FOR /F "tokens=1* delims==" %%A IN ('ECHO.%Line%') DO CALL :Parse02 %%A %%B
:: End of subroutine Parse01
GOTO:EOF


:Parse02
:: Quit if either key or value aren't specified
IF "%2"=="" GOTO:EOF
:: %1 is key
SET InKey=%1
:: %2 is value
SET InValue=%2
:: Remove "Defaultvalue." prefix from key
FOR /F "tokens=2 delims=." %%a IN ('ECHO.%InKey%') DO SET Key=%%a
:: Continue only for these 4 keys, quit otherwise
IF /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 value
FOR /F "tokens=1,2 delims=:" %%a IN ('ECHO.%InValue%') DO (
	SET dWord=%%a
	SET xValue=%%b
)
:: If so, convert hexadecimal value to decimal
IF /I "%dWord%"=="dword" (SET /A Value = 0X%xValue%) ELSE (SET Value=%dWord%)
:: Store the result
SET %Key%=%Value%
:: End of subroutine Parse02
GOTO:EOF


:Syntax
ECHO.
ECHO GetRes.bat,  Version 3.00 for Windows NT 4 / 2000
ECHO Read and display video resolution settings from the registry
ECHO.
ECHO Usage:  GETRES
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.

 
 

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.

<script language="JavaScript" src="./scripts/lastmodified.js" type="text/javascript"> </script>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值