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
shyam pothiniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McKnifeCommented:
In a domain environment, we solve this with group policy preference registry items that can be setup to run once only.
In non-domain environments, you would use either the registry key runonce or you would use the local policy (if available - it's not available on windows home editions). The local policy offers logon script deployment and you can use batches like this:
if exist %appdata%\myreg_has_been_imported goto end
reg.exe import myreg.reg && md %appdata%\myreg_has_been_imported
:end

Open in new window


This runs once only after the regimport has succeeded.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shaun VermaakTechnical Specialist/DeveloperCommented:
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

0
shyam pothiniAuthor Commented:
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.
0
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

McKnifeCommented:
"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.
0
shyam pothiniAuthor Commented:
It does for me too, I like doing through group policy.
But they say its corporate policy, not to use GPO's
0
McKnifeCommented:
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.
0
shyam pothiniAuthor Commented:
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
0
McKnifeCommented:
As I wrote, you can use my script and it will not populate the registry more than once since it checks for the presence of that folder %appdata%\myreg_has_been_imported. If you don't want the script to run at all (why would you, it does not matter?), you can (as I wrote before) use the runonce registry key: https://msdn.microsoft.com/en-us/library/windows/desktop/aa376977%28v=vs.85%29.aspx
-> HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
0
shyam pothiniAuthor Commented:
thanks
0
shyam pothiniAuthor Commented:
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?
0
McKnifeCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 10

From novice to tech pro — start learning today.