We help IT Professionals succeed at work.

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

shyam pothini
on
662 Views
Last Modified: 2018-02-22
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
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
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

Author

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.
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
"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.

Author

Commented:
It does for me too, I like doing through group policy.
But they say its corporate policy, not to use GPO's
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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.

Author

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
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
thanks

Author

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?
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions