Code:
Private sub AfsluitenHerstartHeropen()
Dim advapi32DLLbestaat As Boolean = IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\advapi32.dll")
Dim user32DLLbestaat As Boolean = IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\user32.dll")
'[...]
'ExitWindowsEx aanroepen
If user32DLLbestaat Then
Dim vlag As ExitWindows = ExitWindows.RestartApps
If Geforceerd Then vlag = vlag Or ExitWindows.Force
If advapi32DLLbestaat And Environment.OSVersion.Platform = PlatformID.Win32NT Then AdjustToken()
If Not ExitWindowsEx(vlag, ShutdownReason.MajorOther) = 0 Then
Application.Exit()
Exit Sub
End If
End If
'[...]
'Enumeraties declareren
Private Enum ExitWindows As UInteger
'[...]
RestartApps = &H40 '(is gelijk aan 0x00000040)
Force = &H4
End Enum
Private Enum ShutdownReason As UInteger
'[...]
MajorOther = &H0
'[...]
End Enum
<Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function ExitWindowsEx(ByVal uFlags As ExitWindows, ByVal dwReason As ShutdownReason) As Integer
End Function
'En AdjustToken is werkt prima en heb ik dus niet vermeld. Deze code vraagt de juiste privileges op...
Als ik deze code uitvoer dan logt de computer uit. Echter zou hij opnieuw op moeten starten en geopende programma's heropenen.
Er is geen foutmelding en ExitWindowsEx retourneerd altijd een getal > 0.
Weet er iemand wat ik fout doe? Bij alle andere aanroepen naar ExitWindowsEx (zoals afsluiten) doet hij precies wat hij moet doen.