I am studying Edgar's standby program.
When run it says, "Procedure point OpenProcessToken could not be located in the dynamic link lib kernel32.dll."
When looking at the code, it looks almost like a hybrid C and assembly program.
I get a lot of invalid chars in the path. ??
Andy
MAGNUM,
Here is the MSDN documentation for: OpenProcessToken Function (http://msdn.microsoft.com/en-us/library/windows/desktop/aa379295(v=vs.85).aspx)
If you scroll down the page, you will notice that the executable code is contained in: Advapi32.dll
The most reliable technique for this that I have found is to call LoadLibrary (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx), and then GetProcAddress
(http://msdn.microsoft.com/en-us/library/windows/apps/ms683212(v=vs.85).aspx) That way you can check the return value of each routine for error values,...and, you won't crash your program.
...Where did you find EDGAR's system standby program ??? I searched the Old UK MASM Forum, and could not find it with the advanced search feature.
I will study it.
Andy
Forgot to add this to last post.
I came up with this and works O.K.
; Suspend.asm Suspend computer
;
;
;
.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
WaterMark db "SiegeWorks ð__ð" ; Alt 240 char
%Date db " &@Date " ; Compile date
%time db " &@Time "
AssemblerHome db "HTTP://MASM32.COM/BOARD "
msg_NotNT db "This is NOT an NT system.",0
msg_NotPL db "Privilege requested NOT granted.",13,"Unable to reboot.",0
OutputBuffer BYTE 512 dup(0)
Provider_Name BYTE 'The provider', 0
Failed BYTE 'Failure',0
Success BYTE 'Success', 0
AppName BYTE 'SiegeWorks ',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 SetSystemPowerState,TRUE,FALSE
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