Userprofile with #NoEnv Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
samuelsaari
Posts: 17
Joined: 08 Nov 2017, 07:32

Userprofile with #NoEnv

28 Oct 2021, 07:47

I am trying to run a program with the #NoEnv setting. How to make it work with userprofile?

Code: Select all

#NoEnv 
test1(TARGET_1)
{
MsgBox, % UserProfile . TARGET_1
Return
}

test2(TARGET_1)
{
Run, % UserProfile . TARGET_1
Return
}

^!n::test1("\This\Is\My\Path\Program.exe")
^!m::test2("\AppData\Local\Programs\Microsoft VS Code\Code.exe")
The above works if the #NoEnv is commented out. How to make it work with it? Below is that I have tried:

Code: Select all

#NoEnv not UserProfile 
UserProfile := A_UserProfile
EnvGet, UserProfile, UserProfile
UserProfile = C:\Users\%A_UserName% ; altough this would be suboptimal
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Userprofile with #NoEnv  Topic is solved

28 Oct 2021, 08:00

Variables inside functions are local by default.

Code: Select all

#NoEnv
Global UserProfile
EnvGet, UserProfile, UserProfile
test1("\This\Is\My\Path\Program.exe")

test1(TARGET_1)
{
 MsgBox, % UserProfile . TARGET_1
}
Explained: Local
samuelsaari
Posts: 17
Joined: 08 Nov 2017, 07:32

Re: Userprofile with #NoEnv

28 Oct 2021, 08:16

Appreciated, I do not know what I would do with my scripts without you. Thank you once again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doanmvu, Google [Bot], mikeyww and 276 guests