JNA API 4.0.0

com.sun.jna.platform.win32
Class Advapi32Util

java.lang.Object
  extended by com.sun.jna.platform.win32.Advapi32Util

public abstract class Advapi32Util
extends Object

Advapi32 utility API.

Author:
dblock[at]dblock.org

Nested Class Summary
static class Advapi32Util.Account
          An account.
static class Advapi32Util.EnumKey
           
static class Advapi32Util.EventLogIterator
          An iterator for Event Log entries.
static class Advapi32Util.EventLogRecord
          An event log record.
static class Advapi32Util.EventLogType
          Event log types.
static class Advapi32Util.InfoKey
           
 
Constructor Summary
Advapi32Util()
           
 
Method Summary
static String convertSidToStringSid(WinNT.PSID sid)
          Convert a security identifier (SID) to a string format suitable for display, storage, or transmission.
static byte[] convertStringSidToSid(String sidString)
          Convert a string representation of a security identifier (SID) to a binary format.
static Advapi32Util.Account getAccountByName(String accountName)
          Retrieves a security identifier (SID) for the account on the current system.
static Advapi32Util.Account getAccountByName(String systemName, String accountName)
          Retrieves a security identifier (SID) for a given account.
static Advapi32Util.Account getAccountBySid(String sidString)
          Get an account name from a string SID on the local machine.
static Advapi32Util.Account getAccountBySid(String systemName, String sidString)
          Get an account name from a string SID.
static Advapi32Util.Account getAccountBySid(String systemName, WinNT.PSID sid)
          Get the account by SID.
static Advapi32Util.Account getAccountBySid(WinNT.PSID sid)
          Get the account by SID on the local system.
static Advapi32Util.Account[] getCurrentUserGroups()
          Return the group memberships of the currently logged on user.
static String getEnvironmentBlock(Map<String,String> environment)
          Converts a map of environment variables to an environment block suitable for Advapi32.CreateProcessAsUser(com.sun.jna.platform.win32.WinNT.HANDLE, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, boolean, int, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.STARTUPINFO, com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION).
static WinNT.ACCESS_ACEStructure[] getFileSecurity(String fileName, boolean compact)
           
static Advapi32Util.Account getTokenAccount(WinNT.HANDLE hToken)
          This function returns the information about the user who owns a security token,
static Advapi32Util.Account[] getTokenGroups(WinNT.HANDLE hToken)
          This function returns the groups associated with a security token, such as a user token.
static String getUserName()
          Retrieves the name of the user associated with the current thread.
static boolean isWellKnownSid(byte[] sidBytes, int wellKnownSidType)
          Compares a SID to a well known SID and returns TRUE if they match.
static boolean isWellKnownSid(String sidString, int wellKnownSidType)
          Compares a SID to a well known SID and returns TRUE if they match.
static boolean registryCreateKey(WinReg.HKEY hKey, String keyName)
          Create a registry key.
static boolean registryCreateKey(WinReg.HKEY root, String parentPath, String keyName)
          Create a registry key.
static void registryDeleteKey(WinReg.HKEY hKey, String keyName)
          Delete a registry key.
static void registryDeleteKey(WinReg.HKEY root, String keyPath, String keyName)
          Delete a registry key.
static void registryDeleteValue(WinReg.HKEY hKey, String valueName)
          Delete a registry value.
static void registryDeleteValue(WinReg.HKEY root, String keyPath, String valueName)
          Delete a registry value.
static byte[] registryGetBinaryValue(WinReg.HKEY root, String key, String value)
          Get a registry REG_BINARY value.
static String registryGetExpandableStringValue(WinReg.HKEY root, String key, String value)
          Get a registry REG_EXPAND_SZ value.
static int registryGetIntValue(WinReg.HKEY root, String key, String value)
          Get a registry DWORD value.
static WinReg.HKEYByReference registryGetKey(WinReg.HKEY root, String keyPath, int samDesired)
          Get a registry key, the caller is responsible to close the key after use.
