How to convert this code for NT?

This code successfully reboots my '95 and '98 machines but it does nothing when I run it on an NT box.
What change do I make or what code do I use to make it reboot my NT box?
---------
Private Const EWX_REBOOT As Long = 2
Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long


Private Sub Timer1_Timer()
If Time = "5:16:30 AM" Then
lngResult = ExitWindowsEx(EWX_REBOOT, 0&)
End If
End Sub

---------
a6106aAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

halapayaCommented:
For NT you have to do little more.. try this

Place all in a module and call one off the public functions.

Private Type LUID
    LowPart As Long
    HighPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
        pLuid As LUID
        Attributes As Long
End Type

Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    Privileges(0) As LUID_AND_ATTRIBUTES
End Type

'Define these constants for Security token. define tehes also in the module.

Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2

'These are the apis we use to ge the SID
'there are 3 apis u need, define
'them in the module

Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal
ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As
Long

Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal
TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As
TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As
TOKEN_PRIVILEGES, ReturnLength As Long) As Long

Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias
"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As
String, lpLuid As LUID) As Long

Public Function EndAndReboot() As Boolean
    EndAndReboot = ExecuteShutDown(EWX_FORCE + EWX_REBOOT)
End Function

Public Function EndAndShutdown() As Boolean
    EndAndShutdown = ExecuteShutDown(EWX_FORCE + EWX_POWEROFF)
End Function

Private Function ExecuteShutDown(ShutdownFlags As Long) As Boolean
    Dim hToken As Long
    Dim TakeOwnershipValue As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim lRetVal As Long
    Dim lRetValATPL As Long

    ExecuteShutDown = False

    If OpenProcessToken(GetCurrentProcess(),          TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY,
hToken) = False Then
        Exit Function
    End If

    tkp.PrivilegeCount = 1
    tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED

    If LookupPrivilegeValue("", SE_SHUTDOWN_NAME,                       tkp.Privileges(0).pLuid) = False Then
    Exit Function
    End If

    lRetVal = AdjustTokenPrivileges(hToken, 0, tkp, 16, tkp, lRetValATPL)
    If ExitWindowsEx(ShutdownFlags, 0) = 0 Then
    Exit Function
    Else
        ExecuteShutDown = True
    End If
End Function


Its not very clear when i put all these in this box. but do a cut and paste on a module it shoudl format properly

hope this helps
0
a6106aAuthor Commented:
when I compile this, I get an error on this section:
-------
 If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) = False Then
        Exit Function
    End If
-------
...with "GetCurrrentProcess" highlighted and the error:
"sub or funtion not defined"
??
0
hesCommented:
Add in this in the declare area

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

halapayaCommented:
ooopps.. that API and another API was not defined... here is the whole thing again..


Option Explicit

Private Type LUID
    LowPart As Long
    HighPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
        pLuid As LUID
        Attributes As Long
End Type

Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    Privileges(0) As LUID_AND_ATTRIBUTES
End Type

Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const EWX_FORCE = 4
Private Const EWX_REBOOT = 2

Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Public Function EndAndReboot() As Boolean
    EndAndReboot = ExecuteShutDown(EWX_FORCE + EWX_REBOOT)
End Function

Private Function ExecuteShutDown(ShutdownFlags As Long) As Boolean
    Dim hToken As Long
    Dim TakeOwnershipValue As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim lRetVal As Long
    Dim lRetValATPL As Long

    ExecuteShutDown = False

    If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) = False Then
        Exit Function
    End If
    tkp.PrivilegeCount = 1
    tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
    If LookupPrivilegeValue("", SE_SHUTDOWN_NAME, _
                            tkp.Privileges(0).pLuid) = False Then
        Exit Function
    End If
    lRetVal = AdjustTokenPrivileges(hToken, 0, tkp, 16, tkp, lRetValATPL)

    If ExitWindowsEx(ShutdownFlags, 0) = 0 Then
        Exit Function
    Else
        ExecuteShutDown = True
    End If
End Function


what i added was the two constant values

Private Const EWX_FORCE = 4
Private Const EWX_REBOOT = 2

and defined the two apis which was missing
1)GetCurrentProcess
2)ExitWindowsEx

check now.. am working so i can't check it on my machine :o)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Erick37Commented:
"PRB: ExitWindowsEx API Does Not Reboot Windows NT"

http://support.microsoft.com/support/kb/articles/q176/6/95.asp
0
a6106aAuthor Commented:
thanks for the extra effort !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.