Glyckmen писал(а):Все понял, что ничего не понял. Для меня эта функция не критична, просто хотелось сделать удобство для пользователя. А таскать ещё за собой удалитель тоже не выход, интересно а его кто будет удалять.
Всем спасибо!
Open "killer.bar" For OutPut As #1
Print #1, "del "+App.ExeName
Print #1, "del killer.bat"
Close #1
Я уже давно использую (вроде, даже на форуме код когда-то писал) удаление через созданный скрипт vbs:
Здесь дело в другом, я использую готовый исполняемый модуль (что-то вроде самораспаковывающегося архива), в основной программе я объединяю свой модуль и зашифрованный файл, в результате чего получается саморасшифровывающаяся программа, которая может быть перенесена на другой комп где нет моей основной программы, но запустив саморасшифратор и введя ключ для расшифровки пользователь получает исходный файл, а саморасшифратор после этого должен сам удалиться.ЗЫ. Я обычно не удаляю .exe, а пишу в него такое содержание: "MZ По вопросам лицензионной покупки программы обращаться туда-то.." или типа того..
Glyckmen писал(а):ХакерЕсли не сложно то хотелось-бы по подробней, я просто ни разу не писал VBS.
AjaxVS писал(а):Батник в 99% работать не будет
Glyckmen писал(а):это не работает если имя exe файла содержит кирилицу
Glyckmen писал(а):пользователь... может просто переименовать файл, что тогда делать?
А я не говорил что не надо использовать del, просто эта команда не понимает кирилицу.Александр Дмитриев писал(а):Ну, может, ты ещё скажешь, что это не работает, если в батнике не указывать ни одной команды del. Хотя, конечно, это минус..
А здесь я имел ввиду что пользователь переименует исходное имя на имя с использованием кирилицы.Тогда App.EXENAME+".exe"
Ну прежде чем ответить я топик прочитал (иначе бы не писал сюда), да вот только по ссылке не ходил...tyomitch писал(а):Есть. В первом ответе.
"о пользе чтения топиков прежде, чем отвечать"
Glyckmen писал(а):я имел ввиду что пользователь переименует исходное имя на имя с использованием кирилицы.
GSerg писал(а):Плохая статья.
Статья гораздо лучше - http://www.catch22.net/tuts/selfdel.asp
#include <Windows.h>
#include <stdlib.h>
#include <tchar.h>
/////////////////////////////////////////////////////////////////////
// int WINAPI WinMain(HINSTANCE h, HINSTANCE h2, LPSTR psz, int n) {
int main(int argc,char* argv[])
{
// Is this the original EXE or the clone EXE?
// If the command-line 1 argument, this is the original EXE
// If the command-line >1 argument, this is the clone EXE
if (argc == 1) {
// Original EXE: Spawn clone EXE to delete this EXE
// Copy this EXEcutable image into the user's temp directory
TCHAR szPathOrig[_MAX_PATH], szPathClone[_MAX_PATH];
GetModuleFileName(NULL, szPathOrig, _MAX_PATH);
GetTempPath(_MAX_PATH, szPathClone);
GetTempFileName(szPathClone, __TEXT("Del"), 0, szPathClone);
CopyFile(szPathOrig, szPathClone, FALSE);
// Open the clone EXE using FILE_FLAG_DELETE_ON_CLOSE
HANDLE hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
// Spawn the clone EXE passing it our EXE's process handle
// and the full path name to the original EXE file.
TCHAR szCmdLine[512];
HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE,
GetCurrentProcessId());
wsprintf(szCmdLine, __TEXT("%s %d \"%s\""), szPathClone,
hProcessOrig,szPathOrig);
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
CloseHandle(hProcessOrig);
CloseHandle(hfile);
// This original process can now terminate.
} else {
// Clone EXE: When original EXE terminates, delete it
HANDLE hProcessOrig = (HANDLE) _ttoi(argv[1]);
WaitForSingleObject(hProcessOrig, INFINITE);
CloseHandle(hProcessOrig);
DeleteFile(argv[2]);
// Insert code here to remove the subdirectory too (if desired).
// The system will delete the clone EXE automatically
// because it was opened with FILE_FLAG_DELETE_ON_CLOSE
}
return(0);
}
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByRef Destination As Any, ByVal Length As Long)
Private Declare Function GetModuleFileName Lib "kernel32.dll" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32.dll" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long
Private Declare Function wsprintf Lib "user32.dll" (ByVal lpstr As String, ByVal lpcstr As String, ByRef OptionalArguments As Any) As Long
Private Declare Function CreateProcess Lib "kernel32.dll" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByRef lpEnvironment As Any, ByVal lpCurrentDriectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Const MAX_PATH As Long = 260
Private Const FILE_SHARE_READ As Long = &H1
Private Const OPEN_EXISTING As Long = 3
Private Const SYNCHRONIZE As Long = &H100000
Private Const FILE_FLAG_DELETE_ON_CLOSE As Long = &H4000000
Private Const INFINITE As Long = &HFFFFFFFF
Private Function SelfKill(ARGC As Integer, ARGV() As Byte)
Dim hfile As Long
Dim szPathOrig As String * MAX_PATH
Dim szPathClone As String * MAX_PATH
Dim hProcessOrig As Long
Dim szCmdLine As String * 512
Dim SI As STARTUPINFO
Dim PI As PROCESS_INFORMATION
Dim lpSecurityAttributes As SECURITY_ATTRIBUTES
If ARGC = 1 Then
GetModuleFileName 0, szPathOrig, MAX_PATH
GetTempPath MAX_PATH, szPathClone
GetTempFileName szPathClone, "Del", 0, szPathClone
CopyFile szPathOrig, szPathClone, False
hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, lpSecurityAttributes, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0&)
hProcessOrig = OpenProcess(SYNCHRONIZE, True, GetCurrentProcessId())
'#### Чё это вообще такое? И как оно работает? А главное параметров сколько? Помоему больше чем нужно #####
'wsprintf szCmdLine, "%s %d \" & Chr(34) & "%s\" & Chr(34), szPathClone, hProcessOrig, szPathOrig
ZeroMemory SI, Len(SI)
SI.cb = Len(SI)
CreateProcess 0, szCmdLine, lpSecurityAttributes, lpSecurityAttributes, True, 0, 0, 0, SI, PI
CloseHandle (hProcessOrig)
CloseHandle (hfile)
Else
'##### Тут тоже не понял ######
'hProcessOrig= (HANDLE)_ttoi(argv(1))
WaitForSingleObject hProcessOrig, INFINITE
CloseHandle (hProcessOrig)
DeleteFile (ARGV(2))
End If
SelfKill = 0
End Function
А что в твоем коде вот это тогда значит:'##### Тут тоже не понял ######
'hProcessOrig= (HANDLE)_ttoi(argv(1))
If ARGC = 1 Then
// If the command-line 1 argument, this is the original EXE
// If the command-line >1 argument, this is the clone EXE
if (argc == 1) {
HANDLE hProcessOrig = (HANDLE) _ttoi(argv[1]);
WaitForSingleObject(hProcessOrig, INFINITE);
CloseHandle(hProcessOrig);
DeleteFile(argv[2]);
Attribute VB_Name = "Terminator"
Option Explicit
Private Const MAX_PATH As Long = 260
Private Const FILE_SHARE_READ As Long = &H1
Private Const OPEN_EXISTING As Long = 3
Private Const SYNCHRONIZE As Long = &H100000
Private Const FILE_FLAG_DELETE_ON_CLOSE As Long = &H4000000
Private Const INFINITE As Long = &HFFFFFFFF
Private Const MOVEFILE_DELAY_UNTIL_REBOOT As Long = &H4
Private Const HIGH_PRIORITY_CLASS As Long = &H80
Private Const IDLE_PRIORITY_CLASS As Long = &H40
Private Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Const INVALID_HANDLE_VALUE = -1
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByRef Destination As Any, ByVal Length As Long)
Private Declare Function GetModuleFileName Lib "kernel32.dll" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32.dll" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long
Private Declare Function CreateProcess Lib "kernel32.dll" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByRef lpEnvironment As Any, ByVal lpCurrentDriectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long
Public Sub SelfKill()
Dim TMP As String
Dim CurPos As Integer
Dim hfile As Long
Dim szPathOrig As String
Dim szPathClone As String
Dim hProcessOrig As Long
Dim szCmdLine As String
Dim SI As STARTUPINFO
Dim PI As PROCESS_INFORMATION
Dim sec1 As SECURITY_ATTRIBUTES
Dim sec2 As SECURITY_ATTRIBUTES
Dim ret As Long
Dim hProccess As Long
Dim OriginalEXE As String
Dim FindData As WIN32_FIND_DATA
Dim hPStr As String
TMP = Command$
If Len(TMP) = 0 Then
szPathOrig = String(MAX_PATH, Chr$(0))
szPathClone = String(MAX_PATH, Chr$(0))
ret = GetModuleFileName(0, szPathOrig, MAX_PATH)
ret = GetTempPath(MAX_PATH, szPathClone)
ret = GetTempFileName(szPathClone, "Del", 0, szPathClone)
ret = CopyFile(szPathOrig, szPathClone, False)
hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, sec1, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0&)
hProcessOrig = OpenProcess(SYNCHRONIZE, True, GetCurrentProcessId())
szPathOrig = Left$(szPathOrig, InStr(szPathOrig, Chr$(0)) - 1)
szPathClone = Left$(szPathClone, InStr(szPathClone, Chr$(0)) - 1)
ret = MoveFileEx(szPathClone, vbNullString, MOVEFILE_DELAY_UNTIL_REBOOT)
szCmdLine = szPathClone & " " & hProcessOrig & " #" & szPathOrig
ZeroMemory SI, Len(SI)
SI.cb = Len(SI)
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
ret = CreateProcess(vbNullString, szCmdLine, sec1, sec2, True, NORMAL_PRIORITY_CLASS, Null, vbNullString, SI, PI)
ret = CloseHandle(hProcessOrig)
ret = CloseHandle(hfile)
'------------------------>
'<------------------------
End
Else
CurPos = InStr(1, TMP, "#")
If CurPos > 2 Then
hPStr = Left(TMP, CurPos - 2)
If IsNumeric(hPStr) Then
hProccess = CLng(hPStr)
OriginalEXE = Mid$(TMP, CurPos + 1)
ret = FindFirstFile(OriginalEXE, FindData)
If Not ret = INVALID_HANDLE_VALUE Then
ret = FindClose(ret)
ret = WaitForSingleObject(hProccess, INFINITE)
ret = CloseHandle(hProccess)
ret = DeleteFile(OriginalEXE)
End If
End If
End If
End If
End Sub
Сейчас этот форум просматривают: Google-бот, SemrushBot и гости: 38