static String[] registryGetKeys(WinReg.HKEY hKey)
          Get names of the registry key's sub-keys.
static String[] registryGetKeys(WinReg.HKEY root, String keyPath)
          Get names of the registry key's sub-keys.
static long registryGetLongValue(WinReg.HKEY root, String key, String value)
          Get a registry QWORD value.
static String[] registryGetStringArray(WinReg.HKEY root, String key, String value)
          Get a registry REG_MULTI_SZ value.
static String registryGetStringValue(WinReg.HKEY root, String key, String value)
          Get a registry REG_SZ value.
static Object registryGetValue(WinReg.HKEY hkKey, String subKey, String lpValueName)
          Get a registry value and returns a java object depending on the value type.
static TreeMap<String,Object> registryGetValues(WinReg.HKEY hKey)
          Get a table of registry values.
static TreeMap<String,Object> registryGetValues(WinReg.HKEY root, String keyPath)
          Get a table of registry values.
static boolean registryKeyExists(WinReg.HKEY root, String key)
          Checks whether a registry key exists.
static Advapi32Util.InfoKey registryQueryInfoKey(WinReg.HKEY hKey, int lpcbSecurityDescriptor)
          Queries the information about a specified key.
static Advapi32Util.EnumKey registryRegEnumKey(WinReg.HKEY hKey, int dwIndex)
          Queries the information about a specified key.
static void registrySetBinaryValue(WinReg.HKEY hKey, String name, byte[] data)
          Set a binary value in registry.
static void registrySetBinaryValue(WinReg.HKEY root, String keyPath, String name, byte[] data)
          Set a binary value in registry.
static void registrySetExpandableStringValue(WinReg.HKEY hKey, String name, String value)
          Set an expandable string value in registry.
static void registrySetExpandableStringValue(WinReg.HKEY root, String keyPath, String name, String value)
          Set a string value in registry.
static void registrySetIntValue(WinReg.HKEY hKey, String name, int value)
          Set an integer value in registry.
static void registrySetIntValue(WinReg.HKEY root, String keyPath, String name, int value)
          Set an integer value in registry.
static void registrySetLongValue(WinReg.HKEY hKey, String name, long value)
          Set a long value in registry.
static void registrySetLongValue(WinReg.HKEY root, String keyPath, String name, long value)
          Set a long value in registry.
static void registrySetStringArray(WinReg.HKEY hKey, String name, String[] arr)
          Set a string array value in registry.
static void registrySetStringArray(WinReg.HKEY root, String keyPath, String name, String[] arr)
          Set a string array value in registry.
static void registrySetStringValue(WinReg.HKEY hKey, String name, String value)
          Set a string value in registry.
static void registrySetStringValue(WinReg.HKEY root, String keyPath, String name, String value)
          Set a string value in registry.
static boolean registryValueExists(WinReg.HKEY root, String key, String value)
          Checks whether a registry value exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Advapi32Util

public Advapi32Util()
Method Detail

getUserName

public static String getUserName()
Retrieves the name of the user associated with the current thread.

Returns:
A user name.

getAccountByName

public static Advapi32Util.Account getAccountByName(String accountName)
Retrieves a security identifier (SID) for the account on the current system.

Parameters:
accountName - Specifies the account name.
Returns:
A structure containing the account SID;

getAccountByName

public static Advapi32Util.Account getAccountByName(String systemName,
                                                    String accountName)
Retrieves a security identifier (SID) for a given account.

Parameters:
systemName - Name of the system.
accountName - Account name.
Returns:
A structure containing the account SID.

getAccountBySid

public static Advapi32Util.Account getAccountBySid(WinNT.PSID sid)
Get the account by SID on the local system.

Parameters:
sid - SID.
Returns:
Account.

getAccountBySid

