The ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown or logoff then proceeds asynchronously. The function is designed to stop all processes in the callers logon session. Therefore, if you are not the interactive user, the function can succeed without actually shutting down the computer. If you are not the interactive user, use the InitiateSystemShutdown or InitiateSystemShutdownEx function.
Sub WMIReboot()
Dim strComputer As String = "."
Dim options As New ConnectionOptions
options.Impersonation = ImpersonationLevel.Impersonate
options.EnablePrivileges = True
Dim ms As New ManagementScope("\\" & strComputer & "\root\CIMV2", options)
Dim q As New SelectQuery("SELECT * FROM Win32_OperatingSystem")
Dim search As New ManagementObjectSearcher(ms, q)
enum each entry for Win32_OperatingSystem and call WMI reboot method
Dim info As ManagementObject
For Each info In search.Get()
info.InvokeMethod("Reboot", Nothing)
Next
End Sub