Jump to content

running autoit scripts from cdrom drive


daremo
 Share

Recommended Posts

I just downloaded AutoIt v3 since AutoIt v2 didn't have the RunAsSet command which I needed. But I'm at a loss on how to run a AutoIt script from a cdrom, that calls a file from the cdrom to install on the pc.

Here is more detail. I'm trying to create a autolaunching cd that will install some microsoft patches from the cd. During the install process, it will insert a registry key into the Runonce key to launch the autoit script from within the cd. Upon reboot of the machine, the machine will call the AutoIt script from the cd and then run the program that is specified in the script.

My problem is that I don't know how to get the AutoIt script to know what the drive letter of the cd will be (since this will change depending on the machine that the cd is used on) and then install the program that is specified in the AutoIt script.

Thanks for any help!

Link to comment
Share on other sites

edit... To see the easy way view the post after this B)

I removed my code because it was sloppy. This was very old code, and I am a bit ashamed of it now. :angry:

The theory is to have AutoIt determine the Script's name and path, and rerun itself on reboot, and then determine if it got done with what it was doing.

Also I realised my code could have been used for :whistle: so I removed it.

You can write a text file on the hard drive to determine the progress (logfile.) And check the existance of it, and read the last line if you want to get fancy into a progress bar.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Ok, now that you read the hard way, ( just realised your requirements are quite a bit easier )

This code will run your EXE from where ever you ran it the first time next reboot. Put some code to check where you are on the patch progress

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUNONCE", "TestKey", "REG_SZ", @ScriptFullPath)

I would determine where you were on reboots from patch info, file dates, or a log file, but you can also make several exe files if there is a reason for that. If you want to run several patches, you may wish to run a sequence of exe files. (more work than I would go to.)

....edit added some options for ya.

; autostart.exe start
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUNONCE", "TestKey", "REG_SZ", @ScriptDir&"\patch2.exe")

; Patch2.exe start
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUNONCE", "TestKey", "REG_SZ", @ScriptDir&"\patch3.exe")
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

My problem is that I don't know how to get the AutoIt script to know what the drive letter of the cd will be (since this will change depending on the machine that the cd is used on) and then install the program that is specified in the AutoIt script.

Lookup the following functions - the examples in the Help file explain better than I can here..
  • DriveGetDrive() - Returns an array containing the enumerated drives.
  • DriveGetFileSystem () - Returns File System Type of a drive
  • DriveGetType() - Returns drive type
  • DriveStatus () - Returns the status of the drive as a string, useful in case your user ejected the CD!
HTH :whistle:
Link to comment
Share on other sites

shameless plug... unofficial help file explains the aforementioned functions better (and, I hope, accurately) than the current help file

(edited to fix spelling error)

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Here is more detail.  I'm trying to create a autolaunching cd that will install some microsoft patches from the cd.

I am using AutoIt script for same purpose (installation of patches on W2K).

I made my script with different approach:

- all MS patches are compiled in script (FileInstall)

- patches are installed in %TEMP% folder

- script is running patches with proper switches not to reboot computer

- after running, script is deleting patches from %TEMP% folder

- on the end, script is running qchain.exe.

- script is forcing reboot.

With AutoIt v2, all patches were compiled in second script and that script was executed from first one (FileInstall to %TEMP% folder) with admin rights (Run/Sleep/Send procedure).

Second script was deleted from RunOnce key but from HKCU, not from HKLM because user does not have delete rights in that part of registry

On AutoIt v3, I am having some problems with unexpected delay when running with RunAsSet, but I cannot confirm it that is a problem with AutoIt.

This is not releated with the question, but maybe can be usefull...

Link to comment
Share on other sites

I have been using Autoit3 for similar reasons, and come up with (and in the middle of) developing a somewhat generic solution.

I have a file called "software.ini" that looks like this:

[FirstRun]

SoftwareToDo=ViaChipSet

[secondRun]

SoftwareToDo=WinRar,Indeo,TightVNC,W2KSupport,Mozilla,DivX,IrfanView,WinAmp,IE6

[ThirdRun]

SoftwareToDo=MediaPlayer7,MediaPlayer9,RealPlayer8,RealPlayerGold,MDAC,Acrobat5,Acrobat6,PageDfrg,St

dRegSettings,Recovery

[indeo]

Install=Yes

Languages=EN

ENCMD=%CDROM%\INST\Indeo\Setup -s

[Acrobat5]

Install=No

Languages=NL,EN

NLCMD=%CDROM%\Inst\NL\AcrRead51\setup -s

ENCMD=%CDROM%\Inst\EN\AcrRead51\setup -s

My installation routine looks like this (not finished yet, but the idea is clear I think), and this also finds the right :whistle: CD ROM Drive if there is more than 1....

$InstPrefLang="NL"

$InstDrv="0"

$IniFileName="C:\Inst\SoftWare.ini"

;AutoItSetOption("ExpandEnvStrings",1)

$CD = DriveGetDrive("CDROM")

For $I=1 to Number($CD[0])

$pa = $CD[$I] & "\SPNOTES.HTM"