public static Advapi32Util.Account getAccountBySid(String systemName,
                                                   WinNT.PSID sid)
Get the account by SID.

Parameters:
systemName - Name of the system.
sid - SID.
Returns:
Account.

convertSidToStringSid

public static String convertSidToStringSid(WinNT.PSID sid)
Convert a security identifier (SID) to a string format suitable for display, storage, or transmission.

Parameters:
sid - SID bytes.
Returns:
String SID.

convertStringSidToSid

public static byte[] convertStringSidToSid(String sidString)
Convert a string representation of a security identifier (SID) to a binary format.

Parameters:
sidString - String SID.
Returns:
SID bytes.

isWellKnownSid

public static boolean isWellKnownSid(String sidString,
                                     int wellKnownSidType)
Compares a SID to a well known SID and returns TRUE if they match.

Parameters:
sidString - String representation of a SID.
wellKnownSidType - Member of the WELL_KNOWN_SID_TYPE enumeration to compare with the SID at pSid.
Returns:
True if the SID is of the well-known type, false otherwise.

isWellKnownSid

public static boolean isWellKnownSid(byte[] sidBytes,
                                     int wellKnownSidType)
Compares a SID to a well known SID and returns TRUE if they match.

Parameters:
sidBytes - Byte representation of a SID.
wellKnownSidType - Member of the WELL_KNOWN_SID_TYPE enumeration to compare with the SID at pSid.
Returns:
True if the SID is of the well-known type, false otherwise.

getAccountBySid

public static Advapi32Util.Account getAccountBySid(String sidString)
Get an account name from a string SID on the local machine.

Parameters:
sidString - SID.
Returns:
Account.

getAccountBySid

public static Advapi32Util.Account getAccountBySid(String systemName,
                                                   String sidString)
Get an account name from a string SID.

Parameters:
systemName - System name.
sidString - SID.
Returns:
Account.

getTokenGroups

public static Advapi32Util.Account[] getTokenGroups(WinNT.HANDLE hToken)
This function returns the groups associated with a security token, such as a user token.

Parameters:
hToken - Token.
Returns:
Token groups.

getTokenAccount

public static Advapi32Util.Account getTokenAccount(WinNT.HANDLE hToken)
This function returns the information about the user who owns a security token,

Parameters:
hToken - Token.
Returns:
Token user.

getCurrentUserGroups

public static Advapi32Util.Account[] getCurrentUserGroups()
Return the group memberships of the currently logged on user.

Returns:
An array of groups.

registryKeyExists

public static boolean registryKeyExists(WinReg.HKEY root,
                                        String key)
Checks whether a registry key exists.

Parameters:
root - HKEY_LOCAL_MACHINE, etc.
key - Path to the registry key.
Returns:
True if the key exists.

registryValueExists

public static boolean registryValueExists(WinReg.HKEY root,
                                          String key,
                                          String value)
Checks whether a registry value exists.

Parameters:
root - HKEY_LOCAL_MACHINE, etc.
key - Registry key path.
value - Value name.
Returns:
True if the value exists.

registryGetStringValue

public static String registryGetStringValue(WinReg.HKEY root,
                                            String key,
                                            String value)
Get a registry REG_SZ value.

Parameters:
root - Root key.
key - Registry path.
value - Name of the value to retrieve.
Returns:
String value.

registryGetExpandableStringValue

public static String registryGetExpandableStringValue(WinReg.HKEY root,
                                                      String key,
                                                      String value)
Get a registry REG_EXPAND_SZ value.

Parameters:
root - Root key.
key - Registry path.
value - Name of the value to retrieve.
Returns:
String value.

registryGetStringArray

public static String[] registryGetStringArray(WinReg.HKEY root,
                                              String key,
                                              String value)
Get a registry REG_MULTI_SZ value.

Parameters:
root - Root key.
key - Registry path.
value - Name of the value to retrieve.
Returns:
String value.

registryGetBinaryValue

