Advertisement
dev017

shutdown computer

Jul 30th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import com.sun.jna.Native;
  2. import com.sun.jna.platform.win32.Advapi32;
  3. import com.sun.jna.platform.win32.WinDef;
  4. import com.sun.jna.platform.win32.WinNT;
  5.  
  6. public class ShutdownComputer {
  7.     public static void main(String[] args) {
  8.         Advapi32 advapi32 = Native.load("Advapi32", Advapi32.class);
  9.         WinNT.HANDLE token = new WinNT.HANDLE();
  10.         advapi32.OpenProcessToken(advapi32.GetCurrentProcess(), WinNT.TOKEN_ADJUST_PRIVILEGES | WinNT.TOKEN_QUERY, token);
  11.  
  12.         WinNT.LUID luid = new WinNT.LUID();
  13.         advapi32.LookupPrivilegeValue(null, "SeShutdownPrivilege", luid);
  14.  
  15.         WinNT.TOKEN_PRIVILEGES tp = new WinNT.TOKEN_PRIVILEGES(1);
  16.         tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new WinDef.DWORD(WinNT.SE_PRIVILEGE_ENABLED));
  17.         advapi32.AdjustTokenPrivileges(token, false, tp, 0, null, null);
  18.  
  19.         advapi32.ExitWindowsEx(WinNT.EWX_SHUTDOWN, 0);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement