public interface Kernel32
extends com.sun.jna.win32.StdCallLibrary
NativeWrapper
Modifier and Type | Interface and Description |
---|---|
static class |
Kernel32.FileTime
Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
|
static class |
Kernel32.SecurityAttribute
The SECURITY_ATTRIBUTES structure contains the security descriptor for an object
and specifies whether the handle retrieved by specifying this structure is inheritable.
|
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_FILE_NOT_FOUND
Define some constants to represent the last error code.
|
static int |
FILE_FLAG_BACKUP_SEMANTICS
For method
CreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
and CreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
the sixth parameter dwFlagsAndAttributes can take one of the following constants,
or any combination of them
FILE_FLAG_BACKUP_SEMANTICS: The file is being opened or created for a backup or restore operation. |
static int |
FILE_SHARE_DELETE |
static int |
FILE_SHARE_EXCLUSIVE
For method
CreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
and CreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The third parameter dwShareMode can take one of the following constants,
or any combination of them
FILE_SHARE_EXCLUSIVE: Prevents other processes from opening a file or device
if they request delete, read, or write access. |
static int |
FILE_SHARE_R_W_D |
static int |
FILE_SHARE_READ |
static int |
FILE_SHARE_WRITE |
static int |
GENERIC_ALL |
static int |
GENERIC_EXECUTE |
static int |
GENERIC_NO_ACCESS |
static int |
GENERIC_READ
For method
CreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
and CreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The second parameter dwDesiredAccess can take one of the following constants,
or any combination of them |
static int |
GENERIC_WRITE |
static Kernel32 |
INSTANCE |
static int |
OPEN_EXISTING
For method
CreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
and CreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The fifth parameter dwCreationDisposition can take one of the following constants,
or any combination of them
OPEN_EXISTING: Opens a file or device, only if it exists. |
static int |
SUCCESS_EXECUTE |
Modifier and Type | Method and Description |
---|---|
boolean |
CloseHandle(com.sun.jna.Pointer handle)
BOOL WINAPI CloseHandle(_in HANDLE hObject);
|
com.sun.jna.Pointer |
CreateFileA(java.lang.String lpFileName,
int dwDesiredAccess,
int dwShareMode,
Kernel32.SecurityAttribute lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
com.sun.jna.Pointer hTemplateFile)
Creates or opens a file or I/O device.
|
com.sun.jna.Pointer |
CreateFileW(java.lang.String lpFileName,
int dwDesiredAccess,
int dwShareMode,
Kernel32.SecurityAttribute lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
com.sun.jna.Pointer hTemplateFile) |
int |
FormatMessageA(int dwFlags,
com.sun.jna.Pointer lpSource,
int dwMessageId,
int dwLanguageId,
com.sun.jna.Pointer lpBuffer,
int nSize,
com.sun.jna.Pointer arrStrings)
Formats a message string.
|
boolean |
GetFileTime(com.sun.jna.Pointer hFile,
Kernel32.FileTime lpCreationTime,
Kernel32.FileTime lpLastAccessTime,
Kernel32.FileTime lpLastWriteTime)
{@literal
Retrieves the date and time that a file or directory was created, last accessed, and last modified.
|
int |
GetLastError()
Returns the calling thread's last-error code.
|
com.sun.jna.Pointer |
GetModuleHandleA(com.sun.jna.Pointer lpmoduleName)
HMODULE WINAPI GetModuleHandle( __in_opt LPCTSTR lpModuleName );
|
int |
GetProcessImageFileNameA(com.sun.jna.Pointer hProcess,
com.sun.jna.Pointer pImageFilename,
int nSize)
DWORD WINAPI GetProcessImageFileName(_in HANDLE hProcess, _out LPTSTR lpImageFileName, _in DWORD nSize);
|
com.sun.jna.Pointer |
OpenProcess(int dwDesiredAccess,
boolean bInheritHandle,
int dwProcessId)
HANDLE WINAPI OpenProcess(_in DWORD dwDesiredAccess, _in BOOL bInheritHandle, _in DWORD dwProcessId);
|
void |
Sleep(int ms)
VOID WINAPI Sleep(__in DWORD dwMilliseconds)
|
boolean |
Wow64EnableWow64FsRedirection(boolean enable) |
static final int GENERIC_READ
For methodCreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
andCreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The second parameter dwDesiredAccess can take one of the following constants, or any combination of them
static final int GENERIC_WRITE
static final int GENERIC_EXECUTE
static final int GENERIC_ALL
static final int GENERIC_NO_ACCESS
static final int FILE_SHARE_EXCLUSIVE
For methodCreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
andCreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The third parameter dwShareMode can take one of the following constants, or any combination of them FILE_SHARE_EXCLUSIVE: Prevents other processes from opening a file or device if they request delete, read, or write access. FILE_SHARE_READ: Enables subsequent open operations on a file or device to request read access. Otherwise, other processes cannot open the file or device if they request read access. If this flag is not specified, but the file or device has been opened for read access, the function fails. FILE_SHARE_WRITE: Enables subsequent open operations on a file or device to request write access. Otherwise, other processes cannot open the file or device if they request write access. If this flag is not specified, but the file or device has been opened for write access or has a file mapping with write access, the function fails. FILE_SHARE_DELETE: Enables subsequent open operations on a file or device to request delete access. Otherwise, other processes cannot open the file or device if they request delete access. If this flag is not specified, but the file or device has been opened for delete access, the function fails. Note: Delete access allows both delete and rename operations.
static final int FILE_SHARE_READ
static final int FILE_SHARE_WRITE
static final int FILE_SHARE_DELETE
static final int FILE_SHARE_R_W_D
static final int OPEN_EXISTING
For methodCreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
andCreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
The fifth parameter dwCreationDisposition can take one of the following constants, or any combination of them OPEN_EXISTING: Opens a file or device, only if it exists. If the specified file or device does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).
static final int FILE_FLAG_BACKUP_SEMANTICS
For methodCreateFileA(String, int, int, SecurityAttribute, int, int, Pointer)
andCreateFileW(String, int, int, SecurityAttribute, int, int, Pointer)
the sixth parameter dwFlagsAndAttributes can take one of the following constants, or any combination of them FILE_FLAG_BACKUP_SEMANTICS: The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. You must set this flag to obtain a handle to a directory.
static final int ERROR_FILE_NOT_FOUND
GetLastError()
static final int SUCCESS_EXECUTE
static final Kernel32 INSTANCE
int GetLastError()
Returns the calling thread's last-error code. The Return Value section of the WINAPI documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not. Remarks Functions executed by the calling thread set this value by calling the SetLastError function. You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions call SetLastError with a zero when they succeed, wiping out the error code set by the most recently failed function. To obtain an error string for system error codes, use the FormatMessage function. For a complete list of error codes provided by the operating system, see System Error Codes. The error codes returned by a function are not part of the Windows API specification and can vary by operating system or device driver. For this reason, we cannot provide the complete list of error codes that can be returned by each function. There are also many functions whose documentation does not include even a partial list of error codes that can be returned. Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no system error code has this bit set. If you are defining an error code for your application, set this bit to one. That indicates that the error code has been defined by an application, and ensures that your error code does not conflict with any error codes defined by the system. To convert a system error into an HRESULT value, use the HRESULT_FROM_WIN32 macro.
(msdn:system error codes)
int FormatMessageA(int dwFlags, com.sun.jna.Pointer lpSource, int dwMessageId, int dwLanguageId, com.sun.jna.Pointer lpBuffer, int nSize, com.sun.jna.Pointer arrStrings)
dwFlags
- -- [in] The formatting options, and how to interpret the lpSource parameter.
The low-order byte of dwFlags specifies how the function handles line breaks in the output
buffer. The low-order byte can also specify the maximum width of a formatted output line.
This parameter can be one or more of the following values.
The low-order byte of dwFlags can specify the maximum width of a formatted output line.
The following are possible values of the low-order byte:
0 -- There are no output line width restrictions. The function stores line breaks that
are in the message definition text into the output buffer.
FORMAT_MESSAGE_MAX_WIDTH_MASK -- 0x000000FF
The function ignores regular line breaks in the message definition text. The function
stores hard-coded line breaks in the message definition text into the output buffer. The
function generates no new line breaks.
lpSource
- -- [in_opt] -- The location of the message definition. The type of this
parameter depends upon the settings in the dwFlags parameter:dwMessageId
- - [in] - The message identifier for the requested message.
This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING.
dwLanguageId
- - [in] - The language identifier for the requested message.
This parameter is ignored if dwFlags includes FORMAT_MESSAGE_FROM_STRING. lpBuffer
- - [out] - A pointer to a buffer that receives the null-terminated string
that specifies the formatted message. If dwFlags includes FORMAT_MESSAGE_ALLOCATE_BUFFER,
the function allocates a buffer using the LocalAlloc function, and places the pointer to
the buffer at the address specified in lpBuffer.nSize
- - [in] - If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this
parameter specifies the size of the output buffer, in TCHARs.
If FORMAT_MESSAGE_ALLOCATE_BUFFER is set, this parameter specifies the minimum number of
TCHARs to allocate for an output buffer.arrStrings
- - [in_opt] - An array of values that are used as insert values in the
formatted message. A %1 in the format string indicates the first value in the Arguments
array; a %2 indicates the second argument; and so on. com.sun.jna.Pointer OpenProcess(int dwDesiredAccess, boolean bInheritHandle, int dwProcessId)
Process Access Rights values:
Standard:
DELETE (0x00010000L) Required to delete the object. READ_CONTROL (0x00020000L) Required to read information in the security descriptor for the object, not including the information in the SACL. To read or write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right. For more information, see MSDN SACL Access Right. SYNCHRONIZE (0x00100000L) The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state. WRITE_DAC (0x00040000L) Required to modify the DACL in the security descriptor for the object. WRITE_OWNER (0x00080000L) Required to change the owner in the security descriptor for the object. Process-specific Rights:
PROCESS_ALL_ACCESS All possible access rights for a process object. Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, #define _WIN32_WINNT _WIN32_WINNT_WINXP). For more information, see Using the Windows Headers. PROCESS_CREATE_PROCESS (0x0080) Required to create a process. PROCESS_CREATE_THREAD (0x0002) Required to create a thread. PROCESS_DUP_HANDLE (0x0040) Required to duplicate a handle using DuplicateHandle. PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob). PROCESS_QUERY_LIMITED_INFORMATION (0x1000) Required to retrieve certain information about a process (see QueryFullProcessImageName). A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION. Windows Server 2003 and Windows XP/2000: This access right is not supported. PROCESS_SET_INFORMATION (0x0200) Required to set certain information about a process, such as its priority class (see SetPriorityClass). PROCESS_SET_QUOTA (0x0100) Required to set memory limits using SetProcessWorkingSetSize. PROCESS_SUSPEND_RESUME (0x0800) Required to suspend or resume a process. PROCESS_TERMINATE (0x0001) Required to terminate a process using TerminateProcess. PROCESS_VM_OPERATION (0x0008) Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory). PROCESS_VM_READ (0x0010) Required to read memory in a process using ReadProcessMemory. PROCESS_VM_WRITE (0x0020) Required to write to memory in a process using WriteProcessMemory. SYNCHRONIZE (0x00100000L) Required to wait for the process to terminate using the wait functions.NOTE: Protected Processes:
Windows Vista introduces protected processes to enhance support for Digital Rights Management. The system restricts access to protected processes and the threads of protected processes. The following standard access rights are not allowed from a process to a protected process:DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER,
The following specific access rights are not allowed from a process to a protected process:
PROCESS_ALL_ACCESS, PROCESS_CREATE_PROCESS, PROCESS_CREATE_THREAD, PROCESS_DUP_HANDLE, PROCESS_QUERY_INFORMATION, PROCESS_SET_INFORMATION, PROCESS_SET_QUOTA, PROCESS_VM_OPERATION, PROCESS_VM_READ, PROCESS_VM_WRITE.
The PROCESS_QUERY_LIMITED_INFORMATION right was introduced to provide access to a subset of the information available through PROCESS_QUERY_INFORMATION.
dwDesiredAccess
- -- The access to the process object. This access right is
checked against the security descriptor for the process. This parameter
can be one or more of the process access rights.
If the caller has enabled the SeDebugPrivilege privilege, the requested
access is granted regardless of the contents of the security descriptor.bInheritHandle
- -- If this value is TRUE, processes created by this
process will inherit the handle. Otherwise, the processes do not inherit
this handle. Should almost always be FALSE?.dwProcessId
- -- The identifier of the local process to be opened.
If the specified process is the System Process (0x00000000), the function
fails and the last error code is ERROR_INVALID_PARAMETER. If the specified
process is the Idle process or one of the CSRSS processes, this function
fails and the last error code is ERROR_ACCESS_DENIED because their access
restrictions prevent user-level code from opening them.boolean CloseHandle(com.sun.jna.Pointer handle)
Releases the HANDLE references and resources from any HANDLE previously provided by the system of these types of objects:
Access token, Communications device, Console input, Console screen buffer, Event, File, File mapping, I/O completion port, Job, Mailslot, Memory resource notification, Mutex, Named pipe, Pipe, Process, Semaphore, Thread, Transaction, Waitable timer.
handle
- -- a HANDLE retrieved via a supported function requiring CloseHandle when done.int GetProcessImageFileNameA(com.sun.jna.Pointer hProcess, com.sun.jna.Pointer pImageFilename, int nSize)
Retrieves the name of the executable file for the specified process.
For Windows 7, Windows Server 2008 R2
Use the Psapi version for earlier versions of Windows.
hProcess
- [in] A handle to the process. The handle must have the
PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right.
For more information, see MSDN Process Security and Access Rights.
Windows Server 2003 and Windows XP: The handle must have the PROCESS_QUERY_INFORMATION access right.
pImageFileName
- [out] A pointer to a buffer that receives the full path to
the executable file.nSize
- [in] The size of the pImageFileName buffer, in characters.OpenProcess(int, boolean, int)
,
CloseHandle(Pointer)
,
Psapi.GetProcessImageFileNameA(Pointer, Pointer, int)
,
NativeWrapper.GetProcessFileName(Object)
com.sun.jna.Pointer GetModuleHandleA(com.sun.jna.Pointer lpmoduleName)
Retrieves a module handle for the specified module. The module must have been loaded by the calling process.
lpmoduleName
- -- The name of the loaded module (either a .dll or .exe file). If this parameter is NULL,
GetModuleHandle returns a handle to the file used to create the calling process (.exe file).void Sleep(int ms)
Suspends the execution of the current thread until the time-out interval elapses.
ms
- -- The time interval for which execution is to be suspended, in milliseconds.com.sun.jna.Pointer CreateFileA(java.lang.String lpFileName, int dwDesiredAccess, int dwShareMode, Kernel32.SecurityAttribute lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, com.sun.jna.Pointer hTemplateFile)
Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe. The function returns a handle that can be used to access the file or device for various types of I/O depending on the file or device and the flags and attributes specified. HANDLE WINAPI CreateFile( __in LPCTSTR lpFileName, __in DWORD dwDesiredAccess, __in DWORD dwShareMode, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, __in DWORD dwCreationDisposition, __in DWORD dwFlagsAndAttributes, __in_opt HANDLE hTemplateFile );
lpFileName
- [in]
The name of the file or device to be created or opened.dwDesiredAccess
- [in]
The requested access to the file or device, which can be summarized as read, write, both or neither zero).
If this parameter is zero, the application can query certain metadata such as file, directory,
or device attributes without accessing that file or device, even if GENERIC_READ access would have been denied.dwShareMode
- [in]
The requested sharing mode of the file or device, which can be read, write, both, delete, all of these, or nonelpSecurityAttributes
- [in, optional]
This parameter can be NULL.dwCreationDisposition
- [in]
An action to take on a file or device that exists or does not exist.dwFlagsAndAttributes
- [in]
The file or device attributes and flags, FILE_ATTRIBUTE_NORMAL being the most common default value for files.hTemplateFile
- [in, optional]
This parameter can be NULL.
For parameters: dwDesiredAccess, dwShareMode, dwCreationDisposition and dwFlagsAndAttributes, Please see
the constants definition at the beginning of this class.
com.sun.jna.Pointer CreateFileW(java.lang.String lpFileName, int dwDesiredAccess, int dwShareMode, Kernel32.SecurityAttribute lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, com.sun.jna.Pointer hTemplateFile)
boolean Wow64EnableWow64FsRedirection(boolean enable)
boolean GetFileTime(com.sun.jna.Pointer hFile, Kernel32.FileTime lpCreationTime, Kernel32.FileTime lpLastAccessTime, Kernel32.FileTime lpLastWriteTime)
Retrieves the date and time that a file or directory was created, last accessed, and last modified. BOOL WINAPI GetFileTime( __in HANDLE hFile, __out_opt LPFILETIME lpCreationTime, __out_opt LPFILETIME lpLastAccessTime, __out_opt LPFILETIME lpLastWriteTime );
hFile
- [in]
A handle to the file or directory for which dates and times are to be retrieved.
The handle must have been created using the CreateFile function with the GENERIC_READ access
right. For more information, see File Security and Access Rights.lpCreationTime
- [out, optional]
A pointer to a FILETIME structure to receive the date and time the file or directory was created.
This parameter can be NULL if the application does not require this information.lpLastAccessTime
- [out, optional]
A pointer to a FILETIME structure to receive the date and time the file or directory was last accessed.
The last access time includes the last time the file or directory was written to, read from, or,
in the case of executable files, run. This parameter can be NULL if the application does not require this information.lpLastWriteTime
- [out, optional]
A pointer to a FILETIME structure to receive the date and time the file or directory was last
written to, truncated, or overwritten (for example, with WriteFile or SetEndOfFile).
This date and time is not updated when file attributes or security descriptors are changed.
This parameter can be NULL if the application does not require this informationCopyright © SAS Institute. All Rights Reserved.