Jump to content

How can I make the file delete if the script ends?


Recommended Posts

I want it to:

if the script has ended, delete the files IpChangeOn.bat & IpChangeOff.bat Cant seem to find a way to do it

( Other than using the "FileDelete" function in the _Exit, function, but thats not what I want.

HotKeySet("^!{END}", "_IpConfig")
HotKeySet("^!{PGUP}", "_IpChangeOn")
HotKeySet("^!{PGDN}", "_IpChangeOff")
HotKeySet("^!{HOME}", "_Exit")
MsgBox(0, "", "Write down on a piece of paper your: SubnetMask & DefaultGateway. ( Located using the IpConfig Hotkey )")
MsgBox(0, "", "Ctrl + Alt + End = IpConfig")
MsgBox(0, "", "Ctrl + Alt + Page Up = New IP")
MsgBox(0, "", "Ctrl + Alt + Page Down = Old IP")
MsgBox(0, "", "Ctrl + Alt + Home = Exit")

While 1
    Sleep(25)
WEnd

Func _IpConfig()
    Opt("WinTitleMatchMode", 2)
        Run(@Comspec)
        WinWaitActive("cmd.exe")
        Send("ipconfig")
        Send("{ENTER}")
EndFunc

Func _IpChangeOn()
$IP_ADDY = InputBox("", "NewIP:", "", "", -1, 10)
$SUBNET_MASK = InputBox("", "SubnetMask:", "", "", -1, 10)
$DEFAULT_GATEWAY = InputBox("", "DefaultGateway", "", "", -1, 10)

$IpChangeOn = FileOpen("IpChangeOn.bat", 1)
If $IpChangeOn = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($IpChangeOn, "@Echo Setting IP address to " & $IP_ADDY)
FileWriteLine($IpChangeOn, "@Echo Off")
FileWriteLine($IpChangeOn, "")
FileWriteLine($IpChangeOn, "netsh interface ip set address name=""Local Area Connection"" static " & $IP_ADDY & " " & $SUBNET_MASK & " " & $DEFAULT_GATEWAY & " " & "1")
FileClose($IpChangeOn)

Run("IpChangeOn.bat")
EndFunc

Func _IpChangeOff()
    Opt("WinTitleMatchMode", 2)
$IpChangeOff = FileOpen("IpChangeOff.bat", 1)
If $IpChangeOff = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($IpChangeOff, "@Echo Setting IP address to DHCP assigned.")
FileWriteLine($IpChangeOff, "@Echo Off")
FileWriteLine($IpChangeOff, "netsh interface ip set address ""Local Area Connection"" dhcp")
FileWriteLine($IpChangeOff, "@Echo Setting DNS to DHCP assigned.")
FileWriteLine($IpChangeOff, "@Echo Off")
FileWriteLine($IpChangeOff, "netsh interface ip set dns ""Local Area Connection"" dhcp")
FileClose($IpChangeOff)

Run("IpChangeOff.bat")
EndFunc

Func _Exit()
    Exit
EndFunc
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

I want it to:

if the script has ended, delete the files IpChangeOn.bat & IpChangeOff.bat Cant seem to find a way to do it

( Other than using the "FileDelete" function in the _Exit, function, but thats not what I want.

Add a function at the bottom of your script onAutoITExit with your file deletes and whatever else you want to do, when the script exits it will perform those tasks

Func OnAutoItExit()

FileDelete("myfile.bat")
FileDelete("MyFile.exe")

EndFunc
Link to comment
Share on other sites

HI,

Func _SelfDelete()
    Local $cmdfile
    FileDelete(@TempDir & "\scratch.cmd")
    $cmdfile = ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '"' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & '\scratch.cmd'
    FileWrite(@TempDir & "\scratch.cmd", $cmdfile)
    Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE)
EndFunc  ;==>_SelfDelete

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...