{"id":1257,"date":"2024-07-31T08:00:00","date_gmt":"2024-07-31T00:00:00","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=1257"},"modified":"2024-07-15T10:55:30","modified_gmt":"2024-07-15T02:55:30","slug":"%e8%bf%9b%e7%a8%8b%e4%b8%ad%e8%87%aa%e6%88%91%e9%94%80%e6%af%81","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=1257","title":{"rendered":"\u8fdb\u7a0b\u4e2d\u81ea\u6211\u9500\u6bc1"},"content":{"rendered":"\n<p>Option Explicit<\/p>\n\n\n\n<p>Const NORMAL_PRIORITY_CLASS = &amp;H20<br>Const REALTIME_PRIORITY_CLASS = &amp;H100<br>Const THREAD_PRIORITY_NORMAL = 0<br>Const THREAD_PRIORITY_IDLE = -15<br>Const IDLE_PRIORITY_CLASS = &amp;H40<br>Const DETACHED_PROCESS = &amp;H8<br>Const CREATE_SUSPENDED = &amp;H4<br>Const THREAD_PRIORITY_TIME_CRITICAL = 15<br>Const SW_HIDE = 0<br>Const STARTF_USESHOWWINDOW = &amp;H1<\/p>\n\n\n\n<p>Type STARTUPINFO<br>cb As Long<br>lpReserved As String<br>lpDesktop As String<br>lpTitle As String<br>dwX As Long<br>dwY As Long<br>dwXSize As Long<br>dwYSize As Long<br>dwXCountChars As Long<br>dwYCountChars As Long<br>dwFillAttribute As Long<br>dwFlags As Long<br>wShowWindow As Integer<br>cbReserved2 As Integer<br>lpReserved2 As Long<br>hStdInput As Long<br>hStdOutput As Long<br>hStdError As Long<br>End Type<\/p>\n\n\n\n<p>Type PROCESS_INFORMATION<br>hProcess As Long<br>hThread As Long<br>dwProcessId As Long<br>dwThreadId As Long<br>End Type<\/p>\n\n\n\n<p>Type SECURITY_ATTRIBUTES<br>nLength As Long<br>lpSecurityDescriptor As Long<br>bInheritHandle As Long<br>End Type<\/p>\n\n\n\n<p>Declare Function GetModuleFileName Lib &#8220;kernel32&#8221; Alias &#8220;GetModuleFileNameA&#8221; (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long<br>Declare Function GetEnvironmentVariable Lib &#8220;kernel32&#8221; Alias &#8220;GetEnvironmentVariableA&#8221; (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long<br>Declare Function GetShortPathName Lib &#8220;kernel32&#8221; Alias &#8220;GetShortPathNameA&#8221; (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long<br>Declare Function GetCurrentProcess Lib &#8220;kernel32&#8221; () As Long<br>Declare Function GetCurrentThreadId Lib &#8220;kernel32&#8221; () As Long<br>Declare Function SetPriorityClass Lib &#8220;kernel32&#8221; (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long<br>Declare Function SetThreadPriority Lib &#8220;kernel32&#8221; (ByVal hThread As Long, ByVal nPriority As Long) As Long<br>Declare Function ResumeThread Lib &#8220;kernel32&#8221; (ByVal hThread As Long) As Long<br>Declare Function GetCurrentThread Lib &#8220;kernel32&#8221; () As Long<br>Declare Function CreateProcess Lib &#8220;kernel32&#8221; Alias &#8220;CreateProcessA&#8221; (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long<br>Public Function DeleteMe() As Boolean<br>Dim szModule As String<br>Dim szComspec As String<br>Dim szParams As String<\/p>\n\n\n\n<p>Dim si As STARTUPINFO<br>Dim pi As PROCESS_INFORMATION<br>Dim sa1 As SECURITY_ATTRIBUTES<br>Dim sa2 As SECURITY_ATTRIBUTES<\/p>\n\n\n\n<p>szModule = String(512, 0)<br>szComspec = String(512, 0)<br>szParams = String(512, 0)<\/p>\n\n\n\n<p>&#8216;\/\/ get file path names:<br>If ((GetModuleFileName(0, szModule, 512) &lt;&gt; 0) And (GetShortPathName(szModule, szModule, 512) &lt;&gt; 0) And (GetEnvironmentVariable(&#8220;COMSPEC&#8221;, szComspec, 512) &lt;&gt; 0)) Then<br>&#8216;\/\/ set command shell parameters<br>szComspec = Left(szComspec, InStr(szComspec, Chr(0)) &#8211; 1)<br>szModule = Left(szModule, InStr(szModule, Chr(0)) &#8211; 1)<\/p>\n\n\n\n<p>szComspec = szComspec &amp; &#8221; \/c del &#8221; &amp; szModule<br>&#8216;\u4e0b\u884c\u652f\u6301\u5e26\u7a7a\u683c\u8def\u5f84<br>&#8216;szComspec = szComspec &amp; &#8221; \/c del &#8221; &amp; &#8220;&#8221;&#8221;&#8221; &amp; szModule &amp; &#8220;&#8221;&#8221;&#8221;<\/p>\n\n\n\n<p>&#8216;\/\/ set struct members<br>With si<br>.cb = Len(si)<br>.dwFlags = STARTF_USESHOWWINDOW<br>.wShowWindow = SW_HIDE<br>End With<br>&#8216;\/\/ increase resource allocation to program<br>Call SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)<br>Call SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL)<\/p>\n\n\n\n<p>&#8216;\/\/ invoke command shell<br>&#8216;Debug.Print CreateProcess(vbNullString, szComspec, sa1, sa2, 0&amp;, CREATE_SUSPENDED Or DETACHED_PROCESS, 0&amp;, vbNullString, si, pi)<br>If CreateProcess(vbNullString, szComspec, sa1, sa2, 0, CREATE_SUSPENDED Or DETACHED_PROCESS, 0, vbNullString, si, pi) Then<br>&#8216;\/\/ suppress command shell process until program exits<br>Call SetPriorityClass(pi.hProcess, IDLE_PRIORITY_CLASS)<br>Call SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE)<\/p>\n\n\n\n<p>&#8216;\/\/ resume shell process with new low priority<br>Call ResumeThread(pi.hThread)<\/p>\n\n\n\n<p>&#8216;\/\/ everything seemed to work<br>DeleteMe = True<br>Exit Function<br>Else &#8216;\/\/ if error, normalize allocation<br>Call SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS)<br>Call SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL)<br>End If<br>End If<br>DeleteMe = False<br>End Function<\/p>\n\n\n\n<p>Public Sub KillMe()<br>Dim sPath As String<br>sPath = IIf(Right(App.Path, 1) = &#8220;\\&#8221;, App.Path, App.Path &amp; &#8220;\\&#8221;)<br>On Error GoTo InIDE<br>Debug.Print 1 \/ 0 &#8216;\u89e6\u53d1IDE\u9519\u8bef,\u9632\u6b62\u5220\u9664 VB6.exe<br>Dim iFile As Integer<br>iFile = FreeFile<br>Open sPath &amp; &#8220;KillMe.bat&#8221; For Output As #iFile<br>Print #iFile, &#8220;:Repeat&#8221; &amp; vbCrLf &amp; _<br>&#8220;del &#8220;&#8221;&#8221; &amp; sPath &amp; App.EXEName &amp; &#8220;.exe&#8221;&#8221;&#8221; &amp; vbCrLf &amp; _<br>&#8220;if exist &#8220;&#8221;&#8221; &amp; sPath &amp; App.EXEName &amp; &#8220;.exe&#8221;&#8221;&#8221; &amp; &#8221; goto Repeat&#8221; &amp; vbCrLf &amp; _<br>&#8220;del %0&#8221;<br>Close #iFile<br>Shell sPath &amp; &#8220;KillMe.bat&#8221;, vbHide<br>InIDE:<br>End Sub<\/p>\n\n\n\n<p>Public Sub DelMe()<br>Dim iFileNumber As Integer<br>On Error Resume Next<br>If App.LogMode Then<br>iFileNumber = FreeFile()<br>Open &#8220;del.tmp.vbs&#8221; For Output As iFileNumber<br>SetAttr &#8220;del.tmp.vbs&#8221;, vbHidden<br>Print #iFileNumber, &#8220;Dim FSO,WMI&#8221;<br>Print #iFileNumber, &#8220;Set WMI=GetObject(&#8221; &amp; Chr(34) &amp; &#8220;winmgmts:\/\/.&#8221; &amp; Chr(34) &amp; &#8220;)&#8221;<br>Print #iFileNumber, &#8220;Set FSO=CreateObject(&#8221; &amp; Chr(34) &amp; &#8220;Scripting.FileSystemObject&#8221; &amp; Chr(34) &amp; &#8220;)&#8221;<br>Print #iFileNumber, &#8220;Do While WMI.ExecQuery(&#8221; &amp; Chr(34) &amp; _<br>&#8220;SELECT * FROM WIN32_PROCESS WHERE NAME='&#8221; &amp; App.EXEName &amp; &#8220;.EXE'&#8221; &amp; Chr(34) &amp; &#8220;).Count&#8221;<br>Print #iFileNumber, &#8220;WScript.Sleep 1&#8221;<br>Print #iFileNumber, &#8220;Loop&#8221;<br>Print #iFileNumber, &#8220;FSO.DeleteFile &#8221; &amp; Chr(34) &amp; App.Path &amp; &#8220;\/&#8221; &amp; App.EXEName &amp; &#8220;.EXE&#8221; &amp; Chr(34)<br>Print #iFileNumber, &#8220;FSO.DeleteFile &#8221; &amp; Chr(34) &amp; App.Path &amp; &#8220;\/del.tmp.vbs&#8221; &amp; Chr(34)<br>Print #iFileNumber, &#8220;Set FSO=Nothing&#8221;<br>Print #iFileNumber, &#8220;Set WMI=Nothing&#8221;<br>Close #iFileNumber<br>Shell &#8220;WScript.Exe del.tmp.vbs&#8221;, vbHide<br>End If<br>End Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Option Explicit Const NORMAL_PRIORITY_CLASS = &amp;H20C &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=1257\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u8fdb\u7a0b\u4e2d\u81ea\u6211\u9500\u6bc1\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-1257","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1257"}],"version-history":[{"count":1,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1257\/revisions"}],"predecessor-version":[{"id":1258,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1257\/revisions\/1258"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}