AutoHotkey Permissions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AutoHotkey Permissions

02 Apr 2022, 09:07

Try this I have made to run explorer as the logged in user it may work, and i could edit it more to add the profile bit.

Code: Select all

; this will run notepad as the logged in user not as a admin.
TaskUser("outlook.exe", "C:\Program Files\Microsoft Office\root\Office16")


TaskUser(target, path="")
{
 	Title=%Target% 										
	Title:= SubStr(Title,1,InStr(Title, .)-1)
	RegRead, LastLogon, HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI, LastLoggedOnUser
	stringtrimleft,last,LastLogon,1
	RegRead, Mechine, HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName, ComputerName
	UserID = %Mechine%%last%
	RunWait, %A_WinDir%\System32\schtasks.exe /CREATE /TN %Title% /TR %Path%\%Target% /sc ONCE /RU %UserID% /st 00:00 ,,hide
	RunWait, %A_WinDir%\System32\schtasks.exe /Run /TN %Title% ,,hide
	Run, %A_WinDir%\System32\schtasks.exe /Delete /TN %Title% /f ,,hide
}
Last edited by TrebleTA on 02 Apr 2022, 17:31, edited 1 time in total.
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: AutoHotkey Permissions

02 Apr 2022, 12:11

seems you might try the RunAs command for your script to apply the correct user context. the scheduled task causes an administrative context to the script which needs to be specific to the current user
My user account name is Vlad, and the computer name is AMD. How can these names be used with the RunAs command? Is it also necessary to specify the email address and password used in Outlook?
I have tried using the following commands:

Code: Select all

runas Administrator
run "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
runas
But the following message appears:
1.png
1.png (49.3 KiB) Viewed 966 times
In picture 2 edit trigger, delay task for put 30 seconds. See if that works
I have tried delaying the execution of the task in this way, but Outlook still does not sign in.
The first part of the code is to get your command to run as a user. Just not sure if it will work. The bottom command can then be put in your script to replace the run.
Thank you for writing the script. I have tried using it, and Outlook finally signed in automatically at startup.
But since the script is long, I would like to know whether there is a short command which can achieve the same result. I always try to keep my scripts short and simple.
Is it possible to launch Command Prompt with the use of AutoHotkey and launch Outlook from within Command Prompt with the use of AutoHotkey? Perhaps there will be no permission issues.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AutoHotkey Permissions

02 Apr 2022, 17:26

Just delete the comments, but no it's as short as posable. I have removed the above comments so it's a bit cleaner. But think I would ass comments so you could tell what each part did. Also there is a updated version of my script on my thread I linked before, that you can use arguments like outlook.exe /profile.

You could remove 1 or 2 lines of where I read the reg, to get the user, and you could put your info.

I made this so I can restart explorer.exe, outlook.exe onedrive.exe etc as need to be running as a user if ahk is run as a admin etc.

Or create your own task schedule, then just use the one line that will run your task schedule.
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: AutoHotkey Permissions

03 Apr 2022, 11:02

TrebleTA wrote:
02 Apr 2022, 17:26
Just delete the comments, but no it's as short as posable. I have removed the above comments so it's a bit cleaner. But think I would ass comments so you could tell what each part did. Also there is a updated version of my script on my thread I linked before, that you can use arguments like outlook.exe /profile.

You could remove 1 or 2 lines of where I read the reg, to get the user, and you could put your info.

I made this so I can restart explorer.exe, outlook.exe onedrive.exe etc as need to be running as a user if ahk is run as a admin etc.

Or create your own task schedule, then just use the one line that will run your task schedule.
Thank you very much.
Can you also explain how to start Outlook through the Command Prompt with the use of AutoHotkey?
I have tried to execute the following command in AutoHotkey, but the specified program did not start:

Code: Select all

Run, CMD /c C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey Permissions

03 Apr 2022, 11:41

Put quotation marks around the path. You can also use %ComSpec% instead of CMD to ensure it finds the CMD executable.
Remarks section of Run documentation wrote:When running a program via ComSpec (cmd.exe) -- perhaps because you need to redirect the program's input or output -- if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of quotes.

Code: Select all

Run, %ComSpec% /c "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: AutoHotkey Permissions

03 Apr 2022, 15:59

You have it correct, just your script is running as a admin so it will not work unless you use other methods.

P.s its cmd.exe
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: AutoHotkey Permissions

03 Apr 2022, 16:12

TrebleTA wrote: P.s its cmd.exe
That is typically not necessary. Try running the single-line script Run cmd. Similar to how Run notepad is usually sufficient.
dbgba
Posts: 20
Joined: 02 Apr 2021, 22:11

Re: AutoHotkey Permissions

03 Apr 2022, 19:33

This can be done to downgrade the start

Code: Select all

Run Explorer.exe "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: AutoHotkey Permissions

05 Apr 2022, 11:26

dbgba wrote:
03 Apr 2022, 19:33
This can be done to downgrade the start

Code: Select all

Run Explorer.exe "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
Thank you. This command resolves the issue. Outlook signs in automatically when it is run. This is what I needed from the beginning, a simple one-line command which runs Outlook successfully. I guess that using a Start command in a .bat file with AutoHotkey can achieve the same result too.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: pgeugene and 89 guests