IniRead, Filename with A_Username in it

Get help with using AutoHotkey and its commands and hotkeys
TXShooter
Posts: 115
Joined: 13 Dec 2017, 09:27

IniRead, Filename with A_Username in it

23 Sep 2018, 14:36

I'm attempting to consolidate several of my scripts into a singular setup, using IniRead to fill in most of the common variables. There are many variables containing system parameters such as A_UserName in a filename.

Ini file:
[FileSection]
DefaultTemplate="C:\Users" . A_UserName . "\AppData\Roaming\blah\Blee.blu"


When I read that variable into Template and attempt to Run, %Template%, I get the error "Failed attempt to launch program or document: (and my variable is pointed to). But declaring that variable using the same variable verbatim in the .ahk script, it runs just fine.

Is it possible to do this? To read from the ini file a full path with the system variable 'A_Username' embedded, and then run that full-path file? I've looked into Format(), but couldn't get that to work.
User avatar
Datapoint
Posts: 19
Joined: 18 Mar 2018, 17:06

Re: IniRead, Filename with A_Username in it

23 Sep 2018, 14:42

Code: Select all

DefaultTemplate:="C:\Users\%A_UserName%\AppData\Roaming\blah\Blee.blu"
MsgBox % DefaultTemplate
Transform, DefaultTemplate, Deref, % DefaultTemplate
MsgBox % DefaultTemplate
TXShooter
Posts: 115
Joined: 13 Dec 2017, 09:27

Re: IniRead, Filename with A_Username in it

23 Sep 2018, 15:13

Datapoint wrote:

Code: Select all

Transform, DefaultTemplate, Deref, % DefaultTemplate
THANK YOU!!! Transform I guess that I completely missed that one in my searching.

Another question about ini file reads... I'm having trouble with this:

Code: Select all

IniRead, dPath, Consolidate.ini,Parameters,DefaultPath
Msgbox % "The default path is: " dPath
Where the ini file is set:

Code: Select all

[Parameters]
DefaultPath="D:\"
It keeps coming back as "ERROR", like it's not a valid entry or read. This isn't just a problem with "DefaultPath", but other under the Parameters section as well, and I'm not sure why. What am I doing wrong here?
A_AhkUser
Posts: 872
Joined: 06 Mar 2017, 16:18
Location: France

Re: IniRead, Filename with A_Username in it

29 Sep 2018, 14:21

Datapoint wrote:

Code: Select all

DefaultTemplate:="C:\Users\%A_UserName%\AppData\Roaming\blah\Blee.blu"
MsgBox % DefaultTemplate
Transform, DefaultTemplate, Deref, % DefaultTemplate
MsgBox % DefaultTemplate
I didn't know a sub-command such as deref existed... Its actually very usefull. Thanks for sharing ;)
[url=https://autohotkey.com/boards/viewtopic.php?f=56&p=215673#p215673][b][font=Segoe UI][color=#1ea2db]Video Game[/color] [color=#bbbbbb]Reader[/color][/font][/b][/url] eAutocomplete


Return to “Ask For Help”

Who is online

Users browsing this forum: cjessamy, Tigerlily and 25 guests