ZenKensei Posted December 13, 2004 Share Posted December 13, 2004 Group, I could use just a little help. I'm writing an AutoIt script that will take advantage of the program Dellater.exe which is used to delete files that are currently locked and in use at the next PC reboot. Since the file that is in use may vary, I was going to have the user select the file (or files) with the FileOpenDialog function. What I'm not familiar with is how to make sure that the Dellater application runs against each file. The command line for the Dellater.exe app is 'Dellater.exe <filename>'. Below is the code that I've been toying with, but I don't know how to seperate out each file selected (hopefully in the order selected by the user) and run the Dellater.exe against each file. FileInstall("Dellater.exe", @WindowsDir & "\Dellater.exe") $message = "Hold down Ctrl or Shift to choose multiple files." $Var = FileOpenDialog($message, "C:\Windows\", "All Files (*.*)", 1 + 4) If @error Then MsgBox(4096, "", "No File(s) chosen") Else $DelFile = StringReplace($Var, "|", @CRLF) MsgBox(4096, "", "You chose " & $DelFile) EndIf RunWait(@ComSpec & " /c " & @WindowsDir & "Dellater.exe " & $DelFile) Somehow, I believe I need to break apart the $Delfile variable and run the Dellater.exe against each instance of the split, just not sure what direction I go to do that. Any help would be appreciated Thanks in advance, ZK Link to comment Share on other sites More sharing options...
this-is-me Posted December 13, 2004 Share Posted December 13, 2004 You can use a script by ezzetabi to delete files later on all versions of windows without having to reinvent the wheel. Who else would I be? Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 13, 2004 Share Posted December 13, 2004 (edited) Try this and see how it works. Dim $i $i = 1 FileInstall("Dellater.exe", @WindowsDir & "\Dellater.exe") $message = "Hold down Ctrl or Shift to choose multiple files." $Var = FileOpenDialog($message, "C:\Windows\", "All Files (*.*)", 1 + 4) If @error Then MsgBox(4096, "", "No File(s) chosen") EndIf $DelFile = StringSplit($Var, "|") If $DelFile[0] > 0 Then MsgBox(4096, "", "You chose " & $DelFile[0] & " files") EndIf While 1 RunWait(@ComSpec & " /c " & @WindowsDir & "Dellater.exe " & $DelFile[$i]) If $i <= ($DelFile[0] - 1) Then $i = $i + 1 Else MsgBox(0, "Finished", You have deleted " & $DelFile[0] & " files") ExitLoop EndIf WEnd Edit: I modified my code to work more efficiently. Let me know if you have tried it or if it works or not please. Thanks, JS Edited December 15, 2004 by JSThePatriot AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
ezzetabi Posted December 13, 2004 Share Posted December 13, 2004 eheheh... Nice one. Did you see that the msgbox appear for every file you selected?Have you ever thought about thinking on purpose?Btw, here a link to my udf for deleting file boot time.http://www.autoitscript.com/forum/index.ph...wtopic=5888&hl= Link to comment Share on other sites More sharing options...
ZenKensei Posted December 13, 2004 Author Share Posted December 13, 2004 JS and EZ; Thank you both for your quick responses, they both give me options to use. ezzetabi, could I trouble you with 2 questions about your script? 1) just briefly looking at your script (briefly because it made my head hurt... ), could the functionality you use in your script be modified to work on a remote machine, or are all the calls locally specific? 2) Could the script be modified to read a list of files to delete from a text file (either locally or on a remote machine)? My thought is this. As a network administrator and one who is also in charge of our Microsoft SMS software, it is often necessary to 'clean up' the SMS client from PC's and servers. If you lucky, everything goes smooth using one or two of the established tools and the client is removed and can be installed again correctly (lucky in this instance means you have a better chance of hitting the lotto!). Usually its a matter of deleting some registry keys along with some SMS specific files/folders (these are more or less constant). I was thinking about the possibility of using your script (either by itself if it could modified to work on a remote machine) or with PSExec and a text file if I could modify it to read the list of files to be deleted. Let me know what you think if you have a moment.Thanks,ZK Link to comment Share on other sites More sharing options...
SumTingWong Posted December 13, 2004 Share Posted December 13, 2004 (edited) You can use MoveFileEx instead of Dellater. Here's a couple of examples: To delete: Global $MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 Dim $naDllRet, $sFileName $sFileName = @ScriptDir & "\Test.txt" $naDllRet = DllCall("kernel32.dll", "int", "MoveFileEx", _ "str", $sFileName, _ "int", 0, _ "int", $MOVEFILE_DELAY_UNTIL_REBOOT) If Not @error Then If $naDllRet[0] > 0 Then MsgBox(4096,'debug:' , '$naDllRet: Success');### Debug MSGBOX Else MsgBox(4096,'debug:' , '$naDllRet: Failure');### Debug MSGBOX EndIf EndIf To rename: Global $MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 Dim $naDllRet, $sOldFile, $sNewFile $sOldFile = @ScriptDir & "\Test.old" $sNewFile = @ScriptDir & "\Test.new" $naDllRet = DllCall("kernel32.dll", "int", "MoveFileEx", _ "str", $sOldFile, _ "str", $sNewFile, _ "int", $MOVEFILE_DELAY_UNTIL_REBOOT) If Not @error Then If $naDllRet[0] > 0 Then MsgBox(4096,'debug:' , '$naDllRet: Success');### Debug MSGBOX Else MsgBox(4096,'debug:' , '$naDllRet: Failure');### Debug MSGBOX EndIf EndIf Edited December 13, 2004 by pacman Link to comment Share on other sites More sharing options...
ezzetabi Posted December 13, 2004 Share Posted December 13, 2004 JS and EZ; 1) just briefly looking at your script (briefly because it made my head hurt... ), could the functionality you use in your script be modified to work on a remote machine, or are all the calls locally specific?As is it works in the local machine, but they are functions, so you just have to create the script that uses them and execute the script in the remote machine with PSEXEC.2) Could the script be modified to read a list of files to delete from a text file (either locally or on a remote machine)? <{POST_SNAPBACK}>Sure, being a Func it is enough using FileRead and StringSplit for having the list of files and a easy loop for deleting every file boottime. Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 15, 2004 Share Posted December 15, 2004 (edited) eheheh... Nice one. Did you see that the msgbox appear for every file you selected?Have you ever thought about thinking on purpose?Btw, here a link to my udf for deleting file boot time.http://www.autoitscript.com/forum/index.ph...wtopic=5888&hl=<{POST_SNAPBACK}>Yes one of the message boxes shows up everytime, but that is how he had it I will fix it though Why are you using my quote on me? Did I miss something? (Other than the whole MsgBox() deal?)Edit: I edited the above post to contain the more efficient code.JS Edited December 15, 2004 by JSThePatriot AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
ezzetabi Posted December 15, 2004 Share Posted December 15, 2004 Because I actually dislike your quote. I think it is a generic blaming, quite unpleasent. It is like writing "You are all stupids". Anyway, do you want more 'missings'? Here we are Try Msgbox(0,'',@WindowsDir) As you can see there are no trailing backslashes. Probably you have to use (but I am not totally sure, maybe autoit cares about adding it if needed) RunWait(@ComSpec & " /c " & @WindowsDir & "\Dellater.exe " & $DelFile[$i]) Not enough? I never used Dellater.exe but probably if the filename contains spaces you need to use quotes. So RunWait(@ComSpec & ' /c ' & @WindowsDir & '\Dellater.exe "' & $DelFile[$i] & '"') Again? FileOpenDialog returns a string with Dir|filename1|filename2 and so go on if you select more than one file, and the filename if you selected just one. So you need to check if there are pipes in the string, if there are then you have to use string split and using the result array like $list[1] & $list[$counter] where $counter rolles between 2 to $list[0] in fact $list[1] will keep the foldername, $list[xx] the filenames. if no pipes are present you can just use the filedialog output string. Yet again? Well, using a While 1 in that case seems quite unnatural to me. It is not better using a For/Next loop? You know how many files you selected after all. Still hungry? You fileinstalled a file and you didn't delete it. Really want more? You used Dim as you wanted to use Opt('MustDeclareVars',1) but you didn't pre declared the other variants. I didn't actually tested, but I have some ideas for thinking that it wont work well... Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 15, 2004 Share Posted December 15, 2004 Because I actually dislike your quote.I think it is a generic blaming, quite unpleasent.It is like writing "You are all stupids".Anyway, do you want more 'missings'? Here we areTryMsgbox(0,'',@WindowsDir)As you can see there are no trailing backslashes. Probably you have to use (but I am not totally sure, maybe autoit cares about adding it if needed)RunWait(@ComSpec & " /c " & @WindowsDir & "\Dellater.exe " & $DelFile[$i])Not enough?I never used Dellater.exe but probably if the filename contains spaces you need to use quotes. SoRunWait(@ComSpec & ' /c ' & @WindowsDir & '\Dellater.exe "' & $DelFile[$i] & '"')Again?FileOpenDialog returns a string with Dir|filename1|filename2 and so go on if you select more than one file, and the filename if you selected just one.So you need to check if there are pipes in the string, if there are then you have to use string split and using the result array like $list[1] & $list[$counter] where $counter rolles between 2 to $list[0]in fact $list[1] will keep the foldername, $list[xx] the filenames.if no pipes are present you can just use the filedialog output string.Yet again?Well, using a While 1 in that case seems quite unnatural to me. It is not better using a For/Next loop?You know how many files you selected after all.Still hungry?You fileinstalled a file and you didn't delete it.Really want more?You used Dim as you wanted to use Opt('MustDeclareVars',1) but you didn't pre declared the other variants.I didn't actually tested, but I have some ideas for thinking that it wont work well... <{POST_SNAPBACK}>Okay about my quote, it isnt stating anyone is stupid or that everyone is stupid. My quote asks a simple question. Have you ever thought about thinking (everyone has done this), but the tricky part is have you done it on purpose. If you think about what you are thinking about on purpose it can be good and sometimes it can be bad, it all depends on the situation. Please dont jump on me for my quote when there is no harm meant. Please understand the meaning behind the quote before jumping on me.As far as the script goes. I just used what he already had. I didnt check to see if it was correct or not. I added the while statement. It works, even though for the situation a For...Next loop would have made 'logical' sense even though both of them work, just one requires one more line.As I stated above I wasnt fixing his script for him. I was just adding the functionality that I saw he would probably need to do what he wanted. If I wanted to fix his script I would have declared all of the variables, and whether or not I used the option to make sure I did or I just did doesnt matter that is all user preference. There is no AutoIt rule that says you have to use the option if you are even going to Dim your variables. If there is please show it to me and I will retract this otherwise dont jump my case for a user preference item.All of your statements are jumping on me for my script, which really isnt my script I copied his and modified it slightly to give him an idea of where to go. You can try to flame me for something that isnt mine, but that doesnt matter I am sure I could go view your scripts and let you know where you have logical errors as everyone has bugs, so before you jump on me about anything especially if it isnt mine then I suggest you make all of your scripts perfect.Want me to keep going? I should hope not. I like you, I didnt know you had all these bad feelings. You seem to have been storing this up to now. I guess my signature bothered you evertime you have seen me post. I have respected your work up to this point. Now you have lost some of my respect. Not all of it yet, I know this probably means nothing to you as we are just all online, it still means something as I wont take your scripting as seriously anymore. I wont be of support when you put out a new UDF. You lost support, your loss not mine.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
ezzetabi Posted December 16, 2004 Share Posted December 16, 2004 (edited) An other nice one! I lost some consideration for some friendly advices?The way I wrote may seems blaming, but it was just a fun (for me) joke.If you don't like my scripting anymore, pity.About bad feelings... Ok. I dislike your QUOTE, but that does not mean that I hate YOU or whatever.Still... This answer bother me..I wont be of support when you put out a new UDF. You lost support, your loss not mine.Just FYICheck this linkhttp://www.autoitscript.com/forum/index.ph...opics&highlite=How many times you actually helped me in a 'Support' question?Anyway. I think this discussing is pretty useless and overall wrong. In fact I was willing to help you, I used your quote just for fun. You asked me if I had more things to say you missed I answered.... This was all.I think we can just be friend as before, at least from my part. Edited December 16, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
JSThePatriot Posted December 16, 2004 Share Posted December 16, 2004 (edited) An other nice one! I lost some consideration for some friendly advices?The way I wrote may seems blaming, but it was just a fun (for me) joke.If you don't like my scripting anymore, pity.About bad feelings... Ok. I dislike your QUOTE, but that does not mean that I hate YOU or whatever.Still... This answer bother me..Just FYICheck this linkhttp://www.autoitscript.com/forum/index.ph...opics&highlite=How many times you actually helped me in a 'Support' question?Anyway. I think this discussing is pretty useless and overall wrong. In fact I was willing to help you, I used your quote just for fun. You asked me if I had more things to say you missed I answered.... This was all.I think we can just be friend as before, at least from my part.<{POST_SNAPBACK}>My mistake. If it was all for fun please forgive me. I have been sick recently and have been taking everything badly. So I ask you to forgive my rudeness. I will rethink my quote.I havent actually helped you with a support question as far as I know. I am glad to know this was all in fun and such my apologies. Edit: SpellingJS Edited December 16, 2004 by JSThePatriot AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) 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