public static byte[] registryGetBinaryValue(WinReg.HKEY root,
                                            String key,
                                            String value)
Get a registry REG_BINARY value.

Parameters:
root - Root key.
key - Registry path.
value - Name of the value to retrieve.
Returns:
String value.

registryGetIntValue

public static int registryGetIntValue(WinReg.HKEY root,
                                      String key,
                                      String value)
Get a registry DWORD value.

Parameters:
root - Root key.
key - Registry key path.
value - Name of the value to retrieve.
Returns:
Integer value.

registryGetLongValue

public static long registryGetLongValue(WinReg.HKEY root,
                                        String key,
                                        String value)
Get a registry QWORD value.

Parameters:
root - Root key.
key - Registry key path.
value - Name of the value to retrieve.
Returns:
Integer value.

registryGetValue

public static Object registryGetValue(WinReg.HKEY hkKey,
                                      String subKey,
                                      String lpValueName)
Get a registry value and returns a java object depending on the value type.

Parameters:
hkKey - Root key.
subKey - Registry key path.
lpValueName - Name of the value to retrieve or null for the default value.
Returns:
Object value.

registryCreateKey

public static boolean registryCreateKey(WinReg.HKEY hKey,
                                        String keyName)
Create a registry key.

Parameters:
hKey - Parent key.
keyName - Key name.
Returns:
True if the key was created, false otherwise.

registryCreateKey

public static boolean registryCreateKey(WinReg.HKEY root,
                                        String parentPath,
                                        String keyName)
Create a registry key.

Parameters:
root - Root key.
parentPath - Path to an existing registry key.
keyName - Key name.
Returns:
True if the key was created, false otherwise.

registrySetIntValue

public static void registrySetIntValue(WinReg.HKEY hKey,
                                       String name,
                                       int value)
Set an integer value in registry.

Parameters:
hKey - Parent key.
name - Value name.
value - Value to write to registry.

registrySetIntValue

public static void registrySetIntValue(WinReg.HKEY root,
                                       String keyPath,
                                       String name,
                                       int value)
Set an integer value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
value - Value to write to registry.

registrySetLongValue

public static void registrySetLongValue(WinReg.HKEY hKey,
                                        String name,
                                        long value)
Set a long value in registry.

Parameters:
hKey - Parent key.
name - Value name.
value - Value to write to registry.

registrySetLongValue

public static void registrySetLongValue(WinReg.HKEY root,
                                        String keyPath,
                                        String name,
                                        long value)
Set a long value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
value - Value to write to registry.

registrySetStringValue

public static void registrySetStringValue(WinReg.HKEY hKey,
                                          String name,
                                          String value)
Set a string value in registry.

Parameters:
hKey - Parent key.
name - Value name.
value - Value to write to registry.

registrySetStringValue

public static void registrySetStringValue(WinReg.HKEY root,
                                          String keyPath,
                                          String name,
                                          String value)
Set a string value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
value - Value to write to registry.

registrySetExpandableStringValue

public static void registrySetExpandableStringValue(WinReg.HKEY hKey,
                                                    String name,
                                                    String value)
Set an expandable string value in registry.

Parameters:
hKey - Parent key.
name - Value name.
value - Value to write to registry.

registrySetExpandableStringValue

public static void registrySetExpandableStringValue(WinReg.HKEY root,
                                                    String keyPath,
                                                    String name,
                                                    String value)
Set a string value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
value - Value to write to registry.

registrySetStringArray

public static void registrySetStringArray(WinReg.HKEY hKey,
                                          String name,
                                          String[] arr)
Set a string array value in registry.

Parameters:
hKey - Parent key.
name - Name.
arr - Array of strings to write to registry.

registrySetStringArray

public static void registrySetStringArray(WinReg.HKEY root,
                                          String keyPath,
                                          String name,
                                          String[] arr)
Set a string array value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
arr - Array of strings to write to registry.

registrySetBinaryValue

