Search Tools Links Login

If a users attempts to shutdown/restart their computer while your application is still running


If a users attempts to shutdown/restart their computer while your application is still running, this simple piece of code will actually allow you to abort the request to shutdown. Can be very useful. Please mail me at mailme@shouvik.tk if you are facing any problems or www.shouvik.tk

Original Author: www.shouvik.tk

API Declarations

Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function AbortSystemShutdown Lib "advapi32.dll" Alias "AbortSystemShutdownA" (ByVal lpMachineName As String) As Long
Function GetName()
Dim lpBuff As String * 25
Dim ret As Long, ComputerName As String

ret = GetComputerName(lpBuff, 25)
ComputerName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

GetName = ComputerName
End Function

Code

Private Sub Command1_Click()
  AbortSystemShutdown (GetName)
End Sub

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 96 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.