home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 8,885 of 10,840   
   Auric__ to All   
   Re: computer shutdown   
   14 Oct 04 04:26:54   
   
   From: not.my.real@email.address   
      
   On Thu, 14 Oct 2004 11:24:19 +0200, "Maarten"    
   wrote:   
      
   >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?   
      
   Sorry, FormatMessage is another API call; in the project I pulled that   
   file from I declared it public (I use it more than once) in another   
   module. I use it specifically to get the error message so I can log it   
   (if ExitWindowsEx returns a non-zero value, there was an error). You can   
   safely remove that entire if-then-else structure, or you can add a call   
   to your logging routine immediately after the call to FormatMessage.   
   Here's what you need to add to use it:   
      
   Public Declare Function FormatMessage Lib "kernel32" Alias _   
           "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, _   
           ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal _   
           lpBuffer As String, ByVal nSize As Long, Arguments As Long) _   
           As Long   
      
   Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000   
      
   >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?   
      
   That's the whole point of quitWindows - it starts off by finding out   
   whether or not you're using an NT-based system (using the IsWinNT   
   function), and if so it kicks up its permissions so it can do the   
   shutdown. If it's a 9x system, well, the whole concept of thread   
   security is non-existent there, so *any* process can shutdown Windows   
   just by making the appropriate API calls.   
      
   Another thing that I see I forgot is that the value you pass to   
   quitWindows (which as long) needs to be one of the EWX_* values:   
   EWX_LOGOFF   
   EWX_SHUTDOWN   
   EWX_REBOOT   
   EWX_POWEROFF   
      
   You can OR them with EWX_FORCE or EWX_FORCEIFHUNG to force closing apps   
   that don't respond:   
   quitWindows EWX_REBOOT Or EWX_FORCEIFHUNG   
      
   There might also be an EWX_STANDBY, but since I don't use it (and don't   
   have the API viewer installed) I can't check.   
   --   
   auric underscore underscore at hotmail dot com   
   *****   
   IRC: real-time Usenet.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca