Jump to content
Sign in to follow this  
microbious

Noob question

Recommended Posts

microbious

I am good at CMD scripting and i have just now started to learn autoit.

With cmd, i could copy files using commands like

mkdir foldername
copy "%windiwr%\filename.exe" "foldername"/Y

where mkdir will create folder inside working directory. /Y is to overwrite without asking

and copy will copy filename.exe from "C:\windows" folder into newly created foldername.

At this point i dont understand how to use FileCopy command with autoit

I tried

DirCreate("saved")
FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved" [, flag] )

but its not working. It will create folder it curent location where executable was executed from but will not copy anything into it.

I guess i dont understand the use of "Environmental Variables" use in autoit

Anyone can point me to the right direction ? I have never worked with scripting languages before and all i know is CMD.

Thanks in advance.

Edited by stoopid

Share this post


Link to post
Share on other sites
WideBoyDixon

Take a look at EnvGet() to retrieve the value of environment variables. There are also some pre-built macros such as @SystemDir which you may be able to use.

Also, don't include parameter names in the function calls (i.e. your "[, flag]" is superfluous).

WBD

Edited by WideBoyDixon

Share this post


Link to post
Share on other sites
Mobius

I recommend using the the Expand environment strings option::

Opt("ExpandEnvStrings",1)
;or
 AutoItSetOption("ExpandEnvStrings",1)

that should sort out the problem you had in this code::

DirCreate("saved")
  FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved")

Vlad

Ed:useless data.

Edited by Mobius

Share this post


Link to post
Share on other sites
microbious

can you guys show me 1 example how this

DirCreate("saved")

FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved")

would work ?

Thanks

ALso getting environment var is not a problem as:EnvGet("SYSTEMROOT")

Problem is how to use it.

I tried

$var = EnvGet("SYSTEMROOT")
MsgBox(4096, "Path variable is:", $var)

and i get message C:\Windows

But how do i use this value to copy files from there ?

Example would be great.

Thanks in advance

Edited by stoopid

Share this post


Link to post
Share on other sites
ChrisFromBoston

This example should set you in the right direction:

DirCreate("c:\myFolder")
FileCopy(EnvGet("SYSTEMROOT") & "\explorer.exe", "c:\myFolder")

It will create c:\myFolder and then will copy explorer from SYSTEMROOT.

Share this post


Link to post
Share on other sites
microbious

DirCreate("saved")

FileCopy(EnvGet("SYSTEMROOT") & "system32\drivers\UnlockerDriver5.sys", "saved")

doesn't work ^_^

folder created in working directory as i expected, but file from system32 folder will not copy unless i enter direct path instead of ENV variable

Share this post


Link to post
Share on other sites
Mobius

DirCreate("saved")

FileCopy(EnvGet("SYSTEMROOT") & "system32\drivers\UnlockerDriver5.sys", "saved")

doesn't work ^_^

folder created in working directory as i expected, but file from system32 folder will not copy unless i enter direct path instead of ENV variable

What is wrong with...

Opt("ExpandEnvStrings",1) ;allow the use of cmd shell %EVARS% in strings!
DirCreate(@WORKINGDIR &"\saved")
FileCopy ( "%systemroot%\system32\drivers\UnlockerDriver5.sys", @WORKINGDIR &"\saved")

;)

Ed: but to answer the quote, you forgot the "\" char

FileCopy(EnvGet("SYSTEMROOT") & "\system32\drivers\UnlockerDriver5.sys", "saved")

Edited by Mobius

Share this post


Link to post
Share on other sites
microbious

thanks it works.

Problem is that it wont work without Opt("ExpandEnvStrings",1)

I want to forget about CMD and switch to autoit and as far as i understand, Opt("ExpandEnvStrings",1) understands cmd commands.

Anyway to make this work

DirCreate("saved")

FileCopy( "%systemroot%\system32\drivers\UnlockerDriver5.sys", "saved")

without Opt("ExpandEnvStrings",1) ???????

Big thanks

Share this post


Link to post
Share on other sites
ChrisFromBoston