If FileExists($pa) Then

$instDrv=$CD[$I]

Endif

Next

If $InstDrv="0" Then

exit

Endif

EnvSet("CDROM", $InstDrv)

$result=IniRead($IniFileName, "SecondRun", "SoftWareToDo", "Not Found")

$SWArr=StringSplit($result, ",")

$SWHi=Ubound($SWArr)-1

ProgressOn("Additional Software Installations", "Installing..." & $SWArr[0], 0, @DesktopHeight - 150)

For $I = 0 to $SWHi

ProgressSet( $I/$SWHi*100, "Installing..." & $SWArr[$I])

$result = IniRead( $IniFileName,$SWArr[$I],"Install", "No")

If $result = "Yes" Then

$result = IniRead( $IniFileName,$SWArr[$I],"Languages", "EN")

$LangArr=StringSplit($result, ",")

$LangHi=$LangArr[0]

$PrefLangFound=1

If $LangHi>1 Then

For $J = 1 to $LangHi

If $InstPrefLang=$LangArr[$J] Then

$PrefLangFound=$J

EndIf

Next

EndIf

$RunCMD = IniRead( $IniFileName,$SWArr[$I], $LangArr[$PrefLangFound] & "CMD", "")

$RunCMD=StringReplace($RunCMD, "%CDROM%", $InstDrv)

MSGBox(1, "test", $RunCMD)

RunWait( $RunCMD )

EndIf

Next

Link to comment
Share on other sites

finding the correct CD is fairly easy. Since you would be running it from that CD the first time, @ScriptDir finds the drive and path of the script you are running. I have seen systems with 4 CD drives, and one guy who had 24 mounted CD images (which appear as CD drives.)

This can be used to write an ini file on the hard drive in the temp folder, and refer to it as the script continues. It also would be nice to write in that file the status, so that as it installs, your splash screens show the total progress.

In your generic install file, a nice feature might be a choice with a timeout, so that a user may choose not to install all the functions, and it would write the INI file and intall only those.

Anywhere very simple code to show where you are running the script from.

MsgBox(1,"Drive is "&StringLeft(  @ScriptDir,1 )  ,"Drive:\path=" & @ScriptDir)
MsgBox(1,"Type of Drive is ",DriveGetType ( @ScriptDir))

If you are running this script from say a network, and you want it to do all the installs from one or several original CD disks, your solution looks like it would a bit better. I just prefer not to do searches if I don't need to.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Skriptkitty,

As I said, the script is in development. The primary goal of the script I am writing however is to create a completely unattended install, including all the additional software I prefer. As it is also intended for friends who know f*** all about IT, user interaction is not a feature intended :whistle:

Also, your solution of getting the name from the scriptdir is in my case not feasible, since I intend to run it from a floppy on which also the WINNT.SIF is placed.

Placing it on a floppy has the additional nicety, that you can edit the ini file before starting the installation, so it adaptable, while still using the same installation CD.

Anyway, here is the current version of the script with some of the features you mentiond as well:

$InstPrefLang="NL"
$InstDrv="0"
$IniFileName="A:\SoftWare.ini"

;Commandline parameters may include the preferred language (2 letter abbreviation)
;and the name of the software file
$Parms=""
If $CmdLine[0]> 0 Then
  For $I = 1 to $CmdLine[0]
      $Parms=$Parms & " " & $CmdLine[$I]
      If StringLen($CmdLine[$I]) > 2 Then
         $IniFileName=$CmdLine[$I]
      Else
         $InstPrefLang=$CmdLine[$I]
      EndIf
   Next
EndIf

;Get the CDROM drive Windows was installed from and should contain additional software to install
$CD = DriveGetDrive("CDROM")
For $I=1 to Number($CD[0])
   $pa = $CD[$I] & "\SPNOTES.HTM"
   If FileExists($pa) Then
    $instDrv=$CD[$I]
   Endif
Next
If $InstDrv="0" Then
   exit
Endif
EnvSet("CDROM", $InstDrv)

;Further addition could be a networkdrive to search for, but better would be to include in
;the'software.ini', an extra variable called FilePath, that specifies the absolute path if different
;from the CDROM, and the path and filename on the CD, so that a check can be made if the file exists
;before running the command (also enables failsafe operation of the script)


;Create if necessary, and write to log file 
;Usage: See in which 'run' we are, additionally write errors during installation

$LogFile=EnvGet("TEMP") & "\RvRSW.INI"
If FileExists($LogFile) Then
   $CurrentRun=IniRead( $LogFile, "Run", "Now", "0")
Else
   $Fnum = FileOpen($LogFile,2)
   FileWriteLine( $FNum, ";Logfile for Additional Installations")
   FileClose( $FNum)
   $CurrentRun=0
Endif

IniWrite($LogFile, "Run", "Now", $Result+1)

Select
   Case $CurrentRun = 0
       $Section="FirstRun"
   Case $CurrentRun = 1
       $Section="SecondRun"
   Case $CurrentRun = 2
       $Section="ThirdRun"
   Case $CurrentRun = 3
       $Section="FourthRun"
   Case $CurrentRun = 4
       $Section="FifthRun"
   Case $CurrentRun = 5
       $Section="SixthRun"
