Re: Shutdown Win2000/XP
- Posted by "Wolf" <wolfritz at king.igs.net> Mar 06, 2006
- 484 views
> Does anyone know how I can completely shutdown Win2000/XP using EU code? --shut down Windows, also, if ATX, power. --only tested on 98, 2K include dll.e include machine.e include misc.e constant KERNEL32=open_dll("kernel32.dll") ,GetVersion=define_c_func(KERNEL32,"GetVersion",{},C_UINT) ,GetCurrentProcess=define_c_func(KERNEL32,"GetCurrentProcess",{},C_UINT) ,hToken=allocate(4) ,ADVAPI32=open_dll("advapi32.dll") ,OpenProcessToken=define_c_func(ADVAPI32,"OpenProcessToken", {C_UINT,C_UINT,C_POINTER},C_UINT) ,TOKEN_ADJUST_PRIVILEGES=#20 ,TOKEN_QUERY=#8 ,struct_TOKEN_PRIVILEGES=allocate(16) --4 for count + 12 per privilege ,LookupPrivilegeValue=define_c_func(ADVAPI32,"LookupPrivilegeValueA", {C_POINTER,C_POINTER,C_POINTER},C_UINT) ,SE_SHUTDOWN_NAME=allocate_string("SeShutdownPrivilege") ,SE_PRIVILEGE_ENABLED=2 ,AdjustTokenPrivileges=define_c_func(ADVAPI32,"AdjustTokenPrivileges", {C_UINT,C_UINT,C_POINTER,C_UINT,C_POINTER,C_POINTER},C_UINT) --Win9x's really only need items below ,USER32=open_dll("user32.dll") ,ExitWindowsEx=define_c_func(USER32,"ExitWindowsEx",{C_UINT,C_UINT},C_UINT) ,EWX_SHUTDOWN=1 --,EWX_FORCE=4 --not used here function hi_word( atom d ) return floor(d/#10000) end function atom current, jk --is this NT/2000/XP? if hi_word( c_func(GetVersion,{}) ) < #8000 then mem_set(struct_TOKEN_PRIVILEGES,0,16) current=c_func(GetCurrentProcess,{}) jk=c_func(OpenProcessToken, {current,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hToken}) if jk then poke4(struct_TOKEN_PRIVILEGES,1) --only one privilege --to enable privilege poke4(struct_TOKEN_PRIVILEGES+12,SE_PRIVILEGE_ENABLED) --get Luid into same struct jk=c_func(LookupPrivilegeValue,{0,SE_SHUTDOWN_NAME,struct_TOKEN_PRIVILEGES+4}) jk=c_func(AdjustTokenPrivileges,{peek4u(hToken),0,struct_TOKEN_PRIVILEGES,0,0,0}) printf(1,"%s\n",{"..attempting NT/2000/XP shutdown"}) sleep(2) free_console() --apparently not necessary on NT/XP jk=c_func(ExitWindowsEx,{EWX_SHUTDOWN,0}) end if else printf(1,"%s\n",{"..attempting Win9x/ME shutdown"}) sleep(2) free_console() -- you *must* do this for 9x's, if using console. jk=c_func(ExitWindowsEx,{EWX_SHUTDOWN,0}) end if