I don't have AutoIt on this computer, but I think the variable is @SystemRoot so it'd be:

FileCopy(@SystemRoot & \system32\drivers\UnlockerDriver5.sys", "saved")

Share this post


Link to post
Share on other sites
microbious

i get error

Error: Unterminated string.

if i do

DirCreate ("saved")

FileCopy(@SystemRoot & "system32\drivers\UnlockerDriver5.sys", "saved")

i get

Line -1:

Error: Unknown macro.

File still not copied ^_^

Share this post


Link to post
Share on other sites
microbious

OK got it ^_^

All i needed was

FileCopy(@WindowsDir & "\system32\drivers\UnlockerDriver5.sys", "saved\", 8)

I had no idea slashes could be so important ;)

Thank you all for help.

Oh and one last thing, i want to create a folder in a root of current harddrive.

How do i use DirCreate to accomplish that ?

With CMD there was %source% as environmental variable

and with autoit there is ?

Edited by stoopid

Share this post


Link to post
Share on other sites
CodyBarrett

there are a whole lot of dir macros that are VERY usefull

Share this post


Link to post
Share on other sites
microbious

yes thanks

But i found DriveGetLabel ( "path" )

But this takes me back to the top of this post,

Once program gets drivepath or environmental variable, how to i use it ?

for exaple

$var = EnvGet("WINDIR")
MsgBox(4096, "Path variable is:", $var)

tells me that windows in on C:\Windows

Next line i want to copy file from there into somewhere else.

HOW ?

is it something like this ?

EnvGet("WINDIR")

FileCopy ("here goes what ?", "place\")

confused ^_^

THanks for reply.

Edited by stoopid

Share this post


Link to post
Share on other sites
Mobius

How about::

Ed: I forgot the trailing "\" after the 'saved' directory, so it is now &"\SAVED\"

FileCopy(@SYSTEMDIR &"\drivers\UnlockerDriver5.sys",@SCRIPTDIR &"\SAVED\",9)

This would copy the target file to the chosen folder, creating the folder structure if necessary,

and overwriting any files in that path with the same name.

Ed: As for creating a folder in a drive root...

$sFname = "\NewFolder"; Remember your back slashes. no macro's end with them.
   DirCreate("C:" & $sFname)
;or
  $var = EnvGet("systemdrive")
  DirCreate($var & $sFname)

Vlad

Edited by Mobius

Share this post


Link to post
Share on other sites
Juvigy

If you have the CMD BAT file you can create CMD commands in Autoit with:

RunWait(@COMSPEC & " /c del C:\124.zip /q")

For example.

Share this post


Link to post
Share on other sites
herewasplato

Welcome to the forum.

$var = "it is just short for variable"
$anythingiwant = "yes"

$"anything i want" = "no"
$anything_i_want = "yes"
I use it so seldom that i had to look it up in the help file that comes with the version of SciTE that I mentioned above. I don't know what all comes with (or is absent from) the SciTE-Lite that is installed with AutoIt.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
microbious

let me get this straight.

RunWait(@COMSPEC & " /c del C:\124.zip /q")

RunWait(@COMSPEC & "CMD commands") right ?

its funny help files says

Remarks

To run DOS commands, try RunWait(@ComSpec & " /c " & "commandName") ; don't forget " " before "/c"

Dont forget ?

anyhow so i tried to

RunWait(@HomeDrive & "/c " & "messagebox "window title" "message")

messagebox.exe is in the same directory as built script.

All i get is error line -1 and messagebox will not give me anything.

If so, any chance that CMD will die out in future versions of windows ? LOL that would suck.

Edited by stoopid

Share this post


Link to post
Share on other sites
CodyBarrett

if it does... then you will probably just have to recode it... shouldn't take too long but i highly doubt it will get replaced

Share this post


Link to post
Share on other sites
microbious

well i tried any combination i could think of, and it just dont work.

and why this guy referring to SciTE ?

What is SciTE ? and what does it have to do with AUTOIT ?

Edited by stoopid

Share this post


Link to post
Share on other sites
CodyBarrett

ScitTE is the text editor that we use for autoit...

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  

×