Jump to content

Run a batch script only once on Windows 7 64bit


Recommended Posts

I'm trying to figure out what is the best way to run this reg on computers just once after log on.

The problem is my imaged computers popup "Library" window every time a user logs into windows and this registry below fixes it. I have this in a batch file but how can I run it only once on the machine after logon? I know I can use Task Scheduler but Task Scheduler doesn't give me the option to run it only once and same with group policy. 

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t

I appreciate your help.

Link to comment
Share on other sites


21 hours ago, sam240 said:

I'm trying to figure out what is the best way to run this reg on computers just once after log on.

The problem is my imaged computers popup "Library" window every time a user logs into windows and this registry below fixes it. I have this in a batch file but how can I run it only once on the machine after logon? I know I can use Task Scheduler but Task Scheduler doesn't give me the option to run it only once and same with group policy. 


reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t

I appreciate your help.

Well I was able to figure it out on my own. In case someone needs it.

I created a batch file and added it to Local C:\support\fix.bat (I created a support folder)

To only run once,

open regedit

 goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

Create a new string and name it whatever you like and in DATA field, add the path to the batch file which in my case is C:\support\fix.bat and that worked like a charm. It automatically gets removed from registry after it runs so it does not run over and over again.

@echo off

SET FLAG=%TEMP%\Flag.txt

IF EXIST %FLAG% GOTO END

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Userinit /t REG_SZ /d "C:\Windows\system32\userinit.exe," /t > %FLAG%

:END
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...