VB.net 刪除正在執行的自身exe檔案
阿新 • • 發佈:2018-11-03
Public Sub TestForKillMyself()
Dim bat As String = "@echo off" & vbCrLf & _
": tryagain " & vbCrLf & _
"del %1" & vbCrLf & _
"if exist %1 goto tryagain" & vbCrLf & _
" del %0"
System.IO.File.WriteAllText("killme.bat", bat) '寫bat檔案
Dim psi As New ProcessStartInfo '= new ProcessStartInfo();
psi.FileName = "killme.bat" ';
psi.Arguments = """" & Environment.GetCommandLineArgs()(0) & """"
psi.WindowStyle = ProcessWindowStyle.Hidden ';
Process.Start(psi)
End Sub