Here is completed Batch file that generates java code, compile it, cleans the generated files, and runs in the background. You should be able to do something similar for macOS and Linux. Your reason for changing the power setting \Device\HarddiskVolume1\Users\Gili\.jdks\openjdk-15.0.2\bin\java.exe Then when the user runs powercfg /requests they see: SYSTEM: Throw new AssertionError("PowerClearRequest() failed") If (!kernel32.PowerClearRequest(handle, ())) Throw new AssertionError("PowerSetRequest() failed") If (!kernel32.PowerSetRequest(handle, ())) * Prevent the computer from going to sleep while the application is running. Throw new AssertionError(Native.getLastError()) If (handle = WinBase.INVALID_HANDLE_VALUE) Handle = kernel32.PowerCreateRequest(context) REASON_CONTEXT.ByReference context = new REASON_CONTEXT.ByReference() Ĭontext.version = POWER_REQUEST_CONTEXT_VERSION Ĭontext.flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING Ĭontext.simpleReasonString = new LPWSTR("Your reason for changing the power setting") Kernel32 = Native.load("kernel32", Kernel32.class) ULONG POWER_REQUEST_CONTEXT_VERSION = new ULONG(0) ĭWORD POWER_REQUEST_CONTEXT_SIMPLE_STRING = new DWORD(0x1) * requestType requestType is the ordinal value of PowerRequestType}īoolean PowerSetRequest(HANDLE powerRequestHandle, int requestType) īoolean PowerClearRequest(HANDLE powerRequestHandle, int requestType) * powerRequestHandle the handle returned by #PowerCreateRequest(REASON_CONTEXT.ByReference)} HANDLE PowerCreateRequest(REASON_CONTEXT.ByReference context) Private interface Kernel32 extends StdCallLibrary Public static class ByReference extends REASON_CONTEXT implements Structure.ByReference Public static class REASON_CONTEXT extends Structure Public enum "flags", "simpleReasonString"}) Check your platform at runtime, and if it happens to be Windows then the following will work: import A much cleaner solution is use JNA to tap into the native OS API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |