TehBeyond Posted May 17, 2007 Share Posted May 17, 2007 It seems like everyone and their uncle has asked (or answered) a question about FIleINstall. However, I have not been able to discover where I have been going wrong. I have been experiencing some issues... Sometimes my FileInstall commands work, but usually they don't. However, I need a program that will work the first time, every time. Just so you know what this code does...It is a script that writes scripts. The idea is that people that don't have AutoIt can easily 'lock' files. When the script is run, it is supposed to install files into the temp directory. These files are the ones that AutoIt uses to convert .au3 files into .exe files. THe script writes a script, inclluding a line of FileInstall (this is *not* the FileInstall that doesn't work). It then compiles it into an exe (with the chosen file packed into it), which later acts as a self-extractor. I know my code works because when I call the Aut2Exe from its current directory, it works just fine. I know this code is very simplistic... I wrote it several months ago when I was new to AutoIt. I am aware that there are better ways to "lock" files. I do, however, want to implement the self-writing script capabilities for some of my other programs. The FileInstall is important (because not everyone that will use my program has AutoIt.) Please excuse my rambling nature; any assistance would be appreciated. -TehBeyond CODEexpandcollapse popup#cs This code written by TehBeyond tehbeyond@gmail.com 7/21/06 This code modifed by _________ ___________________ ________ This code modifed by _________ ___________________ ________ This code modifed by _________ ___________________ ________ Feel free to modify this code, but leave this portion intact. Add your name/email to a Modifed By line before distributing your code. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||Description|||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| This script writes scripts :D The idea is to complile this script. It will get all of the files it needs in order to create its own compiled scripts. It 'locks' files by FileInstalling them into the .exe that it creates. Unfortunately, the FileInstall commands below work only half the time. #ce ;#NoTrayIcon Opt("TrayIconDebug", 1) Opt("WinTitleMatchMode", 3) FileInstall("C:\Program Files\AutoIt3\Aut2Exe\Aut2Exe.exe",@TempDir&"\FileLock\Aut2Exe.exe",1) FileInstall("C:\Program Files\AutoIt3\Aut2Exe\AutoItSC.bin",@TempDir&"\FileLock\AutoItSC.bin",1) FileInstall("C:\Program Files\AutoIt3\Aut2Exe\upx.exe",@TempDir&"\FileLock\upx.exe",1) FileInstall("C:\ArchiveStuff\MainArchive.7z\Programs\FileLock\_Readme.txt",@TempDir&"\FileLock\_readme.txt",1) FileInstall("C:\ArchiveStuff\MainArchive.7z\Programs\FileLock\padlock.ico",@TempDir&"\FileLock\icon.ico",1) FileSetAttrib(@TempDir&"\FileLock","+H",1) $filesource = FileOpenDialog("FileLock--> Lock. Please select source file.", "C:\", "All Files(*.*)" ,3) If @error = 1 Then Exit EndIf Call("SetDefaultName") Do $filedestination = FileSaveDialog( "FileLock--> Lock. Please select destination file.", "C:\", "Executables (*.exe)",16,$DefaultName) If @error = 1 Then Local $temp=MsgBox(52,"FileLock--> Save Error","A destination is necessary. Do you wish to Exit? Click No to try again.") If $temp = 6 Then Exit EndIf EndIf Until $filedestination <> "" Do $password=InputBox("FileLock-->Lock","Please enter the unlock password for your Locked file.","","*",250,130) If @error = 1 OR $password="" OR (@error = 1 AND $password="") Then Local $temp=MsgBox(52,"FileLock--> Password Error","A Password is necessary. Do you wish to Exit? Click No to try again.") If $temp = 6 Then Exit EndIf EndIf Until $password <> "" If StringRight($filedestination,4) <> ".exe" Then Local $temp=$filedestination Global $filedestination=$temp&".exe" EndIf Call("WriteFile2Compile") Sleep(1000) Call("Compile") FileSetAttrib(@TempDir&"\FileLock\filetemp.au3","-SHR") While FileExists(@TempDir&"\FileLock\filetemp.au3") FileDelete(@TempDir&"\FileLock\filetemp.au3") WEnd MsgBox(64,"FileLock","Your file was Locked and is in your chosen directory.") Exit Func WriteFile2Compile() $filetemp=FileOpen(@TempDir&"\FileLock\filetemp.au3",10) FileWriteLine($filetemp,"#NoTrayIcon") FileWriteLine($filetemp,'Global $pword="'&$password&'"') FileWriteLine($filetemp,'$passwordinput=InputBox("FileLock-->Unlock","Please enter the unlock password.","","*",250,130)') FileWriteLine($filetemp,'While $pword <>$passwordinput') FileWriteLine($filetemp,'IF @error = 1 Then') FileWriteLine($filetemp,'Exit') FileWriteLine($filetemp,'EndIf') FileWriteLine($filetemp,'$passwordinput=InputBox("FileLock-->Unlock","WRONG Password. Please enter the CORRECT password.","","*")') FileWriteLine($filetemp,'Wend') FileWriteLine($filetemp,'While 1') FileWriteLine($filetemp,'$filedestination = FileSaveDialog( "FileLock-->Unlock-->Destination", "C:\", "Executables (*.exe)",16,"'&$DefaultName2&'")') FileWriteLine($filetemp,'If @error = 1 Then') FileWriteLine($filetemp,'Exit') FileWriteLine($filetemp,'Else') FileWriteLine($filetemp,'ExitLoop') FileWriteLine($filetemp,'EndIf') FileWriteLine($filetemp,'Wend') FileWriteLine($filetemp,'FileInstall("'&$filesource&'",$filedestination,1)') FileWriteLine($filetemp,'MsgBox(64,"FileLock-->Unlock","The file was unlocked to your chosen directory.")') FileClose($filetemp) EndFunc Func Compile() Run(@TempDir&"\FileLock\Aut2Exe.exe",@TempDir&"\FileLock\",@SW_HIDE) Do Sleep(100) Until 1=WinExists("Aut2Exe v3 - AutoIt Script to EXE Converter") ControlSetText("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1020,FileGetLongName(@TempDir&"\FileLock\filetemp.au3",1)) ControlSetText("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1025,$filedestination) ControlSetText("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1026,@TempDir&"\FileLock\icon.ico") If ControlCommand("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1030,"IsChecked","") Then ControlCommand("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1030,"UnCheck","") EndIf WinMenuSelectItem("Aut2Exe v3 - AutoIt Script to EXE Converter","","C&ompression","Highest") WinMenuSelectItem("Aut2Exe v3 - AutoIt Script to EXE Converter","","C&ompression","UPX Compress .exe stub") ControlSend("Aut2Exe v3 - AutoIt Script to EXE Converter",'',1026,"^c") While 0=WinExists("Aut2Exe") Sleep(50) WEnd ProcessClose("Aut2Exe.exe") EndFunc Func SetDefaultName() Local $i=0 Local $tempread While $tempread <> "\" Local $i2=$i $i=$i2+1 $tempread=StringLeft(StringRight($filesource,$i),1) WEnd Global $DefaultName2=StringTrimLeft($filesource,StringLen($filesource)-($i-1)) $i=0 While $tempread <> "." AND $i <51 Local $i2=$i $i=$i2+1 $tempread=StringLeft(StringRight($filesource,$i),1) WEnd If $i<51 Then Global $DefaultName="FL"&StringTrimRight($DefaultName2,$i)&".exe" Else Global $DefaultName="FL"&$DefaultName2&".exe" EndIf EndFunc I would have told you I have Alzheimer's, but I forgot.My Splendid-Tastic Blog Link to comment Share on other sites More sharing options...
Somerset Posted May 17, 2007 Share Posted May 17, 2007 try and use FileExists to make sure all files are there before caring on with the script... the script maybe running too fast and is trying to hide the folder before everything is extracted. good luck. Link to comment Share on other sites More sharing options...
MHz Posted May 17, 2007 Share Posted May 17, 2007 The destination folder used in FileInstall() must exist for success.If DirCreate(@TempDir & '\FileLock') Then FileInstall("C:\Program Files\AutoIt3\Aut2Exe\Aut2Exe.exe", @TempDir & "\FileLock\Aut2Exe.exe", 1) FileInstall("C:\Program Files\AutoIt3\Aut2Exe\AutoItSC.bin", @TempDir & "\FileLock\AutoItSC.bin", 1) FileInstall("C:\Program Files\AutoIt3\Aut2Exe\upx.exe", @TempDir & "\FileLock\upx.exe", 1) FileInstall("C:\ArchiveStuff\MainArchive.7z\Programs\FileLock\_Readme.txt", @TempDir & "\FileLock\_readme.txt", 1) FileInstall("C:\ArchiveStuff\MainArchive.7z\Programs\FileLock\padlock.ico", @TempDir & "\FileLock\icon.ico", 1) FileSetAttrib(@TempDir & "\FileLock", "+H", 1) Else MsgBox(0x40030, 'FileLock', 'User Temp folder is inaccessable' & @CRLF & 'Program will now Exit') Exit 1 EndIf Link to comment Share on other sites More sharing options...
erebus Posted May 17, 2007 Share Posted May 17, 2007 Interesting observation. So, why not to ask for a new feature here -- let's say a new flag (i.e. 2) which will automatically creates the dir if not in place. Something like: FileInstall ( "source", "dest", 1+2 ) ; overwrite + create path Link to comment Share on other sites More sharing options...
TehBeyond Posted May 17, 2007 Author Share Posted May 17, 2007 The destination folder used in FileInstall() must exist for success. Wow. I can't believe it was so easy! Thanks for the help. [Looks at self... thinks "Why didn't I think of that??!!?"] Anyway, thanks a ton. -TehBeyond I would have told you I have Alzheimer's, but I forgot.My Splendid-Tastic Blog 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