📄 registry.java
字号:
keyName = Registry.saveKey;
}
else if ( keyName.equals( "@@" ) )
{
keyName = "HKCU\\Software\\ICE Engineering\\test";
}
else
{
char ch1 = keyName.charAt(0);
char ch2 = keyName.charAt(1);
if ( ch1 == '$' && ch2 >= '0' && ch2 <= '9' )
{
int pIdx = (ch2 - '0');
if ( Registry.preDefines[ pIdx ] != null )
{
if ( keyName.length() < 3 )
keyName = Registry.preDefines[ pIdx ];
else
keyName =
Registry.preDefines[ pIdx ]
+ keyName.substring( 2 );
}
else
{
System.err.println
( "Predefine '" + keyName + "' not defined." );
return;
}
}
else
{
Registry.saveKey = argv[1];
}
}
if ( keyName.startsWith( "\\\\" ) )
{
isRemote = true;
index = keyName.indexOf( '\\', 2 );
hostName = keyName.substring( 2, index );
keyName = keyName.substring( index + 1 );
}
index = keyName.indexOf( '\\' );
if ( index < 0 )
{
//
// "topLevelKeyname"
//
topKeyName = keyName;
keyName = null;
}
else if ( index < 4 )
{
//
// INVALID KEYNAME, topLevelName too short
//
System.err.println
( "Invalid key '" + keyName
+ "', top level key name too short." );
return;
}
else
{
//
// "topLevelKeyname\subKey\subKey\..."
//
topKeyName = keyName.substring( 0, index );
if ( (index + 1) >= keyName.length() )
keyName = null;
else
keyName = keyName.substring( index + 1 );
}
topKey = Registry.getTopLevelKey( topKeyName );
if ( topKey == null )
{
System.err.println
( "ERROR, toplevel key '" + topKeyName
+ "' not resolved!" );
return;
}
if ( isRemote )
{
System.err.println
( "REMOTE Key host='" + hostName + "'" );
RegistryKey remoteKey = null;
try {
remoteKey = topKey.connectRegistry( hostName );
}
catch ( NoSuchKeyException ex )
{
System.err.println
( "ERROR No such key connecting to '"
+ hostName + "', " + ex.getMessage() );
return;
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR errCode=" + ex.getErrorCode()
+ "' connecting to '" + hostName
+ "', " + ex.getMessage() );
return;
}
if ( remoteKey != null )
{
topKey = remoteKey;
}
}
//
// P R O C E S S C O M M A N D S
//
if ( argv[0].equalsIgnoreCase( "create" ) )
{
Registry.createCommand( topKey, keyName );
}
else if ( argv[0].equalsIgnoreCase( "setbin" ) )
{
Registry.setBinaryCommand
( topKey, keyName, argv[2], argv[3] );
}
else if ( argv[0].equalsIgnoreCase( "setdw" ) )
{
Registry.setBinaryCommand
( topKey, keyName, argv[2], argv[3] );
}
else if ( argv[0].equalsIgnoreCase( "setstr" ) )
{
Registry.setStringCommand
( topKey, keyName, argv[2], argv[3] );
}
else if ( argv[0].equalsIgnoreCase( "setmulti" ) )
{
Registry.setMultiStringCommand
( topKey, keyName, argv[2], argv[3] );
}
else if ( argv[0].equalsIgnoreCase( "keys" ) )
{
Registry.listKeysCommand( topKey, keyName );
}
else if ( argv[0].equalsIgnoreCase( "values" ) )
{
Registry.listValuesCommand( topKey, keyName );
}
else if ( argv[0].equalsIgnoreCase( "delkey" ) )
{
Registry.deleteKeyCommand( topKey, keyName, argv[2] );
}
else if ( argv[0].equalsIgnoreCase( "delval" ) )
{
Registry.deleteValueCommand( topKey, keyName, argv[2] );
}
else if ( argv[0].equalsIgnoreCase( "data" ) )
{
Registry.getDataCommand( topKey, keyName, argv[2] );
}
else if ( argv[0].equalsIgnoreCase( "string" ) )
{
Registry.getStringCommand( topKey, keyName, argv[2] );
}
else if ( argv[0].equalsIgnoreCase( "export" ) )
{
Registry.exportKeyCommand( topKey, keyName, argv[2] );
}
else if ( argv[0].equalsIgnoreCase( "expand" ) )
{
Registry.expandStringCommand( topKey, keyName, argv[2] );
}
}
private static void
exportKeyCommand(
RegistryKey topKey, String keyName, String pathName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
try { Registry.exportRegistryKey( pathName, subKey, true ); }
catch ( IOException ex )
{
System.err.println
( "IO Exception: '" + ex.getMessage() + "'" );
}
catch ( NoSuchKeyException ex )
{
System.err.println
( "Error, encountered non-existent key during export." );
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR registry error=" + ex.getErrorCode()
+ ", " + ex.getMessage() );
}
}
private static void
getDataCommand(
RegistryKey topKey, String keyName, String valueName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
RegistryValue data = null;
try { data = subKey.getValue( valueName ); }
catch ( NoSuchValueException ex )
{
System.err.println
( "Value '" + valueName + "' does not exist." );
return;
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR registry error=" + ex.getErrorCode()
+ ", " + ex.getMessage() );
return;
}
System.err.println
( "Value '" + valueName + "' is " + data.toString() );
if ( data instanceof RegStringValue )
{
RegStringValue val = (RegStringValue) data;
System.err.println( "REG_SZ '" + val.getData() + "'" );
}
else if ( data instanceof RegMultiStringValue )
{
RegMultiStringValue val = (RegMultiStringValue) data;
String[] args = val.getData();
for ( int idx = 0 ; idx < args.length ; ++idx )
System.err.println
( "REG_MULTI_SZ[" + idx + "] '"
+ args[idx] + "'" );
}
else if ( data instanceof RegDWordValue )
{
RegDWordValue val = (RegDWordValue) data;
HexNumberFormat xFmt =
new HexNumberFormat( "XXXXXXXX" );
System.err.println(
"REG_DWORD"
+ ( (RegistryValue.REG_DWORD_BIG_ENDIAN
== val.getType())
? "_BIG_ENDIAN" : "" )
+ " '" + val.getData() + "' [x"
+ xFmt.format( val.getData() ) + "]" );
}
else
{
RegBinaryValue val = (RegBinaryValue) data;
/*
System.err.println( "BINARY: len=" + val.getLength() );
System.err.println( "BINARY: [0]=" + val.getData()[0] );
System.err.println( "BINARY: [1]=" + val.getData()[1] );
System.err.println( "BINARY: [2]=" + val.getData()[2] );
System.err.println( "BINARY: [3]=" + val.getData()[3] );
*/
Registry.dumpHexData
( System.err,
"REG_BINARY '" + val.getName()
+ "', len=" + val.getLength(),
val.getData(), val.getLength() );
}
}
private static void
getStringCommand(
RegistryKey topKey, String keyName, String valueName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
try {
String value = subKey.getStringValue( valueName );
System.err.println
( "String Value " + valueName + "='" + value + "'" );
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR getting value '" + valueName + "', "
+ ex.getMessage() );
return;
}
}
private static void
expandStringCommand(
RegistryKey topKey, String keyName, String valueName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
try {
String value = subKey.getStringValue( valueName );
System.err.println
( "String Value " + valueName + "='" + value + "'" );
value = RegistryKey.expandEnvStrings( value );
System.err.println
( "Expanded Value " + valueName + "='" + value + "'" );
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR getting value '" + valueName + "', "
+ ex.getMessage() );
return;
}
}
private static void
deleteKeyCommand(
RegistryKey topKey, String keyName, String deleteKeyName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_WRITE );
if ( subKey == null )
return;
try { subKey.deleteSubKey( deleteKeyName ); }
catch ( NoSuchKeyException ex )
{
System.err.println
( "Key '" + keyName + "\\"
+ deleteKeyName + "' does not exist." );
return;
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR deleting key '" + keyName
+ "', " + ex.getMessage() );
return;
}
}
private static void
deleteValueCommand(
RegistryKey topKey, String keyName, String valueName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_WRITE );
if ( subKey == null )
return;
try { subKey.deleteValue( valueName ); }
catch ( NoSuchValueException ex )
{
System.err.println
( "Value '" + valueName + "' does not exist." );
return;
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR deleting value '" + valueName
+ "', " + ex.getMessage() );
return;
}
}
private static void
listKeysCommand( RegistryKey topKey, String keyName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
try {
Enumeration enum = subKey.keyElements();
for ( int kIdx = 0 ; enum.hasMoreElements() ; ++kIdx )
{
String keyStr = (String) enum.nextElement();
System.err.println
( "Subkey[" + kIdx + "] = '" + keyStr + "'" );
}
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR getting key enumerator, "
+ ex.getMessage() );
return;
}
}
private static void
listValuesCommand( RegistryKey topKey, String keyName )
{
RegistryKey subKey =
Registry.openSubKeyVerbose
( topKey, keyName, RegistryKey.ACCESS_READ );
if ( subKey == null )
return;
try {
Enumeration enum = subKey.valueElements();
for ( int kIdx = 0 ; enum.hasMoreElements() ; ++kIdx )
{
String name = (String) enum.nextElement();
System.err.println
( "Value Name[" + kIdx + "] = '" + name + "'" );
}
}
catch ( RegistryException ex )
{
System.err.println
( "ERROR getting value enumerator, "
+ ex.getMessage() );
return;
}
}
private static void
setDWordCommand(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -