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
}