Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a scheduled task that runs when any user logins to the system

I want to launch an exe file of my product (C:\ClassConnect\class_server.cmd) on user login. I tried 2 solutions ( but nothing seems to work) Solution 1 : ( Added Startup Shortcut )

It asks the user for UAC dialog, which obviously my users will not accept as its a spy app. Solution 2 : ( Added batch to windows scheduler so that it runs for any user)

It runs fine with the administrator account but fails for other users. Moreover I am not able to view scheduled tasks on other users

Please help. ( I want the batch to run on startup for all users on my machine)

like image 761
Rajesh Agrawal Avatar asked Jan 18 '26 10:01

Rajesh Agrawal


2 Answers

I would recommend you to put your class_server.cmd file in the alluser start-up folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Or call your .cmd file via shortcut and runas in the start-up folder to solve the UAC problem. Follow this documentation: http://www.howtogeek.com/124087/how-to-create-a-shortcut-that-lets-a-standard-user-run-an-application-as-administrator/

like image 153
Yanick Schraner Avatar answered Jan 20 '26 22:01

Yanick Schraner


After struggling my head for so many days, I finally found the answer for running the program as admin

I wrote the following batch file to run one of my system program in admin mode without UAC Popup( it auto Enters the admin password )

I wrote a batch file run.bat with following content => it then executes a vb script which waits for 5 second and keys in the password.

================run.bat Start========================

set USER_NAME="administrator"
set PASSWORD="test"
set PROGRAM_NAME="C:\\ClassConnect\\class_student.bat"
set "cm=cscript /B /nologo runas4.vbs %PASSWORD%"
%cm%
runas /profile /env /user:%USER_NAME% "%PROGRAM_NAME%"

================run.bat End========================

================runas4.vbs Start========================

Set objArgs = Wscript.Arguments
password=objArgs(0)
set WshShell = WScript.CreateObject("Wscript.Shell")
WScript.Sleep 5000
bWindowFound = WshShell.AppActivate("ClassConnect_Teacher")
WScript.Sleep 500
WshShell.SendKeys password
WshShell.SendKeys "{ENTER}"
set WshShell = nothing

================runas4.vbs End========================

The above script waits for 5 second and then enters the password for runas command thus I am able to run the script in admin mode.

If you are not sure about your access rights, download the isadmin.exe from internet.

if you do not have admin access on the system , activate the default disabled Administrator account. You can activate the account by using

net user administrator /active:yes

For resetting the default administrator password use: net user administrator *

like image 40
Rajesh Agrawal Avatar answered Jan 20 '26 21:01

Rajesh Agrawal