Jump to content

autoIt set cdrom


maniaq

Recommended Posts

how could i make something like @CDrom??

for egzample:

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

how could i cange the C:\ into cdrom

Edited by maniaq
Link to comment
Share on other sites


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 :P . NirCMD does everything, and it does it without opening cmd.exe windows.

To make a shortcut with NirCMD, use something like

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

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

to put it in the common start menu.

Link to comment
Share on other sites

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.

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

Should work fine now.

Edited by Nologic
Link to comment
Share on other sites

@Nologic

Noticed you have Network drive in there. Your covering the bases. :D

@maniaq

Here is my simple RunOnceEx, with the _FindCD() function, that I use. It does just the CDRom, which is enough for most.

Link to comment
Share on other sites

  • 2 months later...

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:

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:

$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?

Edited by JohnS
Link to comment
Share on other sites

DriveGetDrive() returns an array. This is a quick and dirty solution to running the file on the 1st cdrom with little error checking etc.

$var = DriveGetDrive( "CDROM" )
If Not @error Then Run ($var[1] & "\testing.avi")

Link to comment
Share on other sites

Thank you very much Mhz.

I am one step closer to what I want. :thumbup

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:

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.

Edited by JohnS
Link to comment
Share on other sites

*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. ;)

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.

FindDrive.html

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.

$variable = FindCD('WIN51')

When this line is executed, it will send the WIN51 parameter to the FindCD function below.

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:

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

Link to comment
Share on other sites

Thank you MHz for your explaination.

I got the time to test it and it works exactly the way I wanted.

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.

Edited by JohnS
Link to comment
Share on other sites

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:

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:

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:

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.

Link to comment
Share on other sites

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:

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 :P would be very much appreciated.

Many thanks!

Link to comment
Share on other sites

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

_Deployment.html

_Prepare.html

_Cleanup.html

_Startup.html

For your question:

Simple a change to the previous script is to alter the _Entry function with 2 lines as shown.

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

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

Edited by MHz
Link to comment
Share on other sites

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 :)

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 :)

Link to comment
Share on other sites

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 :)

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

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:

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

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.

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...