News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Modify some shutdown code

Started by skywalker, August 23, 2005, 07:54:09 PM

Previous topic - Next topic

skywalker

I have looked over some Win NT shutdown code and I think this is where the meat is
at. I would like to modify it to just shut down with a double click.
No dialogs or buttons, but I'll probably embed an icon for the desktop.
(I didn't post the whole code, cuz many have already seen it)

I'll make sure no WP apps are open at the time.

I forgot what to put around code fragments.

Thanks.

      .if ovi.dwPlatformId == VER_PLATFORM_WIN32_NT
             mov tkp.Privileges[0].Attributes,0
           invoke AdjustTokenPrivileges,hToken,FALSE,ADDR tkp,0,NULL,0
               invoke CloseHandle,hToken
           .endif
           jmp Quitter2

       .elseif wParam==IDM_ARROPT1
             mov config, 00000001h
             invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT1,MF_BYCOMMAND
             invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
             invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR1,FALSE
             mov config,31h
       .elseif wParam==IDM_ARROPT2
             mov config, 00000002h
             invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT2,MF_BYCOMMAND
             invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
             invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR2,FALSE
             mov config,32h
       .elseif wParam==IDM_ARROPT3
             mov config, 00000003h
             invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT3,MF_BYCOMMAND
             invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
             invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR3,FALSE
             mov config,33h



PBrennick

The changes you would make to 'this' part of the code would be to remove the menu stuff - any lines dealing with CheckMenuRadioItem and SetMenuDefaultItem.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on August 23, 2005, 11:59:21 PM
The changes you would make to 'this' part of the code would be to remove the menu stuff - any lines dealing with CheckMenuRadioItem and SetMenuDefaultItem.

Paul

I appreciate your reply. I posted most of the code. I only want this to shutdown the computer, not become resident
or offer options to reboot or log off either. I hope that makes sense.

Thanks,
               Andy

.data
inf MENUITEMINFO <> ;structure

szKeyName               db "Software\Vom\ArretdeZindows"  ,0
szStringValueConfig     db "Config",0
szKeyName2              db "Software\Microsoft\Windows\CurrentVersion\Run"  ,0
szStringValueDemar      db "ArrêtdeZindows",0

MsgCaption              db "Error"    ,0
ErrorMessage            db "Write or read error in the registry !!!"             ,0

RadioButton1Text        db "&ShutDown the system",0
RadioButton2Text        db "&Reboot the system",0
RadioButton3Text        db "&Log off the current user",0
RadioButtonOPT1Text     db "By default : ShutDown the system",0
RadioButtonOPT2Text     db "By default : Reboot the system",0
RadioButtonOPT3Text     db "By default : Log off the current user",0
RadioDemarText          db "&Load on start",0
AproposString         db "&About",0
ExitString             db "&Exit",0
szDisplayName           db "Arrêt de Zindows",0
TheText                 db "Are-you sure you want to exit Arret de Zindows ?",0

hWnd                    dd 0
hIconImage              dd 0
hIcon                   dd 0

PthBuffer               dw 129 dup(?)
config2                 db 128 dup(0)
Taille2                 DWORD SIZEOF config2

szShut  db "SeShutdownPrivilege",0

.data?
ovi         OSVERSIONINFO <>
tkp         TOKEN_PRIVILEGES <>
note                    NOTIFYICONDATA <>
hPopupMenu               dd ?
hInstance               HINSTANCE ?
config                  dw ?
EsAi                    dd ?
hToken         dd ?

.const
WM_SHELLNOTIFY          equ WM_USER+5
IDI_TRAY                equ 0
IDM_APROPOS             equ 1005
IDM_EXIT               equ 1010
IDM_ARR1                equ 5001
IDM_ARR2                equ 5002
IDM_ARR3                equ 5003
IDM_ARROPT1             equ 5004
IDM_ARROPT2             equ 5005
IDM_ARROPT3             equ 5006
IDM_SEPAR               equ 1006
IDM_DEMAR               equ 5007

.code
start:
      invoke GetModuleHandle, NULL
      mov hInstance, eax

      invoke WinMain,hInstance,NULL,SW_SHOWDEFAULT
        invoke Shell_NotifyIcon,NIM_DELETE,addr note
      invoke ExitProcess,NULL

; #########################################################################

WinMain proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdShow   :DWORD

      ;====================
      ; Put LOCALs on stack
      ;====================

      LOCAL wc   :WNDCLASSEX
      LOCAL msg  :MSG

      ;==================================================
      ; Fill WNDCLASSEX structure with required variables
      ;==================================================

      invoke LoadIcon,hInst,200    ; icon ID
      mov hIcon, eax

      szText szClassName,"Win_Class"

      mov wc.cbSize,         sizeof WNDCLASSEX
      mov wc.style,          CS_HREDRAW or CS_VREDRAW \
                             or CS_BYTEALIGNWINDOW
      mov wc.lpfnWndProc,    offset WndProc
      mov wc.cbClsExtra,     NULL
      mov wc.cbWndExtra,     NULL
      m2m wc.hInstance,      hInst
      mov wc.hbrBackground,  COLOR_WINDOW
      mov wc.lpszMenuName,   NULL
      mov wc.lpszClassName,  offset szClassName
      m2m wc.hIcon,          hIcon
        invoke LoadCursor,NULL,IDC_ARROW
      mov wc.hCursor,        eax
      m2m wc.hIconSm,        hIcon


mov inf.cbSize,         SIZEOF MENUITEMINFO
mov inf.fMask,          MIIM_STATE
mov inf.fType,          MFT_RADIOCHECK
mov inf.fState,         MFS_CHECKED
m2m inf.wID,            hWnd
m2m inf.hSubMenu,       hPopupMenu
mov inf.hbmpChecked,    NULL
mov inf.hbmpUnchecked,  NULL
mov inf.dwItemData,     IDM_DEMAR
mov inf.dwTypeData,     MFT_STRING
mov inf.cch,            21d



      invoke RegisterClassEx, ADDR wc

      ;================================

   invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR szClassName,ADDR szDisplayName,\
           0,0,0,0,0,0,0,hInst,0

      mov   hWnd,eax

      invoke LoadMenu,hInst,600  ; menu ID
      invoke SetMenu,hWnd,eax

      invoke ShowWindow,hWnd,SW_MINIMIZE
      invoke UpdateWindow,hWnd

      ;===================================
      ; Loop until PostQuitMessage is sent
      ;===================================

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain endp

; #########################################################################

WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    LOCAL pt:POINT

    .if uMsg == WM_COMMAND
                    mov     eax, wParam

    ;======== menu commands ========
        .if wParam==IDM_APROPOS
            About:
          .data
          AboutTtl db "Arrêt de Zindows",0
          AboutMsg db "Thomas VIDAL",0
          .code
          invoke ShellAbout,hWin,ADDR AboutTtl,ADDR AboutMsg,hIcon

        .elseif wParam==IDM_EXIT
        invoke MessageBox,hWin,ADDR TheText,ADDR szDisplayName,MB_YESNO + MB_ICONQUESTION
   cmp eax, IDNO
   jne Quitter2
            ret
        Quitter2:
        invoke PostQuitMessage,NULL
        ret

        .elseif wParam==IDM_ARR1
            mov eax, 1
            jmp privileges
        .elseif wParam==IDM_ARR2
            mov eax, 2
            jmp privileges
        .elseif wParam==IDM_ARR3
            mov eax, 0


   privileges:
      push eax
          mov ovi.dwOSVersionInfoSize, sizeof ovi
          invoke GetVersionEx,ADDR ovi

            .if ovi.dwPlatformId == VER_PLATFORM_WIN32_NT
                invoke GetCurrentProcess
                    invoke OpenProcessToken,eax,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,ADDR hToken
                            invoke LookupPrivilegeValue,NULL,addr szShut,addr tkp.Privileges[0].Luid   
                            mov tkp.PrivilegeCount,1
                         mov tkp.Privileges[0].Attributes,SE_PRIVILEGE_ENABLED
                              invoke AdjustTokenPrivileges,hToken,FALSE, ADDR tkp, 0, NULL, 0
            .endif
      pop eax
                invoke ExitWindowsEx,eax,NULL
                   
       .if ovi.dwPlatformId == VER_PLATFORM_WIN32_NT
              mov tkp.Privileges[0].Attributes,0
            invoke AdjustTokenPrivileges,hToken,FALSE,ADDR tkp,0,NULL,0
                invoke CloseHandle,hToken
            .endif
            jmp Quitter2

        .elseif wParam==IDM_ARROPT1
              mov config, 00000001h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT1,MF_BYCOMMAND
              invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR1,FALSE
              mov config,31h
        .elseif wParam==IDM_ARROPT2
              mov config, 00000002h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT2,MF_BYCOMMAND
              invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR2,FALSE
              mov config,32h
        .elseif wParam==IDM_ARROPT3
              mov config, 00000003h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT3,MF_BYCOMMAND
              invoke SetRegKeyDW , ADDR config, ADDR szKeyName, ADDR szStringValueConfig
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR3,FALSE
              mov config,33h

        .elseif wParam==IDM_DEMAR
                .if inf.fState==MFS_CHECKED
                    mov EsAi,TRUE
                    mov inf.fState,         MFS_UNCHECKED
                    invoke SetMenuItemInfo,hPopupMenu,IDM_DEMAR,FALSE,ADDR inf
      invoke lstrlen, addr PthBuffer
      inc eax
                    invoke SetRegKeysz , ADDR PthBuffer, ADDR szKeyName2, ADDR szStringValueDemar, eax
                .elseif inf.fState==MFS_UNCHECKED
                    mov EsAi,FALSE
                    mov inf.fState,         MFS_CHECKED
                    invoke SetMenuItemInfo,hPopupMenu,IDM_DEMAR,FALSE,ADDR inf
      invoke lstrlen, addr PthBuffer
      inc eax
                    invoke SetRegKeysz , ADDR PthBuffer, ADDR szKeyName2, ADDR szStringValueDemar, eax
                .endif
        .endif
    ;====== end menu commands ======

    .elseif uMsg == WM_CREATE
.data
NomFic db "arret.exe",0
.code
      invoke GetAppPath,ADDR PthBuffer
      invoke lstrcat,ADDR PthBuffer,ADDR NomFic

      invoke CreatePopupMenu
      mov hPopupMenu,eax
;      invoke AppendMenu,hPopupMenu,MF_STRING+MF_GRAYED,IDM_ARR1,addr RadioButton1Text  ;Grisé
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARR1,addr RadioButton1Text
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARR2,addr RadioButton2Text
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARR3,addr RadioButton3Text
      invoke AppendMenu,hPopupMenu,MF_SEPARATOR,IDM_SEPAR,NULL
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARROPT1,addr RadioButtonOPT1Text
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARROPT2,addr RadioButtonOPT2Text
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_ARROPT3,addr RadioButtonOPT3Text
      invoke AppendMenu,hPopupMenu,MF_SEPARATOR,IDM_SEPAR,NULL
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_DEMAR,addr RadioDemarText
      invoke AppendMenu,hPopupMenu,MF_SEPARATOR,IDM_SEPAR,NULL
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_APROPOS,addr AproposString
      invoke AppendMenu,hPopupMenu,MF_STRING,IDM_EXIT,addr ExitString

    invoke GetRegKeyDW, ADDR config, ADDR szKeyName, ADDR szStringValueConfig
            .IF config == 00000001h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT1,MF_BYCOMMAND
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR1,FALSE
            .ELSEIF config == 00000002h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT2,MF_BYCOMMAND
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR2,FALSE
            .ELSEIF config == 00000003h
              invoke CheckMenuRadioItem,hPopupMenu,IDM_ARROPT1,IDM_ARROPT3,IDM_ARROPT3,MF_BYCOMMAND
              invoke SetMenuDefaultItem,hPopupMenu,IDM_ARR3,FALSE
            .ENDIF

    invoke GetRegKeysz , ADDR config2, ADDR szKeyName2, ADDR szStringValueDemar, ADDR Taille2
                .IF EsAi == FALSE
                    mov inf.fState,         MFS_UNCHECKED
                    invoke SetMenuItemInfo,hPopupMenu,IDM_DEMAR,FALSE,ADDR inf
                .ELSEIF EsAi == TRUE
                    mov inf.fState,         MFS_CHECKED
                    invoke SetMenuItemInfo,hPopupMenu,IDM_DEMAR,FALSE,ADDR inf
                .ENDIF




    .elseif uMsg == WM_SIZE
      .if wParam==SIZE_MINIMIZED
         mov note.cbSize,sizeof NOTIFYICONDATA
         push hWnd
         pop note.hwnd
         mov note.uID,IDI_TRAY
         mov note.uFlags,NIF_ICON+NIF_MESSAGE+NIF_TIP
         mov note.uCallbackMessage,WM_SHELLNOTIFY
         invoke LoadIcon,hInstance,200
         mov note.hIcon,eax
         invoke lstrcpy,addr note.szTip,addr szDisplayName
         invoke ShowWindow,hWnd,SW_HIDE
         invoke Shell_NotifyIcon,NIM_ADD,addr note
      .endif

    .elseif uMsg == WM_CLOSE || uMsg == WM_DESTROY
        invoke PostQuitMessage,NULL
        ret

    .elseif uMsg==WM_SHELLNOTIFY
      .if wParam==IDI_TRAY
         .if lParam==WM_RBUTTONDOWN
            invoke GetCursorPos,addr pt
            invoke SetForegroundWindow,hWnd
            invoke TrackPopupMenu,hPopupMenu,TPM_RIGHTALIGN,pt.x,pt.y,NULL,hWnd,NULL
            invoke PostMessage,hWnd,WM_NULL,0,0
         .elseif lParam==WM_LBUTTONDBLCLK
                      invoke GetMenuDefaultItem,hPopupMenu,FALSE,GMDI_GOINTOPOPUPS
                        invoke SendMessage,hWnd,WM_COMMAND,eax,0
         .endif
      .endif
    .endif

    invoke DefWindowProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp

; ########################################################################
; -------------------------------------------------------------------------

SetRegKeysz  PROC lpszString:DWORD, lpszKeyName:DWORD, lpszValueName:DWORD, dwStringLength
    LOCAL Disp  :DWORD
    LOCAL pKey  :DWORD
    invoke RegCreateKeyEx, HKEY_LOCAL_MACHINE,
                             lpszKeyName, NULL, NULL,
                             REG_OPTION_NON_VOLATILE,
                             KEY_ALL_ACCESS, NULL,
                             addr pKey, addr Disp

.IF EsAi == TRUE
           invoke RegDeleteValue,pKey,lpszValueName
            .IF eax != ERROR_SUCCESS
                invoke MessageBox, NULL,ADDR ErrorMessage, ADDR MsgCaption, MB_OK
                invoke ExitProcess,NULL ; quit on any error
            .ENDIF
.ELSE
    .IF eax == ERROR_SUCCESS
        invoke RegSetValueEx, pKey, lpszValueName,
                              NULL, REG_SZ,
                              lpszString, dwStringLength

        invoke RegCloseKey, pKey
    .ENDIF
.ENDIF
    ret
SetRegKeysz ENDP

; -------------------------------------------------------------------------
GetRegKeysz PROC lpszBuffer:DWORD, lpszKeyName:DWORD,
                 lpszValueName:DWORD, dwStringLength:DWORD
    LOCAL TType  :DWORD
    LOCAL pKey  :DWORD
    mov TType, REG_SZ
    invoke RegCreateKeyEx, HKEY_LOCAL_MACHINE,
                             lpszKeyName, NULL, NULL,
                             REG_OPTION_NON_VOLATILE,
                             KEY_ALL_ACCESS, NULL,
                             addr pKey, addr TType
    .IF eax == ERROR_SUCCESS
        mov eax, REG_DWORD
        mov TType, eax
        invoke RegQueryValueEx, pKey, lpszValueName,
                             NULL, ADDR TType,
                             lpszBuffer, dwStringLength
        invoke lstrlen,lpszBuffer
            .IF eax == 0
                mov EsAi, FALSE
            .ELSEIF eax != 0
                mov EsAi, TRUE
            .ENDIF
        invoke RegCloseKey, pKey
    .ENDIF
    ret
GetRegKeysz ENDP

; -------------------------------------------------------------------------
SetRegKeyDW PROC lpdwValue:DWORD, lpszKeyName:DWORD, lpszValueName:DWORD
    LOCAL Disp  :DWORD
    LOCAL pKey  :DWORD
    DW_SIZE     EQU     4

    invoke RegCreateKeyEx, HKEY_LOCAL_MACHINE,
                             lpszKeyName, NULL, NULL,
                             REG_OPTION_NON_VOLATILE,
                             KEY_ALL_ACCESS, NULL,
                             addr pKey, addr Disp
    .IF eax == ERROR_SUCCESS
        invoke RegSetValueEx, pKey, lpszValueName,
                              NULL, REG_DWORD_LITTLE_ENDIAN,
                              lpdwValue, DW_SIZE
        invoke RegCloseKey, pKey
    .ENDIF
    ret
SetRegKeyDW ENDP

; -------------------------------------------------------------------------
GetRegKeyDW PROC lpdwValue:DWORD, lpszKeyName:DWORD, lpszValueName:DWORD
    LOCAL Temp  :DWORD
    LOCAL pKey  :DWORD
    LOCAL DWordSize:DWORD
    LOCAL DubWord:DWORD
    DW_SIZE EQU 4
    mov DWordSize, DW_SIZE
    invoke RegCreateKeyEx, HKEY_LOCAL_MACHINE,
                             lpszKeyName, NULL, NULL,
                             REG_OPTION_NON_VOLATILE,
                             KEY_ALL_ACCESS, NULL,
                             addr pKey, addr Temp
    .IF eax == ERROR_SUCCESS
        mov eax, REG_DWORD_LITTLE_ENDIAN
        mov Temp, eax
        invoke RegQueryValueEx, pKey, lpszValueName,
                             NULL, ADDR Temp,
                             lpdwValue, ADDR DWordSize
        invoke lstrlen,lpdwValue
            .IF eax == 0
                mov DubWord, 00000001h
                invoke RegSetValueEx, pKey, lpszValueName,
                                      NULL, REG_DWORD_LITTLE_ENDIAN,
                                      ADDR DubWord, DW_SIZE
                    .IF eax != ERROR_SUCCESS
                        invoke MessageBox, NULL,ADDR ErrorMessage, ADDR MsgCaption, MB_OK
                        invoke ExitProcess,NULL
                    .ENDIF

                invoke RegQueryValueEx, pKey, lpszValueName,
                                     NULL, ADDR Temp,
                                     lpdwValue, ADDR DWordSize
            .ENDIF
        invoke RegCloseKey, pKey
    .ENDIF
    ret
GetRegKeyDW ENDP

; -------------------------------------------------------------------------
; -------------------------------------------------------------------------
end start



PBrennick

skywalker,
This code works on NT systems.  It will shutdown the machine with no messages, etc.


    .386
    .model  flat,stdcall
    option  casemap:none

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\advapi32.inc

    include \masm32\macros\macros.asm

    includelib  \masm32\lib\kernel32.lib
    includelib  \masm32\lib\user32.lib
    includelib  \masm32\lib\advapi32.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




Attached is the complete project.
hth,
Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

skywalker

Quote from: PBrennick on August 24, 2005, 01:41:00 PM
skywalker,
This code works on NT systems.  It will shutdown the machine with no messages, etc.

Attached is the complete project.
hth,
Paul


Thanks it works great on WinXP. On my Win2K, it goes to the shutdown screen where you have to manually hit the power button. Is there some setting I need to change for power button?

Andy


PBrennick

skywalker,
Change EWX_SHUTDOWN to EWX_POWEROFF

Paul
The GeneSys Project is available from:
The Repository or My crappy website