Jump to content
Sign in to follow this  

Using Variables like in DOS

Recommended Posts


Maybe a stupid question but i how can you use simple commands like "copy C:\Documents and Settings\%username% C:\Backup" for an example?

Does it needs an extra character or am i missing something?


Because i want to make a script for copying the most common things and keep the script AutoIT only.

I can do it by running a batch script from AutoIT script, but this is not a nice solution.

The variables from the SET command in DOS prompt is the list wich i would like to use in AutoIT

Edited by Iznogoud

Share this post

Link to post
Share on other sites

you could do

Run(@ComSpec & " /c " & 'copy C:\Documents and Settings\%username% C:\Backup', "", @SW_HIDE)

as well

you can do every doscommand in the ' '

I hoped this one would get passed here ;)

This is just the one i tried in different ways, but with the ComSpec line you can't use %username% or %temp% etc. I will try the other right away o:)

And yes i have looked at the help file, but you need to know where to look for.

Now i do :lmao: "Macro Reference"

Edited by Iznogoud

Share this post

Link to post
Share on other sites

Using DOS commands with @COMSPEC can provide some very handy shortcuts (especially when it comes to recursion, but that's another topic ;) ) ..

TIP: first get the syntax right by trying it out at the command prompt.

When I tried out what you're doing, at my own command prompt, I got an error message saying "The system cannot find the file specified" - whether I was using a copy or dir command. However, using cd on the same path specification worked fine...

dir C:\Documents and Settings\%username%   <-- fails
dir C:\Documents and Settings\Trids     <-- fails
cd C:\Documents and Settings\%username% <-- works
cd C:\Documents and Settings\Trids       <-- works

.. which suggests where the "problem" lies: that dir and copy evidently won't let you hack into the C:\Documents and Settings\ folders, while cd behaves as expected (subject to your Windows access rights).

Bottom line .. don't be discouraged from using DOS commands with AU3, just be sure to confirm expected results at the DOS prompt while you're coding, so that you can make informed decisions.



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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.