Juvigy Posted April 24, 2009 Share Posted April 24, 2009 (edited) I am using the below code: Func _SelfDelete() Local $cmdfile FileDelete(@TempDir & "\dcp.cmd") $cmdfile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & '\dcp.cmd' FileWrite(@TempDir & "\dcp.cmd", $cmdfile) ;Run(@TempDir & "\dcp.cmd", @TempDir, @SW_HIDE) Run(@TempDir & "\dcp.cmd", @TempDir) EndFunc It doesnt work on all computers. I want to be able to do a check an if it is true to close the script and delete the exe file. If VersionCheck() <> 1 Then MsgBox(0,"System error","General version error.Please download latest version") _SelfDelete() Exit EndIf Please help. Edited April 24, 2009 by Juvigy Link to comment Share on other sites More sharing options...
Juvigy Posted April 24, 2009 Author Share Posted April 24, 2009 Looks like the file is in use for some reason and the cmc loop continues like for 5 min and then deletes the file. How can i ensure it is deleted right away? For example how i can delete files in use ? Link to comment Share on other sites More sharing options...
rudi Posted April 24, 2009 Share Posted April 24, 2009 Hi. I've never had problems for the very few cases I needed self deletion. [howto delete open files] e.g. unlocker? (google) Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 8, 2009 Share Posted November 8, 2009 (edited) I have found this somewhere awhile ago. I DO NOT take credit for this but it works great at self destruction if compiled. If @Compiled Then $sCMDLine = ':CheckFile' & @CRLF & _ 'If exist "' & @ScriptFullPath & '" GOTO :DelFile' & @CRLF & _ 'Goto :CheckFile' & @CRLF & _ ':DelFile' & @CRLF & _ 'del /f /q "' & @ScriptFullPath & '"' & @CRLF & _ 'del /f /q "' & @TempDir & '\~deltmp.bat"' $sCMDLine = _StringANSI2OEM($sCMDLine) $hFile = FileOpen(@TempDir & "\~deltmp.bat", 2) FileWrite($hFile, $sCMDLine) FileClose($hFile) Run(@TempDir & "\~deltmp.bat", @TempDir, @SW_HIDE) EndIf Edit: Forgot this function: Func _StringANSI2OEM($strText) Local $buf = DllStructCreate("char["& StringLen($strText)+1 &"]") Local $ret = DllCall("User32.dll", "int", "CharToOem", "str", $strText, "ptr", DllStructGetPtr($buf)) If Not(IsArray($ret)) Then Return SetError(1, 0, '') If $ret[0]=0 Then Return SetError(2, $ret[0], '') Return DllStructGetData($buf, 1) EndFunc ;==> _StringANSI2OEM Edited November 8, 2009 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now