Trying to get the username of the person that opened the file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ceyhunveysel
Posts: 52
Joined: 02 Aug 2019, 15:39

Trying to get the username of the person that opened the file

16 Oct 2019, 10:41

Hellow.
So here, ive been trying to solve this for weeks.
I need to put a file into the startup by using a FileAppend command with full path.
But the path needs the username.
Before posting, 'yOu nEeD tO uSe %uSeRnAmE%', it doesn't work, already tried.
My username is listed as Ceyhun Veysel when i do it. But my actual username is Toshiba. So, plz tell me how to list Toshiba instead of Ceyhun Veysel when i use %Username%.
Thx.

heres da code:

Code: Select all

FileAppend, something, File.txt
FileAppend, ; warning: this is in batch langague
(
move File.txt C:\Users\%Username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
), mover.cmd
run, mover.cmd
sleep 600
filedelete, mover.cmd
ExitApp
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Trying to get the username of the person that opened the file  Topic is solved

16 Oct 2019, 11:19

Use the variable A_Startup

A_Startup

The full path and name of the Startup folder in the current user's Start Menu. For example: C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Code: Select all

#SingleInstance, Force
MsgBox, % A_Startup

RegExMatch(A_Startup, ":\\Users\\(.*?)\\", Username)
MsgBox, % Username
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Trying to get the username of the person that opened the file

16 Oct 2019, 11:39

Is there a reason you are creating a temporary batch file to move the file instead of using the FileMove command like this?

Code: Select all

FileAppend, something, File.txt
FileMove, File.txt, % A_Startup
Perhaps this is just a small example script to isolate the issue you're having, and you have another reason why you need to use a batch file, but just want to make sure.
ceyhunveysel
Posts: 52
Joined: 02 Aug 2019, 15:39

Re: Trying to get the username of the person that opened the file

18 Oct 2019, 03:17

modern questions for modern solutions :dance:
thanks people!!
have a good day
signature C:
ceyhunveysel
Posts: 52
Joined: 02 Aug 2019, 15:39

Re: Trying to get the username of the person that opened the file

18 Oct 2019, 03:22

btw boiler, why i used a batch script was beacuse when i tried to move it with the command FileMove, it didnt work, it just gave errorlevel so i had a patch of just rather using batch
thx!
Last edited by ceyhunveysel on 02 Mar 2020, 11:01, edited 1 time in total.
signature C:
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Trying to get the username of the person that opened the file

18 Oct 2019, 07:08

ceyhunveysel wrote:
18 Oct 2019, 03:22
btw boiler, why i used a batch script was beacuse when i tried to move it with the command FileMove, it didnt work, it just gave errorlevel so i had a patch of just rather using batch
The ErrorLevel result was because it couldn't find your startup folder. Using the batch file didn't address the problem (as you saw) because it also didn't work until you used A_Startup. So you can use FileMove and simplify your code a lot.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: scriptor2016 and 310 guests