<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Самоудаление скрипта]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12416&amp;type=atom" />
	<updated>2017-02-08T13:09:48Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=12416</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Самоудаление скрипта]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111991#p111991" />
			<content type="html"><![CDATA[<p>Так с выбором, что удалять:</p><div class="codebox"><pre><code>var := &quot;file&quot;   ; если &quot;file&quot; — будет удалён только файл, если &quot;folder&quot; — папка файла со всеми файлами
Clean := new Uninstall(var)

if (var != &quot;file&quot;)  {
   MsgBox, 52, Деинсталляция, Этот код удалит папку`n`n%A_ScriptDir%`n`n`со всеми файлами!`nПродолжить?
   IfMsgBox, No
      ExitApp,, Clean.cancel := 1
}
/*
Здесь код деинсталляции
*/
ExitApp

class Uninstall
{
   __New(var := &quot;file&quot;)  {
      if !A_IsCompiled  {
         MsgBox, Скомпилируйте скрипт!
         ExitApp
      }
      
      for k, param in [&quot;ParentPID&quot;, &quot;ParentPath&quot;]
         %param% := %k%
      if ParentPath  {
         SetWorkingDir, % A_Temp
         Process, WaitClose, % ParentPID
         if (var = &quot;file&quot;)
            ComObjCreate(&quot;Scripting.FileSystemObject&quot;).DeleteFile(ParentPath, 1)
         else  {
            SplitPath, ParentPath,, Folder
            ComObjCreate(&quot;Scripting.FileSystemObject&quot;).DeleteFolder(Folder, 1)
         }
         ExitApp,, this.CreateProcess(&quot;rundll32&quot;, DEBUG_ONLY_THIS_PROCESS := 2)
      }
   }
   
   __Delete()  {
      if this.cancel
         ExitApp
      
      TmpFilePath := A_Temp &quot;\ahk_uninstall_&quot; A_TickCount &quot;.exe&quot;
      FileCopy, % A_ScriptFullPath, % TmpFilePath, 1

      hFile := this.OpenTmpFile(TmpFilePath)
      ChildPID := this.CreateProcess(TmpFilePath &quot; &quot; DllCall(&quot;GetCurrentProcessId&quot;) &quot; &quot;&quot;&quot; A_ScriptFullPath &quot;&quot;&quot;&quot;, 0)
      Process, Wait, % ChildPID
      DllCall(&quot;CloseHandle&quot;, Ptr, hFile)
   }
   
   OpenTmpFile(FilePath)  {
      static GENERIC_READ := 0x80000000, FILE_SHARE_READ := 1, FILE_SHARE_DELETE := 4
           , OPEN_EXISTING := 3, FILE_FLAG_DELETE_ON_CLOSE := 0x4000000
           , FILE_ATTRIBUTE_TEMPORARY := 0x100
      
      VarSetCapacity(SECURITY_ATTRIBUTES, size := 2*A_PtrSize + 4, 0)
      NumPut(size, SECURITY_ATTRIBUTES), NumPut(bInheritHandle := 1, &amp;SECURITY_ATTRIBUTES + 2*A_PtrSize)
      Return DllCall(&quot;CreateFile&quot;, Str, FilePath
                                 , Int, GENERIC_READ
                                 , Int, FILE_SHARE_READ|FILE_SHARE_DELETE
                                 , Ptr, &amp;SECURITY_ATTRIBUTES
                                 , Int, OPEN_EXISTING
                                 , Int, FILE_FLAG_DELETE_ON_CLOSE|FILE_ATTRIBUTE_TEMPORARY
                                 , Ptr, 0)
   }
   
   CreateProcess(CommandLine, flag)  {
      VarSetCapacity(STARTUPINFO, size := 4*A_PtrSize + 8*4 + 5*A_PtrSize, 0)
      NumPut(size, STARTUPINFO)
      VarSetCapacity(PROCESS_INFORMATION, 2*A_PtrSize + 8, 0)
      
      DllCall(&quot;CreateProcess&quot;, Ptr, 0, Str, CommandLine
                             , Ptr, 0, Ptr, 0
                             , Int, bInheritHandles := 1, UInt, flag, Ptr, 0, Ptr, 0
                             , Ptr, &amp;STARTUPINFO, Ptr, &amp;PROCESS_INFORMATION)
                             
      DllCall(&quot;CloseHandle&quot;, Ptr, hThread := NumGet(PROCESS_INFORMATION))
      DllCall(&quot;CloseHandle&quot;, Ptr, hProcess := NumGet(&amp;PROCESS_INFORMATION + A_PtrSize))
      Return PID := NumGet(&amp;PROCESS_INFORMATION + 2*A_PtrSize, &quot;UInt&quot;)
   }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-02-08T13:09:48Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111991#p111991</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Самоудаление скрипта]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111986#p111986" />
			<content type="html"><![CDATA[<p>У меня есть вообще страшный код, через скачивание заранее подготовленного деинсталятора и копии AutoHotKey.exe (если вдруг AHK на компьютере жертвы не установлен). В итоге exe закрывается, его удаляет .ahk файл, что был скачан и этот .ahk самоудаляется. В итоге на компе жертвы остается только&nbsp; AutoHotKey.exe который я поместил в папку Temp и он скоро сам удалится.</p>]]></content>
			<author>
				<name><![CDATA[belyankin12]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34408</uri>
			</author>
			<updated>2017-02-08T10:20:47Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111986#p111986</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Самоудаление скрипта]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=111984#p111984" />
			<content type="html"><![CDATA[<p>На просторах сего форума нашел скрипт на самоудаление скомпилированного AHK скрипта (<a href="http://forum.script-coding.com/viewtopic.php?pid=95716#p95716">http://forum.script-coding.com/viewtopi … 716#p95716</a>), но есть одна загвоздка. Вместе со скриптом удаляется и папка, в которой он находится. Как можно изменить скрипт, чтобы тот удалял только сам себя?</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-02-08T08:17:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=111984#p111984</id>
		</entry>
</feed>
