Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of McKnife
McKnife
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of shyam pothini
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.
"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.
It does for me too, I like doing through group policy.
But they say its corporate policy, not to use GPO's
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.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks
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?
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.