⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registrykey.java

📁 注册表的读取信息,工具文件包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	/**
	 * Get the value of a REG_SZ or REG_EXPAND_SZ value.
	 *
	 * @param valueName The name of the value to get.
	 * @return The string data of the named value.
	 *
     * @exception  NoSuchValueException  If the value does not exist.
     * @exception  RegistryException  Any other registry API error.
	 */

	public native String
		getStringValue( String valueName )
			throws NoSuchValueException, RegistryException;

	/**
	 * Get the data from the default value.
	 *
	 * @return The string data of the default value.
	 *
     * @exception  NoSuchValueException  If the value does not exist.
     * @exception  RegistryException  Any other registry API error.
	 */

	public native String
		getDefaultValue()
			throws NoSuchValueException, RegistryException;

	/**
	 * Determines if this key has a default value.
	 *
	 * @return True if there is a default value, else false.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native boolean
		hasDefaultValue()
			throws RegistryException;

	/**
	 * Determines if this key has <em>only</em> a default value.
	 *
	 * @return True if there is only a default value, else false.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native boolean
		hasOnlyDefaultValue()
			throws RegistryException;

	/**
	 * Obtains the number of subkeys that this key contains.
	 *
	 * @return The number of subkeys that this key contains.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native int
		getNumberSubkeys()
			throws RegistryException;

	/**
	 * Obtains the maximum length of all of the subkey names.
	 *
	 * @return The maximum length of all of the subkey names.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native int
		getMaxSubkeyLength()
			throws RegistryException;

	/**
	 * Obtains an enumerator for the subkeys of this key.
	 *
	 * @return The key enumerator.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native String
		regEnumKey( int index )
			throws RegistryException;

	/**
	 * Obtains the number of values that this key contains.
	 *
	 * @return The number of values that this key contains.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native int
		getNumberValues()
			throws RegistryException;

	/**
	 * Obtains the maximum length of all of the value data.
	 *
	 * @return The maximum length of all of the value data.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native int
		getMaxValueDataLength()
			throws RegistryException;

	/**
	 * Obtains the maximum length of all of the value names.
	 *
	 * @return The maximum length of all of the value names.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native int
		getMaxValueNameLength()
			throws RegistryException;

	/**
	 * Obtains an enumerator for the values of this key.
	 *
	 * @return The value enumerator.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public native String
		regEnumValue( int index )
			throws RegistryException;

	//
	// Convenience routines
	//

	/**
	 * This method will increment the value of a REG_DWORD value.
	 *
	 * @param valueName The name of the value to increment.
	 *
     * @exception  NoSuchValueException  If the value does not exist.
     * @exception  RegistryException  Any other registry API error.
	 */

	public native int
		incrDoubleWord( String valueName )
			throws NoSuchValueException, RegistryException;

	/**
	 * This method will decrement the value of a REG_DWORD value.
	 *
	 * @param valueName The name of the value to increment.
	 *
     * @exception  NoSuchValueException  If the value does not exist.
     * @exception  RegistryException  Any other registry API error.
	 */

	public native int
		decrDoubleWord( String valueName )
			throws NoSuchValueException, RegistryException;

	/**
	 * This method will expand a string to include the definitions
	 * of System environment variables that are referenced via the
	 * %variable% construct. This method invokes EnvExpandStrings().
	 *
	 * @param valueName The name of the value to increment.
	 */

	public static native String
		expandEnvStrings( String exString );

	/**
	 * Returns a new Enumeration that will enumerate the 
	 * names of the subkeys of this key,
	 *
	 * @return A new Enumeration to enumerate subkey names.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public Enumeration
	keyElements()
			throws RegistryException
		{
		return this.new RegistryKeyEnumerator( this );
		}

	/**
	 * Returns a new Enumeration that will enumerate the 
	 * names of the values of this key,
	 *
	 * @return A new Enumeration to enumerate value names.
	 *
     * @exception  RegistryException  Any valid registry API error.
	 */

	public Enumeration
	valueElements()
			throws RegistryException
		{
		return this.new RegistryValueEnumerator( this );
		}

	/**
	 * A RegistryKey enumerator class. This enumerator
	 * is used to enumerate the names of this key's subkeys.
	 *
	 * This class should remain opaque to the client,
	 * which will use the Enumeration interface. 
	 */
	class
	RegistryKeyEnumerator implements Enumeration
		{
		RegistryKey		key;
		int				currIndex;
		int				numSubKeys;

		public
		RegistryKeyEnumerator( RegistryKey key )
				throws RegistryException
			{
			this.key = key;
			this.currIndex = 0;
			this.numSubKeys = key.getNumberSubkeys();
			}

		public boolean hasMoreElements()
			{
			return ( this.currIndex < this.numSubKeys );
			}

		public Object
		nextElement()
			{
			Object result = null;
			
			try { result = this.key.regEnumKey( this.currIndex++ ); }
			catch ( RegistryException ex )
				{
				throw new NoSuchElementException( ex.getMessage() );
				}

			return result;
			}
		}

	/**
	 * A RegistryValue enumerator class. This enumerator
	 * is used to enumerate the names of this key's values.
	 * This will return the default value name as an empty string.
	 *
	 * This class should remain opaque to the client.
	 * It will use the Enumeration interface. 
	 */

	class
	RegistryValueEnumerator implements Enumeration
		{
		RegistryKey		key;
		int				currIndex;
		int				numValues;

		public
		RegistryValueEnumerator( RegistryKey key )
				throws RegistryException
			{
			this.key = key;
			this.currIndex = 0;
			this.numValues = key.getNumberValues();
			}

		public boolean hasMoreElements()
			{
			return ( this.currIndex < this.numValues );
			}

		public Object
		nextElement()
			{
			Object result = null;

			try { result = this.key.regEnumValue( this.currIndex++ ); }
			catch ( RegistryException ex )
				{
				throw new NoSuchElementException( ex.getMessage() );
				}

			return result;
			}
		}

	/**
	 * Export this key's definition to the provided PrintWriter.
	 * The resulting file can be imported via RegEdit.
	 *
     * @exception  NoSuchKeyException  Thrown by openSubKey().
     * @exception  NoSuchValueException  Thrown by getValue().
     * @exception  RegistryException  Any other registry API error.
	 */

	public void
	export( PrintWriter out, boolean descend )
		throws NoSuchKeyException, RegistryException
		{
		Enumeration		enum;

		out.println( "[" + this.getFullName() + "]" );

		enum = this.valueElements();

		for ( int idx = 0 ; enum.hasMoreElements() ; ++idx )
			{
			String valueName = (String) enum.nextElement();

			RegistryValue value = this.getValue( valueName );

			value.export( out );
			}

		out.println( "" );

		if ( descend )
			{
			enum = this.keyElements();

			for ( int idx = 0 ; enum.hasMoreElements() ; ++idx )
				{
				String keyName = (String) enum.nextElement();

				RegistryKey subKey = this.openSubKey( keyName );

				subKey.export( out, descend );

				subKey.closeKey();
				}
			}
		}

	}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -