Sign in to follow this  
Followers 0
Ravel

Need help with a usb flash drive script

5 posts in this topic

QUOTE (TurionAltec @ May 31 2008, 03:13 PM) *

You could also look at making a script that could automatically figure out what drive is what by using Drivegetdrive() to find what drives exist on the computer

Then use DriveGetLabel() or maybe Fileexists to see what a given drive is.

Here's a piece of code that I whipped up but haven't tested. It will try to read the drive values from an ini file, where each computer will have their own section. If the section doesn't exist, it will figure out what drive's what, then save to the ini file. Each drive is in the "F:" format.

AutoIt

Global $USB_DriveLtr
Global $Fldr_Programs_DriveLtr
Global $Fldr_AutoIt_dataFldr_DriveLtr
$inidriveletters=IniReadSection(@ScriptDir & "\driveletters.ini",@ComputerName)
If @error==1 Then

    Finddrives()
Else
    For $i=1 to $inidriveletters[0][0]
        If $inidriveletters[$i][0] =="USB_DriveLtr" Then
            $USB_DriveLtr=$inidriveletters[$i][1]
        ElseIf $inidriveletters[$i][0] =="Fldr_Programs_DriveLtr" Then
            $Fldr_Programs_DriveLtr=$inidriveletters[$i][1]
        ElseIf $inidriveletters[$i][0] =="Fldr_AutoIt_dataFldr_DriveLtr" Then
            $Fldr_AutoIt_dataFldr_DriveLtr=$inidriveletters[$i][1]
        EndIf
    Next
   
EndIf

   

Func Finddrives()
    $var = DriveGetDrive( "all" )
    If NOT @error Then
        MsgBox(4096,"", "Found " & $var[0] & " drives")
        For $i = 1 to $var[0]
            If DriveGetLabel($var[$i]) == "USBFLASH" Then
                $USB_DriveLtr=$var[$i]
            ElseIf DriveGetLabel($var[$i]) == "Programs" Then
                $Fldr_Programs_DriveLtr=$var[$i]
            ElseIf DriveGetLabel($var[$i]) == "AUTOIT" Then
                $Fldr_AutoIt_dataFldr_DriveLtr=$var[$i]
            EndIf
        Next
        IniWriteSection(@ScriptDir & "\driveletters.ini",@ComputerName,"USB_DriveLtr="& $USB_DriveLtr&@LF   & "Fldr_Programs_DriveLtr="& $Fldr_Programs_DriveLtr&@LF &"Fldr_AutoIt_dataFldr_DriveLtr=" & $Fldr_AutoIt_dataFldr_DriveLtr)
    EndIf
   
EndFunc

I was looking at this code here, and doing a forum search to try and build a code to perform a task for me. I am really not a coder, but what the original poster of this thread was initially looking for seems like it would serve me too. What I am trying to do is I have roboform portable on my USB flash drive (root\roboform\portableroboform.exe) when the program runs initially it unpacks the "AiRoboForm-Portable.bin" file to windows temp folder. What I want to do is have a script that will automatically search for the usb drive named "WORKUSB" and copy a file {roboform.dll} (located on the workusb flashdrive) which is located at: Root\Roboform\Roboform and copy it as a read only file to the windows temp folder where the aboved .bin file was unpacked. This should occur first, then execute the above .exe file. I would then like it to l lay in wait, until the "portableroboform.exe" is no longer running and then delete the the above .dll file. and exit.

Hopefully you guys can understand this well enough to assist with developing a script that would work. Because I cant seem to wrap my head around the codes to make it a reality. Any help is appreciated.

Share this post


Link to post
Share on other sites



Anyone?

Share this post


Link to post
Share on other sites

Is the script being run from the USB drive? If so that will make things easier. You can use @scriptdir to see where the program is being run from

;if the script is f:\autoit\script.exe
;@scriptdir will be "f:\autoit"
msgbox(1,"Scriptdir is", @Scriptdir)