public static void registrySetBinaryValue(WinReg.HKEY hKey,
                                          String name,
                                          byte[] data)
Set a binary value in registry.

Parameters:
hKey - Parent key.
name - Value name.
data - Data to write to registry.

registrySetBinaryValue

public static void registrySetBinaryValue(WinReg.HKEY root,
                                          String keyPath,
                                          String name,
                                          byte[] data)
Set a binary value in registry.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
name - Value name.
data - Data to write to registry.

registryDeleteKey

public static void registryDeleteKey(WinReg.HKEY hKey,
                                     String keyName)
Delete a registry key.

Parameters:
hKey - Parent key.
keyName - Name of the key to delete.

registryDeleteKey

public static void registryDeleteKey(WinReg.HKEY root,
                                     String keyPath,
                                     String keyName)
Delete a registry key.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
keyName - Name of the key to delete.

registryDeleteValue

public static void registryDeleteValue(WinReg.HKEY hKey,
                                       String valueName)
Delete a registry value.

Parameters:
hKey - Parent key.
valueName - Name of the value to delete.

registryDeleteValue

public static void registryDeleteValue(WinReg.HKEY root,
                                       String keyPath,
                                       String valueName)
Delete a registry value.

Parameters:
root - Root key.
keyPath - Path to an existing registry key.
valueName - Name of the value to delete.

registryGetKeys

public static String[] registryGetKeys(WinReg.HKEY hKey)
Get names of the registry key's sub-keys.

Parameters:
hKey - Registry key.
Returns:
Array of registry key names.

registryGetKeys

public static String[] registryGetKeys(WinReg.HKEY root,
                                       String keyPath)
Get names of the registry key's sub-keys.

Parameters:
root - Root key.
keyPath - Path to a registry key.
Returns:
Array of registry key names.

registryGetKey

public static WinReg.HKEYByReference registryGetKey(WinReg.HKEY root,
                                                    String keyPath,
                                                    int samDesired)
Get a registry key, the caller is responsible to close the key after use.

Parameters:
root - Root key.
keyPath - Path to a registry key.
samDesired - Access level (e.g. WinNT.KEY_READ)
Returns:
HKEYByReference.

registryGetValues

public static TreeMap<String,Object> registryGetValues(WinReg.HKEY hKey)
Get a table of registry values.

Parameters:
hKey - Registry key.
Returns:
Table of values.

registryGetValues

public static TreeMap<String,Object> registryGetValues(WinReg.HKEY root,
                                                       String keyPath)
Get a table of registry values.

Parameters:
root - Registry root.
keyPath - Regitry key path.
Returns:
Table of values.

registryQueryInfoKey

public static Advapi32Util.InfoKey registryQueryInfoKey(WinReg.HKEY hKey,
                                                        int lpcbSecurityDescriptor)
Queries the information about a specified key.

Parameters:
hKey - Current registry key.
Returns:
A InfoKey value object.

registryRegEnumKey

public static Advapi32Util.EnumKey registryRegEnumKey(WinReg.HKEY hKey,
                                                      int dwIndex)
Queries the information about a specified key.

Parameters:
hKey - Current registry key.
Returns:
A InfoKey value object.

getEnvironmentBlock

public static String getEnvironmentBlock(Map<String,String> environment)
Converts a map of environment variables to an environment block suitable for Advapi32.CreateProcessAsUser(com.sun.jna.platform.win32.WinNT.HANDLE, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, boolean, int, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.STARTUPINFO, com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION). This environment block consists of null-terminated blocks of null-terminated strings. Each string is in the following form: name=value\0

Parameters:
environment - Environment variables
Returns:
A environment block

getFileSecurity

public static WinNT.ACCESS_ACEStructure[] getFileSecurity(String fileName,
                                                          boolean compact)

JNA API 4.0.0

Copyright © 2007-2013 Timothy Wall. All Rights Reserved.