Post

How to Run Script in GPO Only Once?

GPO login scripts allow you to run a BAT or PowerShell script at computer startup or user login/logout. In some cases, the administrator wants a particular script (command/program) to be run only once per user or computer and not run on subsequent logins.
You can use this by adding the following commands to your script.

Create the following BAT file ( teksefer.bat ) and save it under directory \\SYSVOL\sysvol\scripts\

@echo off
IF EXIST C:\Users\%UserName%\AppData\app_init.txt GOTO END
date /t >> C:\Users\%UserName%\AppData\app_init.txt
time /t >> C:\Users\%UserName%\AppData\app_init.txt
REM Put your code here, which will be executed once
:END

//my other commands
//hello word
//TheGuler!

The script creates a small text file in the user's profile the first time it runs. The next time the script is run via the GPO, it checks if the file exists on a disk. If it exists, the script has already been executed and the code does not need to be rerun.

Saygılarımla. – Best regards.

This post is licensed under CC BY 4.0 by the author.