Shutdown XP with one click code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Shutdown XP with one click code

Luke7Luke7 Posts: 156Member
If anyone is interested I have some source code that will shutdown WinXP/NT with a single mouseclick.


Comments

  • CollegeboyCollegeboy Posts: 1Member
    : If anyone is interested I have some source code that will shutdown WinXP/NT with a single mouseclick.
    :
    :
    :
    tell me how..Im a beginner in programming...my email is right there..
  • Luke7Luke7 Posts: 156Member
    : : If anyone is interested I have some source code that will shutdown WinXP/NT with a single mouseclick.
    : :
    : :
    : :
    : tell me how..Im a beginner in programming...my email is right there..
    :

    Here you go.

    ; shutdown.asm Shutdown an NT system (WinXP or NT)
    .386
    .model flat,stdcall
    option casemap:none

    include masm32includewindows.inc
    include masm32includeuser32.inc
    include masm32includekernel32.inc
    include masm32includeadvapi32.inc

    include masm32macrosmacros.asm

    includelib masm32libkernel32.lib
    includelib masm32libuser32.lib
    includelib masm32libadvapi32.lib

    ; Local Prototypes
    ;-------------------
    IsWinNT PROTO
    ReqNTPrivilege PROTO :DWORD

    .const
    ;-------------------
    dwMaskNT DWORD 2

    .data
    ;-------------------
    msg_NotNT BYTE "This is NOT an NT system.",0
    msg_NotPL BYTE "Privilege requested NOT granted.",13,"Unable to reboot.",0
    AppName BYTE "ASM Win NT Shutdown",0

    .code
    ;-------------------
    start:
    invoke IsWinNT
    ;----------------------------------------------------------------
    ; if is not an NT system we don't need other stuff and we can
    ; directly call ExitWindowsEx(), so this demo will exit.
    ;----------------------------------------------------------------
    .if eax == FALSE
    invoke MessageBox,NULL,addr msg_NotNT,addr AppName,MB_OK
    invoke ExitProcess,NULL
    .endif
    ;----------------------------------------------------------------
    ; with ReqNTPrivilege call, we ask for the 'SeShutdownPrivilege'
    ; note string names of possible privilege are in windows.inc
    ;----------------------------------------------------------------
    invoke ReqNTPrivilege, SADD("SeShutdownPrivilege")
    .if eax == FALSE
    invoke MessageBox,NULL,addr msg_NotPL,addr AppName,MB_OK
    invoke ExitProcess,NULL
    .endif
    invoke ExitWindowsEx, EWX_SHUTDOWN , 0 ; For Reboot, use EWX_REBOOT
    invoke ExitProcess,NULL
    ;
    ;
    IsWinNT proc
    ;------------------
    ; return TRUE (not zero) in eax if we are in win nt systems
    ;
    LOCAL osvi:OSVERSIONINFO
    ;
    mov osvi.dwOSVersionInfoSize, sizeof osvi
    invoke GetVersionEx, addr osvi
    .if eax == 0
    ret
    .endif
    mov eax, osvi.dwPlatformId
    and eax, dwMaskNT
    ret
    ;-------------------
    IsWinNT endp
    ;
    ;
    ReqNTPrivilege proc lpPrivilegeName:DWORD
    ;-------------------
    ; return TRUE (not zero) in eax if privilege is granted
    ; lpPrivilegeName parameter points to a string with request privilege name
    ;
    LOCAL hProcess:DWORD
    LOCAL hToken:DWORD
    LOCAL phToken:DWORD
    LOCAL RetLen:DWORD
    LOCAL pRetLen:DWORD
    LOCAL tkp:TOKEN_PRIVILEGES
    LOCAL tkp_old:TOKEN_PRIVILEGES
    ;
    invoke GetCurrentProcess
    mov hProcess, eax
    lea eax, hToken
    mov phToken, eax
    invoke OpenProcessToken, hProcess,
    TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY,
    phToken
    .if eax != FALSE
    lea eax, tkp.Privileges[0].Luid
    invoke LookupPrivilegeValue, NULL,
    lpPrivilegeName,
    eax
    lea eax, RetLen
    mov pRetLen, eax
    mov tkp.PrivilegeCount, 1
    mov tkp.Privileges[0].Attributes, SE_PRIVILEGE_ENABLED
    invoke AdjustTokenPrivileges, hToken,
    NULL,
    addr tkp,
    sizeof tkp_old,
    addr tkp_old,
    pRetLen
    .endif
    ret
    ;-------------------
    ReqNTPrivilege endp
    ;
    ;
    end start


  • dededede Posts: 145Member
    you can simpley write one line instead of all of this using ExitWindowsEx();
    [code]
    ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,0);
    [/code]
    dede:-)

Sign In or Register to comment.