Page 1 of 1

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

Posted: 16 Oct 2019, 10:41
by ceyhunveysel
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

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

Posted: 16 Oct 2019, 11:19
by TheDewd
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

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

Posted: 16 Oct 2019, 11:39
by boiler
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.

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

Posted: 18 Oct 2019, 03:17
by ceyhunveysel
modern questions for modern solutions :dance:
thanks people!!
have a good day

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

Posted: 18 Oct 2019, 03:22
by ceyhunveysel
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!

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

Posted: 18 Oct 2019, 07:08
by boiler
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.