Sign in to follow this  
Followers 0
TristanPittman

How do you refer to Microsoft environment variables in an Autoit script?

14 posts in this topic

How do you refer to Microsoft environment variables in an Autoit script?

I'm stuck. I do not understand how to use a Microsoft environment variable such as %UserProfile%, %AllUSersProfile%, %AppData%, in an Autoit script. This must be a dumb question but I'm new to Autoit and programming.

I need to close two windows opened by an installer, is this proper syntax?

WinClose ("%UserProfile%\Start Menu\Programs\open folder", "")

WinClose ("%AllUSersProfile%\Start Menu\Programs\open folder", "")

I would like to copy folders to the following location, is this proper syntax?

DirCopy ( "I:\install files", "%AllUSersProfile%\desktop", 1)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Check out the Macro Reference in the help file.

Macros for "All User" data. Most values are read from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

@AppDataCommonDir path to Application Data

@DesktopCommonDir path to Desktop

@DocumentsCommonDir path to Documents

@FavoritesCommonDir path to Favorites

@ProgramsCommonDir path to Start Menu's Programs folder

@StartMenuCommonDir path to Start Menu folder

@StartupCommonDir path to Startup folder

Macros for Current User data. Most values are read from HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion

@AppDataDir path to current user's Application Data

@DesktopDir path to current user's Desktop

@MyDocumentsDir path to My Documents target

@FavoritesDir path to current user's Favorites

@ProgramsDir path to current user's Programs (folder on Start Menu)

@StartMenuDir path to current user's Start Menu

@StartupDir current user's Startup folder

@UserProfileDir Path to current user's Profile folder.

Edited by weaponx

Share this post


Link to post
Share on other sites

There are AutoIt Macros that cover what you are wanting.

@StartMenuCommonDir - path to Start Menu folder

@StartMenuDir - path to current user's Start Menu

@DesktopCommonDir - path to Desktop

Share this post


Link to post
Share on other sites

Furthermore, there is EnvGet() to retrieve actual environment variables for when you need something that is not covered by the AutoIt macros.

Also: you can just close a window by doing WinClose() with the title of the window (or with a part of it). Your approach might be the long way around.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

I am trying to do the same thing by switching from a batch file to autoit. i would like to convert the following batch file

If Exist "%USERPROFILE%\office 2007" GOTO END

MD "%USERPROFILE%\office 2007"

:end

I used this

If Not FileExists("%USERPROFILE%\office 2007") Then

DirCreate("%USERPROFILE%\office 2007")

EndIf

It will not create the directory if it does not exist. How do I use @UserProfileDir to fix this?

Share this post


Link to post
Share on other sites

the syntax would be

If Not FileExists(@UserProfileDir & "\office 2007") Then
DirCreate(@UserProfileDir & "\office 2007")
EndIf

Share this post


Link to post
Share on other sites

Damn you toaster....you popped up your eviler head before I could finish my post!!

*shakes fist*


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Yet another zombie thread. The only way to stop it now is by removing the head or destroying the brain.

Share this post


Link to post
Share on other sites

Thanks a lot. It works great.

Is there anywhere else to learn about how to use some of these autoit commands? Due to the fact that the help file is really vague.

Share this post


Link to post
Share on other sites

I think the help file is quite comprehensive. It is the only means of reference other than this forum if thats what you're asking.

We are still waiting on AutoIt: For Dummies! to show up at Staples but meanwhile you can look into AutoIt 1-2-3:

http://www.autoitscript.com/forum/index.php?showtopic=21048#

Share this post


Link to post
Share on other sites

Thanks a lot. It works great.

Is there anywhere else to learn about how to use some of these autoit commands? Due to the fact that the help file is really vague.

Vague? You've got to be kidding. <_< Every function has an example, it's all indexed, and there's a perfectly good search.

Share this post


Link to post
Share on other sites

There is a lot of examples on most of the topics. But for the last search with @UserProfileDir it showed nothing for an example. I do not like coming in here asking for help all of the time. It makes me feel that the questions that I am asking are so simple to figure out but I just can't do it. I just don't like waisting your time for these simple answers.

Share this post


Link to post
Share on other sites

what part of

Macros for Current User data. Most values are read from HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion

@AppDataDir path to current user's Application Data

@DesktopDir path to current user's Desktop

@MyDocumentsDir path to My Documents target

@FavoritesDir path to current user's Favorites

@ProgramsDir path to current user's Programs (folder on Start Menu)

@StartMenuDir path to current user's Start Menu

@StartupDir current user's Startup folder

@UserProfileDir Path to current user's Profile folder.

Don't you understand? It's in clear english!


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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