How To Write A Logon Script For Windows Server 2008
GPO logon scripts allow you to run a BAT or PowerShell script at computer startup or user logon/logoff. In some cases, an administrator wants a particular script (command/program) to be run for each user or computer simply one time and not run at the next logons.
To solve this task, y'all can use a standard logon script that checks for a sure flag on the computer. This can be a registry parameter, a text file on the disk, etc.
For case, you want a sure lawmaking block to be executed only once at the start user log on to a reckoner.
- Create the following BAT file (corp_user_init.bat) and save it to
%SystemRoot%\SYSVOL\sysvol\<domain name>\scripts
on your domain controller:@echo off
IF Be 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 volition exist executed once
:ENDThe script creates a modest text file in a user'southward contour when it is run for the offset time. When the script is run for the next time through the GPO, it checks if the file exists on a disk. If it does, the script has already been executed and the lawmaking doesn't need to exist run once more.
- Open the domain Group Policy Management console (
gpmc.msc
); - Create a new policy and link it to an OU with users (or computers, but and then you take to enable the Loopback Processing mode);
- Go to User Configuration -> Windows Settings -> Scripts (Logon / Logoff);
- Select Logon;
- Click Add and specify the path to your BAT file in SYSVOL (
\\woshub.com\SysVol\woshub.com\scripts
);
- After updating Group Policy settings on a client reckoner, your script will be executed at user logon. Brand sure that it has successfully created the app_init.txt file in a user's contour.
If the GPO with the script has not been applied, use the gpresult tool and troubleshooting methods described in the article Why GPO Is not Applied.
- At the side by side user logs on to a computer, the main script code volition not be executed. So, the script is actually applied to the user only one time.
Another fashion to run a script simply once using GPO is to create a ane-fourth dimension chore in the Task Scheduler.
- Salvage your script file (information technology may exist either a BAT file or a PowerShell script) to the Sysvol folder on the domain controller (
\\<your_domain_name>\SysVol\<your_domain_name>\scripts
); - Create a new GPO, link information technology to the user's OU, and open its settings;
- Become to Preferences -> Command Console Settings -> Scheduled Task -> New -> Firsthand Job (At least Windows 7);
- Specify the task name;
- Open the Deportment tab, click New, and specify the full UNC path to your script file in SYSVOL;
- Then get to the Common tab and bank check the Apply one time and do non reapply option;
- This task will run on a computer merely once at the first user logon.
Source: http://woshub.com/run-gpo-logon-script-once/
Posted by: ryaneyseld.blogspot.com
0 Response to "How To Write A Logon Script For Windows Server 2008"
Post a Comment