Help - Search - Members - Calendar
Full Version: autoIt set cdrom
MSFN Forums > Unattended Windows Discussion & Support > Application Installs

   
Google Internet Forums Unattended CD/DVD Guide
maniaq
how could i make something like @CDrom??

for egzample:

CODE
FileCopy("C:\soft\copy\Nero Burning ROM.lnk", @DesktopDir & "\")


how could i cange the C:\ into cdrom
Achdine
I'm a very limited AutoIt user (I prefer other methods) so I can't help you with making variables, but I can tell you that it's much easier to create a shortcut that to copy it over. You can use Shortcut.exe, which is designed solely for creating shortcuts, or NirCMD, which is almost TOO sexy tongue.gif . NirCMD does everything, and it does it without opening cmd.exe windows.

To make a shortcut with NirCMD, use something like
CODE
NirCMD shortcut "%ProgramFiles%\Ahead\Nero\Nero.exe" "~$folder.common_desktop$\Programs" "Nero Burning ROM"

to put a shortcut on the common desktop,

or something like
CODE
NirCMD shortcut "%ProgramFiles%\Ahead\Nero\Nero.exe" "~$folder.common_start_menu$\Programs" "Nero Burning ROM"

to put it in the common start menu.
Nologic
Well if its just to move a shortcut...why not just use "FileCreateShortcut" to create a shortcut.

That said there are a number of ways to go about it. If you already know how to find the CD via batch scripts, then you can use a batch to execute an autoit script on the cd next to what files you are looking to copy, move, install,.... by simply using the macro @ScriptDir which is the pathing info based on where the script is.

So if your CD is D:\ and your script is in a folder called foo then @ScriptDir would = D:\foo

That said I use the following code which is a mesh of code written by my self and Mhz...mostly Mhz's work tho.

CODE
Func _FindDrive($type, $name)
  Local $drvs
  While Not $Drive
     $drvs = DriveGetDrive($type)
     If Not @error Then
        For $i = 1 To $drvs[0]
           If DriveStatus($drvs[$i] & "\") = "READY" Then
              If FileExists($drvs[$i] & "\" & $name) Or DriveGetLabel($drvs[$i]) = $name Then
                 $Drive = $drvs[$i] & "\"
                 Return $Drive
              EndIf
           EndIf
        Next
        If Not $Drive Then
           If StringInStr("CDROM|REMOVABLE|NETWORK", $type) Then
              If StringInStr("CDROM|REMOVABLE", $type) Then
                 If MsgBox(21, "Warning", "Please insert media into a drive now") = 2
                    Sleep(1000)
                    If MsgBox(36, 'Important', 'Are you sure that you want to exit?') = 6 Then Exit
              ElseIf $type = "NETWORK" Then
                 If MsgBox(21, "Warning", "Please connect to a network now") = 2 Then
                    Sleep(1000)
                    If MsgBox(36, 'Important', 'Are you sure that you want to exit?') = 6 Then Exit
                 EndIf
              EndIf
           Else
              If MsgBox(36, 'Drive Not Found', 'Drive could not be found would you like to exit?') = 6 Then Exit
           EndIf
           Sleep(2000)
        EndIf
     EndIf
  WEnd
EndFunc


You'll have to look up DriveGetDrive to get all the options that can be used for the $type values that can be passed to it.

$name is passed to the function so that has a one of a kind file to look for example "win51" thats normally on all unattended install cd's. Your not limited to only the file name...you can pass path information along with the file name...but a file name is expected.

Any ways you can see it put to use in my autoit replacement for RunOnce that is attached.

*Update*
Mhz did some code clean up on the _FindDrive function as can be seen above. I made $Drive global, and fixed the #include issue. newwink.gif

Should work fine now.
MHz
@Nologic
Noticed you have Network drive in there. Your covering the bases. biggrin.gif

@maniaq
Here is my simple RunOnceEx, with the _FindCD() function, that I use. It does just the CDRom, which is enough for most.
Nologic
Heh just a few extra lines of code...never know might actually use that feature some day. smile.gif
JohnS
Hi,
I have searched this forum and read:
Autoit Cdrom Variable?
AutoIT Guide
multiple cd drives and autoit
Also searched Autoit forum
cdrom drive letter as variable, run autoit3.exe from cdrom
and still can't execute an Autoit script that is in the hard drive and run this command:
CODE
Run ("d:\testing.avi")

or something like that, d: being the cd-rom.
What I want is to have the Autoit script in %systemdrive\install and have it run any file located in the cdrom.
Do I have to have all that code from Nologic to do that? But it doesn't work on my Autoit, because it given me many errors.
I have tried this but it also does not work:
CODE
$var = DriveGetDrive( "CDROM" )
Run ($var & "testing.avi", )

I know nothing of programing, but I managed until now to use this Autoit macros: @HomeDrive, @ProgramsDir, etc, but I cannot achieve to do the same thing with a cdrom. Something like Maniaq asked in the first post.
Can someone help, please?
MHz
DriveGetDrive() returns an array. This is a quick and dirty solution to running the file on the 1st cdrom with little error checking etc.
CODE
$var = DriveGetDrive( "CDROM" )
If Not @error Then Run ($var[1] & "\testing.avi")
JohnS
Thank you very much Mhz.
I am one step closer to what I want. thumbup.gif
Now the last little bit.
If I have more than one CD-rom it seems that the right way of doing things is, as it is done with RunOnceEx from CD method, to search for a match title or little file in the cd, then define that letter as the cd letter, then run the file.
In another post I found the RunOnceEx from CD method applied with Autoit:
CODE
AutoItSetOption ( "ExpandEnvStrings", 1 )
RunWait(@ComSpec & " /c for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%i:\WIN51 set CDROM=%%i:", "", @SW_HIDE)

This method does not seem to be good
So, how is it done by a simple way?
I have never found it clearly explained. At least I didn't understand it.
(I could not test yours and Nologic code posted above in this thread because of errors so could not figure what it does and learn from it).
Again, thank you for your time.
MHz
QUOTE (Nologic @ Jun 17 2005, 04:45 AM)
*Update*
Mhz did some code clean up on the _FindDrive function as can be seen above. I made $Drive global, and fixed the #include issue. newwink.gif

Should work fine now.
*

Nologic,
You should not make $Drive global. It is only used within the function locally. Everything is done within the function, which simply returns the drive letter. #include only required to include an additional script to the main script. Have attached the version that I have.
Click to view attachment

JohnS,
The code that you show will Not work as @ComSpec will not return any value back to the script for use.
I believe that your error is not knowing how to call a user function? Without showing the problem, then a resolve is not possible.
I will post a simple version for you. If you want help, then please post enough information, that may allow for a correct answer to be given.

This is a line of code to use at the top of your script to retrieve the drive letter by calling the FindCD function.
CODE
$variable = FindCD('WIN51')


When this line is executed, it will send the WIN51 parameter to the FindCD function below.
CODE
Func FindCD($filename)
   $cdrom = DriveGetDrive('CDROM')
   If Not @error Then
       For $i = 1 To $cdrom[0]
           If FileExists($cdrom[$i] & '\' & $filename) Then Return $cdrom[$i]
       Next
   EndIf
EndFunc

The FindCD function can be inserted at the bottom of your script, out of the way.



What a script could look like:
CODE
$CD1 = FindCD('WIN51')
$CD2 = FindCD('Software')

Run($CD1 & '\I386\Winnt32.exe')
Run($CD2 & '\Software\Setup.exe')


Func FindCD($name)
   $cdrom = DriveGetDrive('CDROM')
   If Not @error Then
       For $i = 1 To $cdrom[0]
           If FileExists($cdrom[$i] & '\' & $name) Then Return $cdrom[$i]
       Next
   EndIf
EndFunc

In this example, $CD1 stores the cdrom letter of the drive that has WIN51 in it and $CD2 stores the cdrom letter of the drive with Software in it.
Just ask if you cannot understand anything shown.
JohnS
Thank you MHz for your explaination.
I got the time to test it and it works exactly the way I wanted.
QUOTE
I believe that your error is not knowing how to call a user function? Without showing the problem, then a resolve is not possible.

Yes, my problem is that Autoit is a new language that I have to learn from the begining.
I more or less understood your script, but could never reproduce it.
It is as if I had two years of english and you gave me an Oxford book to read: I can read but cannot realy understand.
For example:
1- If you have a function that looks for a certain file in the CD - $variable = FindCD('WIN51') - why do you need the DriveGetDrive function to detect the CDrom?
2- Why doesn't the function FindCD appears in the Autoit Help file?
3- Why is a third variable - $i - needed?
4- What exactly does this line do: For $i = 1 To $cdrom[0]?
More:
- When I use the Run function, it seems that it just can run .exe files, not other type of files?
Please, if you see that all this is very advanced don't waist your time with me. I am already thankfull for what you did.
MHz
1- If you have a function that looks for a certain file in the CD - $variable = FindCD('WIN51') - why do you need the DriveGetDrive function to detect the CDrom?
The DriveGetDrive is a builtin function in AutoIt for locating drives. It is far easier to use DriveGetDrive rather then reproducing with it with numerous lines of code. DriveGetDrive returns an array of drives available, but some further lines of code is required to refine a match that suits our needs. This explains for the function FindCD.

2- Why doesn't the function FindCD appears in the Autoit Help file?
FindCD is a User Defined Function. It exists through my creation. AutoIt users can create their own User Defined Functions and use them similar to builtin functions. For example, let us say that a script may require lots of basic MessageBox functions, but using the builtin MessageBox has too many parameters for a simple task. I could make a User Defined Function (UDF) as below:
CODE
Func Message($text)
   MsgBox(0, '', $text)
EndFunc

Now I place the above UDF at the bottom of the script and call the function as below:
CODE
Message('This is easier')

The above single line will execute the Message function. $text parameter will be replace with the string 'This is easier'. Imagine that this is what the function looks like when called:
CODE
Func Message('This is easier')
   MsgBox(0, '', 'This is easier') ;<-- This will popup a MessageBox. $text is replaced with the string.
EndFunc


3- Why is a third variable - $i - needed?
$i is a variable used for storing the loop count for the For Next loop. It is self declared and a required variable for For Next loops.

4- What exactly does this line do: For $i = 1 To $cdrom[0]?
A For Next loop will continue to loop through the code between the For and the Next keywords. $i stores the loop count. 1 is the start number for the loop count. $cdrom[0] stores the amount of drive letters that the DriveGetDrive function returned. If DriveGetDrive returned 2 CDRoms, then $cdrom[0] = 2. The For Next loop would loop twice. The first loop would replace $cdrom[$i] with $cdrom[1], which is the 1st CDRom letter and checks if the FileExists and return the CDRom letter if true. If false, then the 2nd loop will happen and $cdrom[$i] is replaced with $cdrom[2], which is the 2nd CDRom letter and checks if the FileExists and return the CDRom letter if true.

5- When I use the Run function, it seems that it just can run .exe files, not other type of files?
Straight out of the helpfile. The full name of the executable (EXE, BAT, COM, or PIF) to run. This is a simple indicator. DLLs and others can also be included as files to run etc.
Mekrel
Hi Mhz and thanks for the wealth of info in this thread,

I was looking for a script to install applications via RunOnceEx like you have posted, however your script seems limited in one small way.

Sometimes with my install, each application has two steps to it, such as an example installing the program and then running a SFX archive to replace config files etc..

such as in this example:
CODE
REG ADD %KEY%\060 /VE /D "SmartFTP + Settings" /f
REG ADD %KEY%\060 /V 1 /D "%CDROM%\Apps\SmartFTP\SFTPNSI.exe /S" /f
REG ADD %KEY%\060 /V 2 /D "%CDROM%\Apps\SmartFTP\Settings.exe" /f


with your script it appears to not be able to add more than one step and probably because you SFX all your applications into switchless ones?

Im pretty handy enough to use AutoIT (although no where near as good as nologic and yourself) but cant see how to modify the script to add support for two step applications.

Any info/help especially an updated script tongue.gif would be very much appreciated.

Many thanks!
MHz
Arh, my old RunOnceEx script that the link shows. Those are all compiled scripts that RunOnceEx executes, so limitation is only the amount of code that I have within the compiled scripts. This would compare to your 2 commands as a enormous difference in function, as my scripts can have can have almost unlimited functions.
Currently I install everything from Cmdlines.txt. AutoIt3.exe runs the master Au3 script, which adds paths, environment variables and services. The master script then executes a cleanup Au3 script. It then searches a software folder for Au3 scripts which AutoIt3.exe executes each in order. Logs software installation times and exitcodes while installing. The scripts will access support files whilst executing. Most software scripts are CMenu created scripts and a few are Gui driven. All this is done while a fullscreen picture on a AlwaysOnTop Gui is displayed showing the software list scrolling through as installs are working and a progress bar display. The Gui can be toggled from AlwaysOnTop setting by pressing the spacebar, incase an installation stalls. A startup Au3 script is then copied to the windows directory and the execution line is added to the HKCU RunOnce key for Desktop cleanup and shortcut removal etc. The master Au3 script can also run from RunOnceEx and resize the Gui to suit the resolution. This setup has 0 compiled AutoIt scripts which saves space and is easy to edit the scripts when needed.
Display of working script
Click to view attachment
Click to view attachment
Click to view attachment
Click to view attachment
For your question:
Simple a change to the previous script is to alter the _Entry function with 2 lines as shown.
CODE
Func _Entry($title, $file1, $file2 = '', $file3 = '')
   $count = $count + 1
   RegWrite($key & '\' & $count, '', 'Reg_sz', $title)
   RegWrite($key & '\' & $count, '1', 'Reg_sz', $file1)
   If $file2 <> '' Then RegWrite($key & '\' & $count, '2', 'Reg_sz', $file2)
   If $file3 <> '' Then RegWrite($key & '\' & $count, '3', 'Reg_sz', $file3)
EndFunc

Then call the function like this
CODE
_Entry('SmartFTP + Settings', $software & '\SmartFTP\SFTPNSI.exe /S', $software & 'SmartFTP\Settings.exe')

The above modification allows for 2 extra optional parameters, so you can call 2 more items to execute under the 'SmartFTP + Settings' title.
There is no set concept with unattended AutoIt scripts, just good imagination to make them.

Edit: Added attachments: _Prepare.html, _Cleanup.html and _Startup.html.
Mekrel
Many thanks,

Im real liking your master script idea, sounds very clever and easy to customise as when you change one of the children scripts, then the master script doesnt have to be changed to execute it smile.gif

I just wondered if I could have your input on something Mhz,

I want to convert all of my CMD scripts into au3 scripts so they dont popup (cmdown.exe still pops up a window and other wrappers that try to hide the console fail).

I did have a plan, which was to write the commands to be ran as uaul but to store them in a text file, and then for a au3 script to read it and pass each line into a Run function which called

@Comspec & "/c" & "command here"

but command here was obviously a variable which was read from each line and obviously done with a loop untill the end of the file was reached, but unfortunatly this spawned alot of windows as each time the run function was called = another instance of cmd.exe being made.

So I thought I would use _RunDos but I kept getting some kind of error.

Any ideas on to make a au3 script which will cleanly and silently run a cmd script?

Cheers for the help so far smile.gif
MHz
QUOTE (Mekrel @ Sep 26 2005, 08:20 AM)
Im real liking your master script idea, sounds very clever and easy to customise as when you change one of the children scripts, then the master script doesnt have to be changed to execute it smile.gif
*

Thanks, it is easy. Just add the installer and Au3 script to the Software folder and it is done. No list to update.

QUOTE (Mekrel @ Sep 26 2005, 08:20 AM)
I want to convert all of my CMD scripts into au3 scripts so they dont popup (cmdown.exe still pops up a window and other wrappers that try to hide the console fail).
*

Identify Installer in CMenu is recommended. It is quick.
If you want to do the same as my method then:
Add the master script in root $OEM$ named _Deployment.au3.
Create a folder in root of $OEM$ named Software.
Add installers and CMenu scripts in $OEM$\Software
I use the Winntbbu.dll picture added to $OEM$ root.
Create Au3 files named _Prepare.au3, _Cleanup.au3 and _Startup.au3.
Add AutoIt3.exe from latest Beta to $OEM$ root.
Add Regtweaks.reg to $OEM$ root.
Create Cmdline.txt and add this inside it:
CODE
[COMMANDS]
"AutoIt3.exe _Deployment.au3"
"RegEdit /s RegTweaks.reg"

Done. This runs from Cmdlines.txt. A small script can make it run from RunOnceEx instead.

QUOTE (Mekrel @ Sep 26 2005, 08:20 AM)
I did have a plan, which was to write the commands to be ran as uaul but to store them in a text file, and then for a au3 script to read it and pass each line into a Run function which called

@Comspec & "/c" & "command here"

but command here was obviously a variable which was read from each line and obviously done with a loop untill the end of the file was reached, but unfortunatly this spawned alot of windows as each time the run function was called = another instance of cmd.exe being made.

So I thought I would use _RunDos but I kept getting some kind of error.

Any ideas on to make a au3 script which will cleanly and silently run a cmd script?
*

A text file of commands is a harder method to setup and maintain. Here are some silent samples but instead of using Run, you will need to use RunWait instead.
CODE
$cmdfile = 'test.cmd'

; Sample 1
RunWait($cmdfile, '', @SW_HIDE)

; Sample 2
RunWait(@ComSpec & ' /c Call "' & $cmdfile & '"', '', @SW_HIDE)

This would spawn lots of hidden cmd windows, but not all at once.

If you are handy enough with AutoIt, then you should not need a single cmd script in your whole project. Cmd windows are not a problem when using solely AutoIt.
webmedic
Hello Mhz thanks for all you good code. I also do a few things in autoit and am getting ready release something if all goes well.

However for now I'm using a network and I have from the command lines text a single batch file that sets up my network and starts my installer scripts that are on a network share. This saves me allot of space on my cdrom that can be better used for whatever I see fit.

The thing is that I'm currently using xplode and it works great Iahve no issues there and it is network transparent. I want to now use auto it for this and I also want to use autoit for scripting some installers to make them silent.

My main issue here is that I have tried to use the macro recorder that comes with scite for auto it and I'm not really happy with what it produces. I also have to admit that I'm using auto it for gui purposes and not to automate things so I'm not really to good at that part of it.

Could you explain in a simple step by step how you make your installer scripts and also possibly share some more of your au3 scripts for cleanup and also for the runonce stuff after you boot into the os. If you don't want to I understand that ok but i thought I would ask anyway.

Oh and my project. It's called buster and you can think of it more as a system cleaner / virus / malware / spyware scanner with definition files that anybody can write. They are completely open. Hopefully soon I will have it out I just need to finish the code for reading the def files and change the back end to execute the commands in the proper order.
MHz
QUOTE (webmedic @ Oct 4 2005, 02:30 AM)
The thing is that I'm currently using xplode and it works great  Iahve no issues there and it is network transparent. I want to now use auto it for this and I also want to use autoit for scripting some installers to make them silent.
*

If you want to use AutoIt to make some silent installs, then use CMenu. Identify Installer within CMenu can create template AutoIt scripts for you. It will make it easy for you.

QUOTE (webmedic @ Oct 4 2005, 02:30 AM)
My main issue here is that I have tried to use the macro recorder that comes with scite for auto it and I'm not really happy with what it produces. I also have to admit that I'm using auto it for gui purposes and not to automate things so I'm not really to good at that part of it.
*

AutoMacroGenerator is rough but quick at creating an automated script. It is fine if you are not concerned for it's output. Checking and editing can be a post operation.

QUOTE (webmedic @ Oct 4 2005, 02:30 AM)
Could you explain in a simple step by step how you make your installer scripts and also possibly share some more of your au3 scripts for cleanup and also for the runonce stuff after you boot into the os. If you don't want to I understand that ok but i thought I would ask anyway.
*

Post #13 has some scripts added if you want a look. The prepare, cleanup and startup scripts are mostly custom to my needs, but you may see something to learn from.
Are you refering to silent install scripts or automated scripts? There is a WinZip tutorial in the AutoIt helpfile. The automated example uses WinWaitActive and Send. WinWait and ControlClicks are more reliable to use if possible. Always use the Au3Info tool to supply you the information for using the function parameters. Let me know what you do not understand and which type of install, whether silent or automated.
webmedic
thanks for the reply I have been extremely busy the last few weeks and have not been able to get back to this.

I have looked over your scripts do you happen to know if they work ok over the network?
MHz
Try it over a network. It may depend on your setup to what issues may arise. Running it at Cmdlines.txt means your running as system rather then an account so RunAsSet is perhaps no requirement, if it was anyway. You can only fix problems that come your way, not the ones that do not exist yet. The scripts are flexible to small changes if needed.
webmedic
sure of course I already have my setups set to run over the network from commandlines.txt so that is no issue. I currently use xplode though and seeing as how it is a paid product I'm looking at moving to other pastures.

At any rate I have been wanting to go with a atuoit based setup for a while. I'm hoping autoit maps network paths correctly during t-12 though.

Oh well I'll let you know and thanks for the help.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.