Suicide Snippet

Okay this is a little function that i ported to vb6 today from a Delphi snippet i had, read the description to understand it’s purpose have another put that is private won’t show it :P.

Option Explicit
‘—————————————————————————————
‘ Function    : Suicide
‘ DateTime    : 26.07.2009  12:23AM
‘ Author      : Kreshnik Hasanaj
‘ Mail        : kresha7@hotmail.com
‘ Purpose     : A Simple Melt function that i ported from delphi,call it on the form unload event.
‘ Usage       : At your own risk
‘ Requirements: None
‘ Distribution: You can freely use this code in your own
‘               applications, but you may not reproduce
‘               or publish this code on any web site,
‘               online service, or distribute as source
‘               on any media without express permission.
‘—————————————————————————————
Const SW_HIDE = 0
Private Declare Function GetModuleFileName Lib “kernel32” Alias “GetModuleFileNameA” (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetShortPathName Lib “kernel32” Alias “GetShortPathNameA” (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Private Declare Function lstrcpy Lib “kernel32” Alias “lstrcpyA” (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function lstrcat Lib “kernel32” Alias “lstrcatA” (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetEnvironmentVariable Lib “kernel32” Alias “GetEnvironmentVariableA” (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function Suicide() As Boolean
Dim FilePath As String * 255
Dim CMD      As String * 255
Dim Lng      As Long
Suicide = False
If GetModuleFileName(0, FilePath, 256) <> 0 Then
Lng = lstrlen(FilePath)
GetShortPathName FilePath, FilePath, Lng
lstrcpy CMD, “/c del “
lstrcat CMD, FilePath
lstrcat CMD, ” >> NUL”
If (GetEnvironmentVariable(“ComSpec”, FilePath, 256) <> 0) And (ShellExecute(Me.hwnd, vbNullString, FilePath, CMD, 0, SW_HIDE) > 32) Then
Suicide = True
End If
End If
End Function
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s