Avatar of shyam pothini
shyam pothini
 asked on

how to run a batch file whenever user logs in for only one time

How to run a batch file one time for user.
that means I have a batch file to change registry keys and I want to run it when a user logs in and if the user logs in for second time it should not run.
But if another user logs in the batch file should run.
Is there any setting in registry like run or run once?

Thanks
Windows 10* Regedit

Avatar of undefined
Last Comment
McKnife

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
McKnife

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Shaun Vermaak

I would do what McKnife suggested but with Registry

@Echo Off
reg query HKCU\SOFTWARE\MySoftware /v RunOnce

IF %errorlevel% NEQ 0 GOTO Run
Goto End

:Run
MySoftware.exe
reg add HKCU\SOFTWARE\MySoftware /v RunOnce /d 1 /f

:End

Open in new window

shyam pothini

ASKER
thanks for the responses
Its domain environment but we don't want to do it with group policy
but local group policies are ok
Please guide me how to do that.
McKnife

"We don't want to do it with group policy but local group policies are ok" - you need to tell why, because that sounds, well, crazy.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
shyam pothini

ASKER
It does for me too, I like doing through group policy.
But they say its corporate policy, not to use GPO's
McKnife

But local GPO is ok?? It's the same thing, the very same thing. That makes no sense at all.
Ok, open gpedit.msc, navigate to user policy - windows settings - scripts - logon. There, link a batch.
shyam pothini

ASKER
Thanks
I kept the batch file in there.
But it run everytime user logs in. Is there any way I can run only one time for user
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
McKnife

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
shyam pothini

ASKER
thanks
shyam pothini

ASKER
If I create reg key name application and give the path where the file is
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

it will run everytime user logs in right?
McKnife

No, just once. MIcrosoft's article describes it:
By default, the value of a RunOnce key is deleted before the command line is run. You can prefix a RunOnce value name with an exclamation point (!) to defer deletion of the value until after the command runs. Without the exclamation point prefix, if the RunOnce operation fails the associated program will not be asked to run the next time you start the computer.
Your help has saved me hundreds of hours of internet surfing.
fblack61