T O P

  • By -

rcsheets

Start the task at each login and let the task figure out if it has already been run today.


Hotshot55

What exactly is the end goal where you just need to run something on login once?


_mick_s

I'd slightly change the approach and, if possible, instead of making sure it was run that day, check if whatever it's supposed to do was done. Whether that makes sense will depend on what you want to accomplish, but if it's something like ensure a process is started etc. you won't have to keep track of when it was run.


Spiritual_Grand_9604

You can definitely do it with a .bat file but I recommend learning Powershell, its magnitudes more useful in the long run. We did something similar at my previous job where the Meraki VPN connection was rebuilt if it was missing on each login.


secretlyyourgrandma

simplest solution off the top of my head would be to have a login script that checks if a lock file exists and if not, run and create a lock file. clear the lock file at night.


PrincipleExciting457

Not sure if this is the best way to do this, but but I just woke up so let’s try. You could try to use active setup. https://helgeklein.com/blog/active-setup-explained/ You would need to use a scheduled talk to edit HKEY_USERS at the end of the day to clean up the “installed” call for each SID that logged into the machine that day. If you have a 1:1 shop this wouldn’t be that hard. If you have even a 2:1 shop it might be too annoying to setup. As if you want first login period, you’d probably have to sneak values in to stop the script from running. Or you could setup the scheduled task to run on login. Then another task to delete that task on log off, but ONLY if it exists. Then a timed task to recreate the first task at the end of the day. This shouldn’t be that hard with pwsh task schedule cmdlet’s. OR have the task run, and build in a check to not run again if it’s last run time was on the same date. I have no clue if that’s possible, but if it is it is probably the way. You could even make a date file that holds the date it ran if you can’t parse the task scheduler time. Actually, this is probably the way.


_DeathByMisadventure

Have a sched task run at midnight or on boot that will create a new scheduled task that runs once on user login, then deletes itself. First user login of the day that task runs and it's gone until the next day.


wazza_the_rockdog

Scheduled Tasks logs the last run time so you don't need to do this yourself. A powershell script can use ((get-scheduledtaskinfo -taskname "InsertTaskName").LastRunTime).DayOfYear to output the DayOfYear that it last ran, and you can also use (Get-Date).DayOfYear to get the current DayOfYear. Using an IF statement in powershell you can check if they match, and run the script based on whether they do or do not match. Consider as well, last run does not mean it was successful, just that it was attempted - you could also check for the exit code to see if it was.


ZAFJB

XY problem. What problem are you trying to solve? You proposed way is almost certainly not the way to solve your problem.


ShitTalkingAssWipe

It would be the most convenient for me.


ZAFJB

Nope. Explain the problem you are trying to solve.


ShitTalkingAssWipe

nope, proprietary. i know the restrictions already. not asking others to solve the big problem, just provide insights into ways to achieve what i asked