$USBdrive= StringLeft(@scriptdir,3)
;$USBdrive will now contain "f:\"
msgbox(1,"USBdrive is",$USBdrive)oÝ÷ ØZèØ^­ì¨¹Æ§ºÇ­í7éDv¸¯zö«¦å{^*.Á©í¶(§'âëéî±än¢¶Ú,µªí¶©®+jf§v+pYijëëh×±yË­îإجvÞjëh×6Filecopy($USBdrive&"Roboform\Roboform.dll",@tempdir)
Filecopy($USBdrive&"Roboform\Roboform.exe",@tempdir)

RunWait(@tempdir & "\Roboform.exe")

filedelete(@tempdir& "\robofirm.dll")
filedelete(@tempdir& "\robofirm.exe")

I haven't tested any of this code. Specifically I don't know whether @tempdir has a trailing "\" or not.

Hope that gives you some ideas :)

Share this post


Link to post
Share on other sites

another idea if you want to consolidate the script exe, AND the roboform files into one file, you can use Fileinstall to extract them during runtime.

FileInstall ( "c:\Autoit\scriptstobuild\AiRoboForm-Portable.bin", @TempDir)
FileInstall ( "c:\Autoit\scriptstobuild\roboform.dll", @TempDir )
FileInstall ( "c:\Autoit\scriptstobuild\roboform.exe", @TempDir)
;The first  parameter is the location of the file to be included into the compiled exe and must be literal, not a variable, the second 
;parameter will drop it into the Temp directory when the compiled exe is run

FileSetAttrib (@tempdir& "\roboform.dll", "+R") ;set read only
FileSetAttrib (@tempdir& "\roboform.exe", "+R")
FileSetAttrib (@tempdir& "\AiRoboForm-Portable.bin", "+R")

runwait(@tempdir& "\roboform.exe, @tempdir); Runs the program from the tempdir with a  working directory of tempdir

FileSetAttrib (@tempdir& "\roboform.dll", "-R") ;clear read only
FileSetAttrib (@tempdir& "\roboform.exe", "-R")
FileSetAttrib (@tempdir& "\AiRoboForm-Portable.bin", "-R")

filedelete(@tempdir& "\roboform.dll")
filedelete(@tempdir& "\roboform.exe")
filedelete(@tempdir& "\AiRoboForm-Portable.bin")

Share this post


Link to post
Share on other sites

another idea if you want to consolidate the script exe, AND the roboform files into one file, you can use Fileinstall to extract them during runtime.

FileInstall ( "c:\Autoit\scriptstobuild\AiRoboForm-Portable.bin", @TempDir)
FileInstall ( "c:\Autoit\scriptstobuild\roboform.dll", @TempDir )
FileInstall ( "c:\Autoit\scriptstobuild\roboform.exe", @TempDir)
;The first  parameter is the location of the file to be included into the compiled exe and must be literal, not a variable, the second 
;parameter will drop it into the Temp directory when the compiled exe is run

FileSetAttrib (@tempdir& "\roboform.dll", "+R") ;set read only
FileSetAttrib (@tempdir& "\roboform.exe", "+R")
FileSetAttrib (@tempdir& "\AiRoboForm-Portable.bin", "+R")

runwait(@tempdir& "\roboform.exe, @tempdir); Runs the program from the tempdir with a  working directory of tempdir

FileSetAttrib (@tempdir& "\roboform.dll", "-R") ;clear read only
FileSetAttrib (@tempdir& "\roboform.exe", "-R")
FileSetAttrib (@tempdir& "\AiRoboForm-Portable.bin", "-R")

filedelete(@tempdir& "\roboform.dll")
filedelete(@tempdir& "\roboform.exe")
filedelete(@tempdir& "\AiRoboForm-Portable.bin")
Ok. I will test this one out. It looks promising. I haven't had a chance to do it yet, because I am at work. But once I get a second to do so I will try it out. But from the looks of the script this is exactly what I am looking for. If anything it will definitely put me on the right track. Thanks.

Share this post


Link to post
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
Sign in to follow this  
Followers 0