Sign in to follow this  
Followers 0
malong

Script does not work correct when launch from Cr-rom

10 posts in this topic

Hello,

First of all sorry for my English.

im newbie in autoit, this is my first script.

So, i have a problem when try to running autoit script from CD-rom (Script placed on CD)

My script works in next order:

1) copy config files from cd to hard disk,

2) finding driveletter my cd rom

3) change config files (adding path with founded drive letter)

4) and run my programs etc

Problem is my config files don't change when i run script from cd. But when i run it from hard disk all works fine.

Bellow part of my script

Please help me, how i can resolve this problem.

Thanks

DirCopy(@ScriptDir&"\data\settings\", "C:\data\settings\",1)
DirCopy(@ScriptDir&"\data\language", "C:\data\language",1)
FileCopy(@ScriptDir&"\data\.VirtualBox\VirtualBox.xml", "C:\data\.VirtualBox\", 9)
FileCopy(@ScriptDir&"\data\.VirtualBox\Machines\test\test.vbox", "C:\data\.VirtualBox\Machines\test\", 9)
Global $myPath = "C:\data\.VirtualBox\Machines\test\test.vbox"
Global $cdDrive = DriveGetDrive("CDROM")
for $i=1 to $cdDrive[0]
If FileExists($cdDrive[$i]&"\LiesMich.txt") then
  $driveLetter=$cdDrive[$i]
  endif
  Next
Global $oldtext = "test.vdi"
Global $newtext = $driveLetter&"data\.VirtualBox\Machines\test\test.vdi"
Global $oldCDPath = "D:/Distrib/ISO/ess-linux-0.1-rc8.iso"
Global $newCDPath = $driveLetter&"data\.VirtualBox\Machines\test\ess-linux-0.1-rc8.iso"
$myFile=FileOpen($MyPath, 0)
$myText=FileRead($myFile)
FileClose($myFile)
$myText=StringReplace($myText, $oldtext, $newtext)
$myText=StringReplace($myText, $oldCDPath, $newCDPath)
$myFile=FileOpen($MyPath, 2)
$myText=FileWrite($myFile,$myText)
FileClose($myFile)

Share this post


Link to post
Share on other sites



MsgBox(0, '?', $myText)

Do check the variables to understand. Use the virtual CD-ROM drive.

Share this post


Link to post
Share on other sites

Why do this part?

Global $cdDrive = DriveGetDrive("CDROM")

If your script is on the CD, and is in the root, then @ScriptDir will give you the CD drive's letter.

Share this post


Link to post
Share on other sites

i used @scriptDir in first editions, but script didn't work, then i tryed use driveGetDrive functions, but result was the same.

I also tryed to run script from root directory and in subdirectories on CD.

Share this post


Link to post
Share on other sites

Global $myPath = "C:data.VirtualBoxMachinestesttest.vbox"
; snip
$myFile=FileOpen($MyPath, 0)

$myPath <> $MyPath

Does it matter that one is lowercase and the other is capital?

Share this post


Link to post
Share on other sites

There's no case sensitivity for variable names in AutoIt. $mypath = $mYpAtH as far as AutoIt is concerned.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

These lines are incorrect:

Global $newtext = $driveLetter & "data\.VirtualBox\Machines\test\test.vdi"
Global $newCDPath = $driveLetter & "data\.VirtualBox\Machines\test\ess-linux-0.1-rc8.iso"

You need the backslash before the word data.

Global $newtext = $driveLetter & "\data\.VirtualBox\Machines\test\test.vdi"
Global $newCDPath = $driveLetter & "\data\.VirtualBox\Machines\test\ess-linux-0.1-rc8.iso"

From the Help file for DriveGetDrive

Success: Returns an array of strings (drive letter followed by colon) of drives found. The zeroth array element contains the number of drives.

Because it only returns the drive letter and a colon (D:), you need to add the backslash to the path statements.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You need the backslash before the word data.

Added backslash as you advised me, but result was same with/without backslash script wokred properly if i run it from hard disk drive or usb flash drive (CD path added to $myPath), but if i run it from cd, files just copied and didn't changed

Share this post


Link to post
Share on other sites

Check the file copied to make sure it isn't being copied with the Read Only setting set, which sometimes happens when copying from a CD to a HDD


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Check the file copied to make sure it isn't being copied with the Read Only setting set, which sometimes happens when copying from a CD to a HDD

It works! Thanks, after removing attribute "read only" with FileSetAttrib function, script works correct.

Thank you.

Edited by malong

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