Logon Script example

This forum contains useful scripts and script guidelines to have effective Windows Scripting
Post Reply
ManU
Founder
Founder
Posts: 98
Joined: Sat Sep 26, 2009 9:57 am
Location: India
Contact:

Logon Script example

Post by ManU » Wed Oct 21, 2009 11:41 am

Script to switch from static IP to DHCP

1. Copy the following lines to a notepad
REM Start Script
netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set DNS "Local Area Connection" dhcp
:end
REM End script
2. Save it in an appropriate name (for example: logon.bat, logon.cmd, logon.vbs, etc.). The script can use ANY name with the right file extension type

3. copy the file to %SystemRoot%\SYSVOL\sysvol\<domain DNS name>\Policies\{GUID}\User\Scripts\Logon

If you wish to assign script to more than one user, you will need to create as many logon scripts as you want, and then add them in the right order in the right GPO

If you choose to apply on all the users in the domain, you must create a Group Policy Object (or GPO) and link it to the ENTIRE domain. If you choose to apply the script ONLY to a SPECIFIC SET of users, you must place all the users in one OU (Organization Unit) in Active Directory Users and Computers, and link the GPO to that OU.

In order to assign the GPO and edit it, we'll use a tool called Group Policy Management console, or GPMC in short. This tool is not installed by default in Windows Server 2003, and neither is it installed by default in Windows Server 2008. In Windows Server 2008, GPMC is considered to be a "Feature", and you must install it before being able to use it.

4. Open Group Policy Management Console from the Administrative Tools folder (or gpmc.msc from RUN).

5. If you decided to apply the script to ALL THE DOMAIN USERS, expand the domain tree, locate the domain name. Right-click the domain name and select Create and Link a GPO Here. If you decided to apply the script to ONLY a SPECIFIC SET of users, expand the domain tree, locate the OU where the users from are located. Right-click the OU and select Create and Link a GPO Here.

6. In the New GPO window, give the new GPO a descriptive name, such as "Test Logon Script GPO". Click Ok.

7. Right-click the new GPO and select Edit.

8. In the Group Policy Management Editor window, expand User Configuration > Policies > Windows Settings > Scripts.

9. Double-click Logon in the right-hand pane.

10. In the Logon Properties window, click Show Files.

11. A window will open. The path will be a folder similar to the following: \\domain.com\SYSVOL\<domain DNS name>\Policies\{E4A62379-8423-4654-8DB6-01FB8F58582D}\User\Scripts\Logon. Paste the logon script you've created there.

12. Back in the Logon Properties window, click Add.

13. In the Add a Script window, click Browse and you will see the logon script pasted in a previous step. Click Ok.

14. Back in the Logon Properties window, see if the logon script is listed, and if it is, click Ok

15. Close the Group Policy Management Editor window.

16. Close the GPMC window.

17. On one of the computers that is part of the domain, logoff the specific user account.

18. Logon and test whether it is working properly
Thanks
MANU PHILIP
Microsoft MVP(Exchange Server)
| MCITP | MCTS | MCSA | ITIL V3 |
TechNet Forums Profile: ManU

babylon78
Rank1
Rank1
Posts: 1
Joined: Mon Feb 01, 2010 11:15 pm

Re: Logon Script example

Post by babylon78 » Wed Feb 03, 2010 11:19 pm

Good tip regarding the login script. I've never really used the login script to switch from static to DHCP, but I do use them for tons of other stuff, and i found that http://Kixtart.org is one of the best scripting languages for this, well, given that it is geared for login scripts.

It has a pretty community with tons of UDFs to do pretty much anything under the sun. It's very "VBish", but has specific built-in Macros and functions that make it easier to use than VB, and DEFINITELY more flexible than batch files :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest