Logon Scripts

  

Logon Scripts - Simple Sample Script

Logon Script

This page will get you started writing VBScripts.  I will explain how to create, then and test a simple script.  All you need is notepad.  As you work through the example, see how you manipulate the Object (network) with the Method (Echo).Sample VBScript

The purpose of this script is to echo the name of the User who is logged-on.  Also VBScript will display the 'hostname' of the Computer where the script is run.

Instructions to Create your VBscript:

  1. Pre-requisites.  You need a domain controller for this script to work.
    If you have no domain controller try this script.
  2. Copy and paste the script below into notepad.
  3. Save the file with .vbs extension e.g. MyInfo.vbs
  4. Double click and observe the message box

 

 

'  VBScript.

'  Guy Thomas October 2004
'  Purpose of script to display the UserName and ComputerName
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name = " & WshNetwork.ComputerName & VBCrLf _
& "User Name = " & WshNetwork.UserName

 

Learning Points

Note 1: VBCrLf is needed to force a carriage return in your script.

Note 2: Underscore(_) is necessary because my script will not fit on one line.  ( The _ is not an error on your screen!)

˚

Testing:

Double click the .vbs file to test your script.  VBScript will work on Windows 2003, XP and Windows 2003 machines.

Bonus Sample 2

Stage 2)  Let us ask the script to display the domain, naturally you must be logged to a domain for this part to work!

Instructions:

  1. Pre-requisites.  You need a domain controller for this script to work.
  2. Copy and paste the script below into notepad.
  3. Save the file with .vbs extension e.g. MyDomain.vbs
  4. Double click and observe the message box
  5. Add to your first script:  & "Domain = " & WshNetwork.UserDomain
    Check the script below to see the extra:  & vbCrLF _  on the line above.

 

 

'  VBScript.
'  Guy Thomas October 2004
'  Purpose of script to display the Domain name
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name = " & WshNetwork.ComputerName & vbCrLF _
& "User Name = " & WshNetwork.UserName & vbCrLf _
& "Domain = " & WshNetwork.UserDomain

 

 

Two ways to run your scripts.

  • Double-click the icon of the script. Useful for testing (I expect you have done this already.)
  • From the command line, type the name of the script.  This is what will happen at logon.

Assign the script to your users

 

See Also

 


Download my Logon Script eBook for only $6.25

Logon ScriptThe extra features you get in your eBook include, more pages full of detailed examples.  Also, ten 'how to...' sections, with screen shots showing which menus to use.  Go for Guy's eBook - and get a printable version with copy enabled and no expiry date.

  Jumbo Script 7 Package

 

 *


Google

Webcomputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Here is a solution to monitor, manage and archive thousands of events that are generated by devices across your entire network.  Get your free evaluation copy of GFI EventsManager.

 

Home Copyright © 1999-2008 Computer Performance LTD All rights reserved

Please report a broken link, or an error.