EndSelect


;Get the number of runs from the ini file
$result=IniRead($IniFileName, "NumberOfRuns", "Runs", "0")  

If $result < $CurrentRun Then
;Create Registry Keys to run on next boot
   RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Title", 

"REG_SZ","The Status dialogue won't be displayed because of Flags.")
   RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Flags", 

"REG_DWORD","136")

   $RgKey="||" & @ScriptFullPath & $Parms
   RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\ZZZZ", "Step01", 

"REG_SZ",$RgKey)
Else
  Exit
End if



;Get the list of software to install on this run
$result=IniRead($IniFileName, $Section, "SoftWareToDo", "Not Found")    
$SWArr=StringSplit($result, ",")

$SWHi=Ubound($SWArr)-1
ProgressOn("Additional Software Installations", "Please Wait...", "Installing... " & $SWArr[1], 0, 

@DesktopHeight - 150)

For $I = 0 to $SWHi
    ProgressSet( $I/$SWHi*100, "Installing..." & $SWArr[$I])       
    $result = IniRead( $IniFileName,$SWArr[$I],"Install", "No")
    If $result = "Yes" Then
       $result = IniRead( $IniFileName,$SWArr[$I],"Languages", "EN")
       $LangArr=StringSplit($result, ",")
       $LangHi=$LangArr[0]
       $PrefLangFound=1
       If $LangHi>1 Then
          For $J = 1 to $LangHi
            If $InstPrefLang=$LangArr[$J] Then
               $PrefLangFound=$J
            EndIf
         Next
       EndIf
       $RunCMD = IniRead( $IniFileName,$SWArr[$I], $LangArr[$PrefLangFound] & "CMD", "")
       $RunCMD=StringReplace($RunCMD, "%CDROM%", $InstDrv)
    MSGBox(1, "test", $RunCMD)
       RunWait( $RunCMD )
     EndIf
Next
Link to comment
Share on other sites

ronaldvr,

Nice work. I especially like how you are doing the INI files and such, very professional. Use of the temp drive and such, etc.

Sorry if I worded it in a way that you felt offended or something. I think it is great to run off a floppy, this way you can additionally do a status check on the CDRom drives and such, and give warnings, or even eject the CD if needed to change.

My only thing I don't like about floppy installs is reboot problems with bios settings, and the OS. Anyone know a way to turn off the boot from floppy setting from Windows? If this is a problem, you could write the script so that it copies itself to the temp drive, and asks the user to eject the floppy (Maybe you did actually, or were planning this.)

Part of what I really like about this board is that everyone comes out with a slightly different approach, and that many times you find a new way to do something.

I didn't double check your script or anything, but it looks very thought out.

I only have one small question, and most likely from cut and paste from your editor. I hate to ask because you may think I am nitpicking, and you did say under development. Especially since it is such a nice script. :whistle:

If $result < $CurrentRun Then

;Create Registry Keys to run on next boot

  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Title",

"REG_SZ","The Status dialogue won't be displayed because of Flags.")

  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Flags",

"REG_DWORD","136")

  $RgKey="||" & @ScriptFullPath & $Parms

  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\ZZZZ", "Step01",

"REG_SZ",$RgKey)

Else

was this part on the same line? or cntinuations like this?

If $result < $CurrentRun Then
;Create Registry Keys to run on next boot
  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Title", _
"REG_SZ","The Status dialogue won't be displayed because of Flags.")
  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx", "Flags", _
"REG_DWORD","136")

  $RgKey="||" & @ScriptFullPath & $Parms
  RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\ZZZZ", "Step01", _
"REG_SZ",$RgKey)
Else
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Skriptkitty,

I was not offended (I very rarely am;) I only got the impression that you hadn't read the 'under develeopment' bit or did not understand it. If I develop, I always do the rough stuff first, and the nice (GUI) bits (pun intended) later. It is a bit like 'Lets first get this car on the road and able to drive and worry about the spray job later'.

I should also mention that this script is not fully tested yet, so anyone: use at your own peril! If it is finished, I may upload the entire thing someplace, because I have spent days looking for the right commands I included (some silent install stuff I found at other places), and it would be helpful to have it all in 1 package I think. Saves other people some time....

I have seen many posts about similar subjects, so perhaps I should start an "Windows and Software Installation" Topic and have a collective go at all the nasty bits one encounters, and at the end have a nice set of scripts, that anyone can use the get their installations done.

About the floppy install, there is no other way if you want to use the WINNT.SIF file that I know about. Using that method implies you have turned off floppy boot in the BIOS in the first place. Additionally, I think floppy boot is one of the things that should be turned off anyway, they can contain nasty boot secor viruses and stuff yechh! (If you desperately need to, you can enable it again)

Thanks for the compliments!!! I like getting them :whistle:

About the line continuation, you are right, it is from the cut and paste, and should be on 1 line.

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...