Package com.sun.jna.platform.win32
Class Advapi32Util
- java.lang.Object
-
- com.sun.jna.platform.win32.Advapi32Util
-
public abstract class Advapi32Util extends java.lang.ObjectAdvapi32 utility API.- Author:
- dblock[at]dblock.org
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAdvapi32Util.AccessCheckPermissionstatic classAdvapi32Util.AccountAn account.static classAdvapi32Util.EnumKeystatic classAdvapi32Util.EventLogIteratorAn iterator for Event Log entries.static classAdvapi32Util.EventLogRecordAn event log record.static classAdvapi32Util.EventLogTypeEvent log types.static classAdvapi32Util.InfoKeystatic classAdvapi32Util.PrivilegeConvenience class to enable certain Windows process privileges
-
Constructor Summary
Constructors Constructor Description Advapi32Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanaccessCheck(java.io.File file, Advapi32Util.AccessCheckPermission permissionToCheck)Checks if the current process has the given permission for the file.static intalignOnDWORD(int cbAcl)Align cbAcl on a DWORDstatic voidbackupEncryptedFile(java.io.File src, java.io.File destDir)Backup an encrypted file or folder without decrypting it.static java.lang.StringconvertSidToStringSid(WinNT.PSID sid)Convert a security identifier (SID) to a string format suitable for display, storage, or transmission.static byte[]convertStringSidToSid(java.lang.String sidString)Convert a string representation of a security identifier (SID) to a binary format.static voiddecryptFile(java.io.File file)Decrypts an encrypted file or directory.static voiddisableEncryption(java.io.File directory, boolean disable)Disables or enables encryption of the specified directory and the files in it.static voidencryptFile(java.io.File file)Encrypts a file or directory.static intfileEncryptionStatus(java.io.File file)Checks the encryption status of a file.static Advapi32Util.AccountgetAccountByName(java.lang.String accountName)Retrieves a security identifier (SID) for the account on the current system.static Advapi32Util.AccountgetAccountByName(java.lang.String systemName, java.lang.String accountName)Retrieves a security identifier (SID) for a given account.static Advapi32Util.AccountgetAccountBySid(WinNT.PSID sid)Get the account by SID on the local system.static Advapi32Util.AccountgetAccountBySid(java.lang.String sidString)Get an account name from a string SID on the local machine.static Advapi32Util.AccountgetAccountBySid(java.lang.String systemName, WinNT.PSID sid)Get the account by SID.static Advapi32Util.AccountgetAccountBySid(java.lang.String systemName, java.lang.String sidString)Get an account name from a string SID.static intgetAceSize(int sidLength)Helper function to calculate the size of an ACE for a given PSID sizestatic Advapi32Util.Account[]getCurrentUserGroups()Return the group memberships of the currently logged on user.static java.lang.StringgetEnvironmentBlock(java.util.Map<java.lang.String,java.lang.String> environment)Converts a map of environment variables to an environment block suitable forAdvapi32.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.ACE_HEADER[]getFileSecurity(java.lang.String fileName, boolean compact)static WinNT.SECURITY_DESCRIPTOR_RELATIVEgetFileSecurityDescriptor(java.io.File file, boolean getSACL)Gets a file's Security Descriptor.static MemorygetSecurityDescriptorForObject(java.lang.String absoluteObjectPath, int objectType, boolean getSACL)Get a self relative security descriptor for the given object type.static Advapi32Util.AccountgetTokenAccount(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 Advapi32Util.AccountgetTokenPrimaryGroup(WinNT.HANDLE hToken)This function returns the primary group associated with a security token, such as a user token.static java.lang.StringgetUserName()Retrieves the name of the user associated with the current thread.static booleanisWellKnownSid(byte[] sidBytes, int wellKnownSidType)Compares a SID to a well known SID and returns TRUE if they match.static booleanisWellKnownSid(java.lang.String sidString, int wellKnownSidType)Compares a SID to a well known SID and returns TRUE if they match.static voidregistryCloseKey(WinReg.HKEY hKey)Close the registry keystatic booleanregistryCreateKey(WinReg.HKEY hKey, java.lang.String keyName)Create a registry key.static booleanregistryCreateKey(WinReg.HKEY hKey, java.lang.String keyName, int samDesiredExtra)Create a registry key.static booleanregistryCreateKey(WinReg.HKEY root, java.lang.String parentPath, java.lang.String keyName)Create a registry key.static booleanregistryCreateKey(WinReg.HKEY root, java.lang.String parentPath, java.lang.String keyName, int samDesiredExtra)Create a registry key.static voidregistryDeleteKey(WinReg.HKEY hKey, java.lang.String keyName)Delete a registry key.static voidregistryDeleteKey(WinReg.HKEY root, java.lang.String keyPath, java.lang.String keyName)Delete a registry key.static voidregistryDeleteKey(WinReg.HKEY root, java.lang.String keyPath, java.lang.String keyName, int samDesiredExtra)Delete a registry key.static voidregistryDeleteValue(WinReg.HKEY hKey, java.lang.String valueName)Delete a registry value.static voidregistryDeleteValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String valueName)Delete a registry value.static voidregistryDeleteValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String valueName, int samDesiredExtra)Delete a registry value.static byte[]registryGetBinaryValue(WinReg.HKEY hKey, java.lang.String value)Get a registry REG_BINARY value.static byte[]registryGetBinaryValue(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry REG_BINARY value.static byte[]registryGetBinaryValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry REG_BINARY value.static java.lang.StringregistryGetExpandableStringValue(WinReg.HKEY hKey, java.lang.String value)Get a registry REG_EXPAND_SZ value.static java.lang.StringregistryGetExpandableStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry REG_EXPAND_SZ value.static java.lang.StringregistryGetExpandableStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry REG_EXPAND_SZ value.static intregistryGetIntValue(WinReg.HKEY hKey, java.lang.String value)Get a registry DWORD value.static intregistryGetIntValue(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry DWORD value.static intregistryGetIntValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry DWORD value.static WinReg.HKEYByReferenceregistryGetKey(WinReg.HKEY root, java.lang.String keyPath, int samDesired)Get a registry key, the caller is responsible to close the key after use.static java.lang.String[]registryGetKeys(WinReg.HKEY hKey)Get names of the registry key's sub-keys.static java.lang.String[]registryGetKeys(WinReg.HKEY root, java.lang.String keyPath)Get names of the registry key's sub-keys.static java.lang.String[]registryGetKeys(WinReg.HKEY root, java.lang.String keyPath, int samDesiredExtra)Get names of the registry key's sub-keys.static longregistryGetLongValue(WinReg.HKEY hKey, java.lang.String value)Get a registry QWORD value.static longregistryGetLongValue(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry QWORD value.static longregistryGetLongValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry QWORD value.static java.lang.String[]registryGetStringArray(WinReg.HKEY hKey, java.lang.String value)Get a registry REG_MULTI_SZ value.static java.lang.String[]registryGetStringArray(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry REG_MULTI_SZ value.static java.lang.String[]registryGetStringArray(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry REG_MULTI_SZ value.static java.lang.StringregistryGetStringValue(WinReg.HKEY hKey, java.lang.String value)Get a registry REG_SZ value.static java.lang.StringregistryGetStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value)Get a registry REG_SZ value.static java.lang.StringregistryGetStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Get a registry REG_SZ value.static java.lang.ObjectregistryGetValue(WinReg.HKEY hkKey, java.lang.String subKey, java.lang.String lpValueName)Get a registry value and returns a java object depending on the value type.static java.util.TreeMap<java.lang.String,java.lang.Object>registryGetValues(WinReg.HKEY hKey)Get a table of registry values.static java.util.TreeMap<java.lang.String,java.lang.Object>registryGetValues(WinReg.HKEY root, java.lang.String keyPath)Get a table of registry values.static java.util.TreeMap<java.lang.String,java.lang.Object>registryGetValues(WinReg.HKEY root, java.lang.String keyPath, int samDesiredExtra)Get a table of registry values.static booleanregistryKeyExists(WinReg.HKEY root, java.lang.String key)Checks whether a registry key exists.static booleanregistryKeyExists(WinReg.HKEY root, java.lang.String key, int samDesiredExtra)Checks whether a registry key exists.static WinReg.HKEYByReferenceregistryLoadAppKey(java.lang.String fileName, int samDesired, int dwOptions)Loads the specified registry hive as an application hive.static Advapi32Util.InfoKeyregistryQueryInfoKey(WinReg.HKEY hKey, int lpcbSecurityDescriptor)Queries the information about a specified key.static Advapi32Util.EnumKeyregistryRegEnumKey(WinReg.HKEY hKey, int dwIndex)Queries the information about a specified key.static voidregistrySetBinaryValue(WinReg.HKEY hKey, java.lang.String name, byte[] data)Set a binary value in registry.static voidregistrySetBinaryValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, byte[] data)Set a binary value in registry.static voidregistrySetBinaryValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, byte[] data, int samDesiredExtra)Set a binary value in registry.static voidregistrySetExpandableStringValue(WinReg.HKEY hKey, java.lang.String name, java.lang.String value)Set an expandable string value in registry.static voidregistrySetExpandableStringValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String value)Set a string value in registry.static voidregistrySetExpandableStringValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String value, int samDesiredExtra)Set a string value in registry.static voidregistrySetIntValue(WinReg.HKEY hKey, java.lang.String name, int value)Set an integer value in registry.static voidregistrySetIntValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, int value)Set an integer value in registry.static voidregistrySetIntValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, int value, int samDesiredExtra)Set an integer value in registry.static voidregistrySetLongValue(WinReg.HKEY hKey, java.lang.String name, long value)Set a long value in registry.static voidregistrySetLongValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, long value)Set a long value in registry.static voidregistrySetLongValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, long value, int samDesiredExtra)Set a long value in registry.static voidregistrySetStringArray(WinReg.HKEY hKey, java.lang.String name, java.lang.String[] arr)Set a string array value in registry.static voidregistrySetStringArray(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String[] arr)Set a string array value in registry.static voidregistrySetStringArray(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String[] arr, int samDesiredExtra)Set a string array value in registry.static voidregistrySetStringValue(WinReg.HKEY hKey, java.lang.String name, java.lang.String value)Set a string value in registry.static voidregistrySetStringValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String value)Set a string value in registry.static voidregistrySetStringValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String value, int samDesiredExtra)Set a string value in registry.static booleanregistryValueExists(WinReg.HKEY root, java.lang.String key, java.lang.String value)Checks whether a registry value exists.static booleanregistryValueExists(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)Checks whether a registry value exists.(package private) static java.lang.String[]regMultiSzBufferToStringArray(Memory data)Convert the null-delimited buffer of strings returned from registry values of typeWinNT.REG_MULTI_SZto an array of strings.static voidsetFileSecurityDescriptor(java.io.File file, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)Sets a file's Security Descriptor.static voidsetSecurityDescriptorForObject(java.lang.String absoluteObjectPath, int objectType, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)Set a self relative security descriptor for the given object type.
-
-
-
Method Detail
-
getUserName
public static java.lang.String getUserName()
Retrieves the name of the user associated with the current thread.- Returns:
- A user name.
-
getAccountByName
public static Advapi32Util.Account getAccountByName(java.lang.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(java.lang.String systemName, java.lang.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(java.lang.String systemName, WinNT.PSID sid)
Get the account by SID.- Parameters:
systemName- Name of the system.sid- SID.- Returns:
- Account.
-
convertSidToStringSid
public static java.lang.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(java.lang.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(java.lang.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.
-
alignOnDWORD
public static int alignOnDWORD(int cbAcl)
Align cbAcl on a DWORD- Parameters:
cbAcl- size to align- Returns:
- the aligned size
-
getAceSize
public static int getAceSize(int sidLength)
Helper function to calculate the size of an ACE for a given PSID size- Parameters:
sidLength- length of the sid- Returns:
- size of the ACE
-
getAccountBySid
public static Advapi32Util.Account getAccountBySid(java.lang.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(java.lang.String systemName, java.lang.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.
-
getTokenPrimaryGroup
public static Advapi32Util.Account getTokenPrimaryGroup(WinNT.HANDLE hToken)
This function returns the primary group associated with a security token, such as a user token.- Parameters:
hToken- Token.- Returns:
- Token primary group.
-
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, java.lang.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.
-
registryKeyExists
public static boolean registryKeyExists(WinReg.HKEY root, java.lang.String key, int samDesiredExtra)
Checks whether a registry key exists.- Parameters:
root- HKEY_LOCAL_MACHINE, etc.key- Path to the registry key.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- True if the key exists.
-
registryValueExists
public static boolean registryValueExists(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryValueExists
public static boolean registryValueExists(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Checks whether a registry value exists.- Parameters:
root- HKEY_LOCAL_MACHINE, etc.key- Registry key path.value- Value name.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- True if the value exists.
-
registryGetStringValue
public static java.lang.String registryGetStringValue(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetStringValue
public static java.lang.String registryGetStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry REG_SZ value.- Parameters:
root- Root key.key- Registry path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- String value.
-
registryGetStringValue
public static java.lang.String registryGetStringValue(WinReg.HKEY hKey, java.lang.String value)
Get a registry REG_SZ value.- Parameters:
hKey- Parent Key.value- Name of the value to retrieve.- Returns:
- String value.
-
registryGetExpandableStringValue
public static java.lang.String registryGetExpandableStringValue(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetExpandableStringValue
public static java.lang.String registryGetExpandableStringValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry REG_EXPAND_SZ value.- Parameters:
root- Root key.key- Registry path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- String value.
-
registryGetExpandableStringValue
public static java.lang.String registryGetExpandableStringValue(WinReg.HKEY hKey, java.lang.String value)
Get a registry REG_EXPAND_SZ value.- Parameters:
hKey- Parent Key.value- Name of the value to retrieve.- Returns:
- String value.
-
registryGetStringArray
public static java.lang.String[] registryGetStringArray(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetStringArray
public static java.lang.String[] registryGetStringArray(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry REG_MULTI_SZ value.- Parameters:
root- Root key.key- Registry path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- String value.
-
registryGetStringArray
public static java.lang.String[] registryGetStringArray(WinReg.HKEY hKey, java.lang.String value)
Get a registry REG_MULTI_SZ value.- Parameters:
hKey- Parent Key.value- Name of the value to retrieve.- Returns:
- String value.
-
regMultiSzBufferToStringArray
static java.lang.String[] regMultiSzBufferToStringArray(Memory data)
Convert the null-delimited buffer of strings returned from registry values of typeWinNT.REG_MULTI_SZto an array of strings.- Parameters:
data- A buffer containing strings delimited by a null character, ending with two null characters.- Returns:
- An array of strings corresponding to the strings in the buffer.
-
registryGetBinaryValue
public static byte[] registryGetBinaryValue(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetBinaryValue
public static byte[] registryGetBinaryValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry REG_BINARY value.- Parameters:
root- Root key.key- Registry path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- String value.
-
registryGetBinaryValue
public static byte[] registryGetBinaryValue(WinReg.HKEY hKey, java.lang.String value)
Get a registry REG_BINARY value.- Parameters:
hKey- Parent Key.value- Name of the value to retrieve.- Returns:
- String value.
-
registryGetIntValue
public static int registryGetIntValue(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetIntValue
public static int registryGetIntValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry DWORD value.- Parameters:
root- Root key.key- Registry key path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- Integer value.
-
registryGetIntValue
public static int registryGetIntValue(WinReg.HKEY hKey, java.lang.String value)
Get a registry DWORD value.- Parameters:
hKey- Parent key.value- Name of the value to retrieve.- Returns:
- Integer value.
-
registryGetLongValue
public static long registryGetLongValue(WinReg.HKEY root, java.lang.String key, java.lang.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.
-
registryGetLongValue
public static long registryGetLongValue(WinReg.HKEY root, java.lang.String key, java.lang.String value, int samDesiredExtra)
Get a registry QWORD value.- Parameters:
root- Root key.key- Registry key path.value- Name of the value to retrieve.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- Integer value.
-
registryGetLongValue
public static long registryGetLongValue(WinReg.HKEY hKey, java.lang.String value)
Get a registry QWORD value.- Parameters:
hKey- Parent key.value- Name of the value to retrieve.- Returns:
- Integer value.
-
registryGetValue
public static java.lang.Object registryGetValue(WinReg.HKEY hkKey, java.lang.String subKey, java.lang.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, java.lang.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 hKey, java.lang.String keyName, int samDesiredExtra)
Create a registry key.- Parameters:
hKey- Parent key.keyName- Key name.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- True if the key was created, false otherwise.
-
registryCreateKey
public static boolean registryCreateKey(WinReg.HKEY root, java.lang.String parentPath, java.lang.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.
-
registryCreateKey
public static boolean registryCreateKey(WinReg.HKEY root, java.lang.String parentPath, java.lang.String keyName, int samDesiredExtra)
Create a registry key.- Parameters:
root- Root key.parentPath- Path to an existing registry key.keyName- Key name.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_CREATE_SUB_KEY. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- True if the key was created, false otherwise.
-
registrySetIntValue
public static void registrySetIntValue(WinReg.HKEY hKey, java.lang.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, java.lang.String keyPath, java.lang.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.
-
registrySetIntValue
public static void registrySetIntValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, int value, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registrySetLongValue
public static void registrySetLongValue(WinReg.HKEY hKey, java.lang.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, java.lang.String keyPath, java.lang.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.
-
registrySetLongValue
public static void registrySetLongValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, long value, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registrySetStringValue
public static void registrySetStringValue(WinReg.HKEY hKey, java.lang.String name, java.lang.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, java.lang.String keyPath, java.lang.String name, java.lang.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.
-
registrySetStringValue
public static void registrySetStringValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String value, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registrySetExpandableStringValue
public static void registrySetExpandableStringValue(WinReg.HKEY hKey, java.lang.String name, java.lang.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, java.lang.String keyPath, java.lang.String name, java.lang.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 root, java.lang.String keyPath, java.lang.String name, java.lang.String value, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registrySetStringArray
public static void registrySetStringArray(WinReg.HKEY hKey, java.lang.String name, java.lang.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, java.lang.String keyPath, java.lang.String name, java.lang.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.
-
registrySetStringArray
public static void registrySetStringArray(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, java.lang.String[] arr, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registrySetBinaryValue
public static void registrySetBinaryValue(WinReg.HKEY hKey, java.lang.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, java.lang.String keyPath, java.lang.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.
-
registrySetBinaryValue
public static void registrySetBinaryValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String name, byte[] data, int samDesiredExtra)
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.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registryDeleteKey
public static void registryDeleteKey(WinReg.HKEY hKey, java.lang.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, java.lang.String keyPath, java.lang.String keyName)
Delete a registry key.- Parameters:
root- Root key.keyPath- Path to an existing registry key.keyName- Name of the key to delete.
-
registryDeleteKey
public static void registryDeleteKey(WinReg.HKEY root, java.lang.String keyPath, java.lang.String keyName, int samDesiredExtra)
Delete a registry key.- Parameters:
root- Root key.keyPath- Path to an existing registry key.keyName- Name of the key to delete.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registryDeleteValue
public static void registryDeleteValue(WinReg.HKEY hKey, java.lang.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, java.lang.String keyPath, java.lang.String valueName)
Delete a registry value.- Parameters:
root- Root key.keyPath- Path to an existing registry key.valueName- Name of the value to delete.
-
registryDeleteValue
public static void registryDeleteValue(WinReg.HKEY root, java.lang.String keyPath, java.lang.String valueName, int samDesiredExtra)
Delete a registry value.- Parameters:
root- Root key.keyPath- Path to an existing registry key.valueName- Name of the value to delete.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ and WinNT.KEY_WRITE. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)
-
registryGetKeys
public static java.lang.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 java.lang.String[] registryGetKeys(WinReg.HKEY root, java.lang.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.
-
registryGetKeys
public static java.lang.String[] registryGetKeys(WinReg.HKEY root, java.lang.String keyPath, int samDesiredExtra)
Get names of the registry key's sub-keys.- Parameters:
root- Root key.keyPath- Path to a registry key.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- Returns:
- Array of registry key names.
-
registryGetKey
public static WinReg.HKEYByReference registryGetKey(WinReg.HKEY root, java.lang.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.
-
registryLoadAppKey
public static WinReg.HKEYByReference registryLoadAppKey(java.lang.String fileName, int samDesired, int dwOptions)
Loads the specified registry hive as an application hive.- Parameters:
fileName- Path to the filesamDesired- Access mask that specifies the desired access rights to thedwOptions- If this parameter is REG_PROCESS_APPKEY, the hive cannot be loaded again while it is loaded by the caller. This prevents access to this registry hive by another caller.
-
registryCloseKey
public static void registryCloseKey(WinReg.HKEY hKey)
Close the registry key- Parameters:
hKey- Registry key.
-
registryGetValues
public static java.util.TreeMap<java.lang.String,java.lang.Object> registryGetValues(WinReg.HKEY hKey)
Get a table of registry values.- Parameters:
hKey- Registry key.- Returns:
- Table of values.
-
registryGetValues
public static java.util.TreeMap<java.lang.String,java.lang.Object> registryGetValues(WinReg.HKEY root, java.lang.String keyPath)
Get a table of registry values.- Parameters:
root- Registry root.keyPath- Regitry key path.- Returns:
- Table of values.
-
registryGetValues
public static java.util.TreeMap<java.lang.String,java.lang.Object> registryGetValues(WinReg.HKEY root, java.lang.String keyPath, int samDesiredExtra)
Get a table of registry values.- Parameters:
root- Registry root.keyPath- Regitry key path.samDesiredExtra- Registry key security and access rights to be requested in addition to WinNT.KEY_READ. (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.)- 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.lpcbSecurityDescriptor- security descriptor- 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.dwIndex-- Returns:
- A InfoKey value object.
-
getEnvironmentBlock
public static java.lang.String getEnvironmentBlock(java.util.Map<java.lang.String,java.lang.String> environment)
Converts a map of environment variables to an environment block suitable forAdvapi32.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.ACE_HEADER[] getFileSecurity(java.lang.String fileName, boolean compact)
- Parameters:
fileName- path to the filecompact- if true compatible ACEs are merged if possible- Returns:
- list of ACEs in the DACL of the referenced file
-
getSecurityDescriptorForObject
public static Memory getSecurityDescriptorForObject(java.lang.String absoluteObjectPath, int objectType, boolean getSACL)
Get a self relative security descriptor for the given object type. The value is returned in Memory- Parameters:
absoluteObjectPath- A pointer to a null-terminated string that specifies the name of the object from which to retrieve security information. For descriptions of the string formats for the different object types, see SE_OBJECT_TYPE inAccCtrl.SE_OBJECT_TYPEobjectType- Object type referred to by the path. SeeAccCtrl.SE_OBJECT_TYPEfor valid definitions.getSACL- Get SACL of the object. SeeAdvapi32.GetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference)for process privilege requirements in getting the SACL.- Returns:
- Memory containing the self relative security descriptor
-
setSecurityDescriptorForObject
public static void setSecurityDescriptorForObject(java.lang.String absoluteObjectPath, int objectType, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)Set a self relative security descriptor for the given object type.- Parameters:
absoluteObjectPath- A pointer to a null-terminated string that specifies the name of the object from which to retrieve security information. For descriptions of the string formats for the different object types, seeAccCtrl.SE_OBJECT_TYPE.objectType- Object type referred to by the path. SeeAccCtrl.SE_OBJECT_TYPEfor valid definitions.securityDescriptor- A security descriptor to set.setOwner- Set the owner. The owner is extracted from securityDescriptor and must be valid, otherwise IllegalArgumentException is throw. SeeAdvapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)for process privilege requirements in getting the OWNER.setGroup- Set the group. The group is extracted from securityDescriptor and must be valid, otherwise IllegalArgumentException is throw.setDACL- Set the DACL. The DACL is extracted from securityDescriptor and must be valid, otherwise IllegalArgumentException is throw.setSACL- Set the SACL. The SACL is extracted from securityDescriptor and must be valid, otherwise IllegalArgumentException is throw. SeeAdvapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)for process privilege requirements in getting the SACL.setDACLProtectedStatus- Set DACL protected status as contained within securityDescriptor.control.setSACLProtectedStatus- Set SACL protected status as contained within securityDescriptor.control.
-
accessCheck
public static boolean accessCheck(java.io.File file, Advapi32Util.AccessCheckPermission permissionToCheck)Checks if the current process has the given permission for the file.- Parameters:
file- the file to checkpermissionToCheck- the permission to check for the file- Returns:
- true if has access, otherwise false
-
getFileSecurityDescriptor
public static WinNT.SECURITY_DESCRIPTOR_RELATIVE getFileSecurityDescriptor(java.io.File file, boolean getSACL)
Gets a file's Security Descriptor. Convenience wrapper getSecurityDescriptorForObject.- Parameters:
file- File object containing a path to a file system object.getSACL- Get the SACL. SeeAdvapi32.GetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference)for process privilege requirements in getting the SACL.- Returns:
- The file's Security Descriptor in self relative format.
-
setFileSecurityDescriptor
public static void setFileSecurityDescriptor(java.io.File file, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)Sets a file's Security Descriptor. Convenience wrapper setSecurityDescriptorForObject.- Parameters:
file- File object containing a path to a file system object.securityDescriptor- The security descriptor to set.setOwner- Set the owner. SeeAdvapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)for process privilege requirements in setting the owner.setGroup- Set the group.setDACL- Set the DACL.setSACL- Set the SACL. SeeAdvapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)for process privilege requirements in setting the SACL.setDACLProtectedStatus- Set DACL protected status as contained within securityDescriptor.control.setSACLProtectedStatus- Set SACL protected status as contained within securityDescriptor.control. *
-
encryptFile
public static void encryptFile(java.io.File file)
Encrypts a file or directory.- Parameters:
file- The file or directory to encrypt.
-
decryptFile
public static void decryptFile(java.io.File file)
Decrypts an encrypted file or directory.- Parameters:
file- The file or directory to decrypt.
-
fileEncryptionStatus
public static int fileEncryptionStatus(java.io.File file)
Checks the encryption status of a file.- Parameters:
file- The file to check the status for.- Returns:
- The status of the file.
-
disableEncryption
public static void disableEncryption(java.io.File directory, boolean disable)Disables or enables encryption of the specified directory and the files in it.- Parameters:
directory- The directory for which to enable or disable encryption.disable- TRUE to disable encryption. FALSE to enable it.
-
backupEncryptedFile
public static void backupEncryptedFile(java.io.File src, java.io.File destDir)Backup an encrypted file or folder without decrypting it. A file named "bar/sample.text" will be backed-up to "destDir/sample.text". A directory named "bar" will be backed-up to "destDir/bar". This method is NOT recursive. If you have an encrypted directory with encrypted files, this method must be called once for the directory, and once for each encrypted file to be backed-up.- Parameters:
src- The encrypted file or directory to backup.destDir- The directory where the backup will be saved.
-
-