I've taken this code right out of my app and made the debug program just so you can test it too.
I'm getting access denied, not to be totally unexpected on a navy computer but when I took it home I got the same thing.
This code camedirectly out of an older app I had that DID work!
Anything I"mdoing ? DOes this work for you?
I put the abortsystemshutdown in after a sleep statement so you won't have to restart to test....the dialog box has a 30 second timeout.
Thanks,
This should drop right in and compile for you with 8.04
I'm getting access denied, not to be totally unexpected on a navy computer but when I took it home I got the same thing.
This code camedirectly out of an older app I had that DID work!
Anything I"mdoing ? DOes this work for you?
I put the abortsystemshutdown in after a sleep statement so you won't have to restart to test....the dialog box has a 30 second timeout.
Thanks,
This should drop right in and compile for you with 8.04
Code:
#Compile Exe #Dim All #Include "Win32api.inc" #Include "Reason.inc" Declare Function CCSGetComputerName()As String Declare Function SetShutdownPrivilege() As Long Declare Function GetLastErrorDescription( ByVal ErrorCode As Long ) As String '============================================<WINMAIN>================================================================== Function WinMain (ByVal hInstance As Long, _ ByVal hPrevInstance As Long, _ ByVal lpCmdLine As Asciiz Ptr, _ ByVal iCmdShow As Long) As Long Local Param1 As String Local Param2 As String Local lResult As Long Local ErrType As Long Local lpMachineName As Asciiz * 16 lpMachineName = CCSGetComputerName() Param1 = 30 Param2 = "DEBUGGING CODE - Test Test Test" lResult = SetShutdownPrivilege() 'Grab privilege just in case 'Errorchecking goes here lResult = InitiateSystemShutdownEx(ByVal VarPtr(lpMachineName),_ ByVal StrPtr(Param2),_ Val(Param1), _ ByVal %FALSE, _ ByVal %FALSE, _ %SHTDN_REASON_MAJOR_OTHER Or %SHTDN_REASON_MINOR_MAINTENANCE) 'lResult = InitiateSystemShutdown(lpMachineName, ByVal StrPtr(Param2), ByVal Val(Param1), ByVal %TRUE, ByVal %TRUE) If IsFalse lResult Then ErrType = GetLastError() MsgBox "Error: " & Format$(ErrType) & " - " & GetLastErrorDescription(ErrType) & $CrLf & "lResult (Non-Zero for success): " & Format$(lResult) End If 'Use this for debug Sleep 2500 AbortSystemShutdown lpMachineName End Function '========================================================================================== Function CCSGetComputerName()As String Local lResult As Long Local buff As Asciiz * 17 lResult = GetComputerName(buff, SizeOf(buff)) Function = buff End Function '========================================================================================== Function SetShutdownPrivilege() As Long Local hdlProcessHandle As Long Local hToken As Long Local tmpLuid As LUID Local tp As TOKEN_PRIVILEGES Local tpNewButIgnored As TOKEN_PRIVILEGES Local BufferLength As Long Local lBufferNeeded As Long %TOKEN_ADJUST_PRIVILEGES = &H20 %TOKEN_QUERY = &H8 %SE_PRIVILEGE_ENABLED = &H2 hdlProcessHandle = GetCurrentProcess() OpenProcessToken hdlProcessHandle, (%TOKEN_ADJUST_PRIVILEGES Or %TOKEN_QUERY), hToken ' Get the LUID for setSystemTime privilege. LookupPrivilegeValue "", "SeShutdownPrivilege",tmpLuid tp.PrivilegeCount = 1 ' One privilege to set tp.Privileges(1).pLuid = tmpLuid tp.Privileges(1).Attributes=%SE_PRIVILEGE_ENABLED ' Enable the SetSystemTime privilege in the access token of this process. BufferLength = SizeOf(tpNewButIgnored) Function= AdjustTokenPrivileges( ByVal hToken,ByVal 0,tp,ByVal BufferLength ,tpNewButIgnored,lBufferNeeded) End Function '========================================================================================== Function GetLastErrorDescription( ByVal ErrorCode As Long ) As String Dim sRtrnCode As Asciiz * 256 Dim lRet As Long If ErrorCode = %ERROR_SUCCESS Then Exit Function lRet = FormatMessage( %FORMAT_MESSAGE_FROM_SYSTEM, _ ByVal 0&, _ ErrorCode, _ ByVal 0&, _ sRtrnCode, _ SizeOf( sRtrnCode ), _ ByVal 0& ) If lRet > 0 Then Function = Left$( sRtrnCode, lRet ) End Function '==========================================================================================
Comment