From: gurkjaan@hotmail.com   
      
   thanks for the reply   
      
   Public Sub quitWindows(which As Long)   
    Dim n As Long   
      
    If IsWinNT Then EnableShutDown   
    n = ExitWindowsEx(which, &HFFFF) '((which Or EWX_FORCE), &HFFFF)   
    If n Then   
    Dim x As String * 256   
    FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, 0, Err.LastDllError, _   
    0, x, 256, 0   
    Else   
    Unload frmBackground   
    End If   
   End Sub   
      
   in this part i get ann error   
      
   FormatMessage sub or function not derfined?   
      
   I'm using a computer with xp to program, but i test and run my software on   
   a computer with win 98. wil it work for both?   
      
   thanks Maarten   
      
   "Auric__" wrote in message   
   news:h5erm09c6nb5od0328uum5u5ervvejb5pn@4ax.com...   
   > On Wed, 13 Oct 2004 23:18:03 +0200, mickey    
   > wrote:   
   >   
   > >On Wed, 13 Oct 2004 09:56:50 +0200, "Maarten"    
   > >you typed some letters in random order:   
   > >   
   > >>hi   
   > >>   
   > >>does someone knows how to shut down you're compueter with vb 6.0?   
   > >>   
   > >>thanks Maarten   
   > >>   
   > >I'm not shure it works for OS > win98   
   > >   
   > >Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As   
   > >Long, ByVal dwReserved As Long) As Long   
   > >   
   > >Call ExitWindowsEx(1, 0)   
   >   
   > For NT systems it's a bit more complex - you have to give the thread   
   > permission to shut down, otherwise all you can do is logoff.   
   >   
   > Here's what I use (call quitWindows to use):   
   >   
   > ' found somewhere on the www (can't remember where)   
   > ' so don't give me credit   
   >   
   > Private Declare Function GetCurrentProcess Lib "kernel32" () As Long   
   > Private Declare Function OpenProcessToken Lib "advapi32" ( _   
   > ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _   
   > TokenHandle As Long) As Long   
   > Private Declare Function LookupPrivilegeValue Lib "advapi32" _   
   > Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, _   
   > ByVal lpName As String, lpLuid As LUID) As Long   
   > Private Declare Function AdjustTokenPrivileges Lib "advapi32" ( _   
   > 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 ExitWindowsEx Lib "user32" (ByVal uFlags As _   
   > Long, ByVal dwReserved As Long) As Long   
   > Private Declare Function GetVersionEx Lib "kernel32" Alias _   
   > "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) _   
   > As Long   
   >   
   > Public Const EWX_LOGOFF = 0   
   > Public Const EWX_SHUTDOWN = 1   
   > Public Const EWX_REBOOT = 2   
   > Public Const EWX_FORCE = 4   
   > Public Const EWX_POWEROFF = 8   
   > Public Const EWX_FORCEIFHUNG = 16   
   >   
   > Private Const TOKEN_QUERY = 8   
   > Private Const TOKEN_ADJUST_PRIVILEGES = 32   
   >   
   > Private Const SE_PRIVILEGE_ENABLED = 2   
   >   
   > Private Const ANYSIZE_ARRAY = 1   
   > Private Const VER_PLATFORM_WIN32_NT = 2   
   >   
   > Type OSVERSIONINFO   
   > dwOSVersionInfoSize As Long   
   > dwMajorVersion As Long   
   > dwMinorVersion As Long   
   > dwBuildNumber As Long   
   > dwPlatformId As Long   
   > szCSDVersion As String * 128   
   > End Type   
   >   
   > Public Type LUID   
   > LowPart As Long   
   > HighPart As Long   
   > End Type   
   >   
   > Public Type LUID_AND_ATTRIBUTES   
   > pLuid As LUID   
   > Attributes As Long   
   > End Type   
   >   
   > Public Type TOKEN_PRIVILEGES   
   > PrivilegeCount As Long   
   > Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES   
   > End Type   
   >   
   > Public Sub quitWindows(which As Long)   
   > Dim n As Long   
   >   
   > If IsWinNT Then EnableShutDown   
   > n = ExitWindowsEx(which, &HFFFF) '((which Or EWX_FORCE), &HFFFF)   
   > If n Then   
   > Dim x As String * 256   
   > FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, 0, Err.LastDllError, _   
   > 0, x, 256, 0   
   > Else   
   > Unload frmBackground   
   > End If   
   > End Sub   
   >   
   > Public Function IsWinNT() As Boolean   
   > ' Detect if the program is running under Windows NT   
   > Dim myOS As OSVERSIONINFO   
   >   
   > myOS.dwOSVersionInfoSize = Len(myOS)   
   > GetVersionEx myOS   
   > IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)   
   > End Function   
   >   
   > Private Sub EnableShutDown()   
   > ' Set the shut down privilege for the current application   
   > Dim hProc As Long, hToken As Long, mLUID As LUID   
   > Dim mPriv As TOKEN_PRIVILEGES, mNewPriv As TOKEN_PRIVILEGES   
   >   
   > hProc = GetCurrentProcess()   
   > OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, _   
   > hToken   
   > LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID   
   > mPriv.PrivilegeCount = 1   
   > mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED   
   > mPriv.Privileges(0).pLuid = mLUID   
   >   
   > ' enable shutdown privilege for the current application   
   > AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 * _   
   > mPriv.PrivilegeCount), mNewPriv, 4 + (12 * _   
   > mNewPriv.PrivilegeCount)   
   > End Sub   
   >   
   > --   
   > auric underscore underscore at hotmail dot com   
   > *****   
   > The absence of war does not automatically mean peace.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|