Archive for the 'Windows 2003' Category

Types of logon scripts

There are four types you can have.

1. Group Policy logon / logoff scripts.
2. Group Policy Computer startup / shutdown scripts.
3. Domain User logon scripts.
4. Local user logon scripts.

Type 1 script executes when a USER logs on or logs off. And it executes with that user privilege.

Type 2 script executes when the COMPUTER starts up or shuts down. It executes in context of “Local System Account”.

Type 3 script executes when a domain user logs on. The difference is type 3 works on all Windows versions whereas type 1 only works with Windows 2000 and up.

Type 4 script: the name says itself. It only executes when the user logs on locally.

How to map a drives under VBS with different logon credentials

As not to go off topic with this post I have removed most of everything else in this script apart from anything relating to drive mappings.

Please note I am no expert in scripting and the information below should be properly tested if you intend to use it.

The script below maps drives for uses in two ways. First off, it will give all users the default shares and there home drive (P, S, X).

Then it checks what groups a user is a member of and attaches the appropriate drives. (W, U, Z, M, L)

Drives M, L attach to another server and also use different logon credentials. If you required another drive with different credentials, you could try…

On the line

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1

Add another value “objNetwork2”

Then find in the script below and copy and paste it to a new section. Then replace all the 1’s with 2’s.

Amend the username, password and the share to reflect the desired connection. And fingers crossed it should work.

Set objNetwork1 = WScript.CreateObject(”WScript.Network”)
strLocalDrive1 = “L:”
strRemoteShare1 = “\\server\share”
strPer1 = “FALSE”
strUsr1 = “username”
strPas1 = “password”
objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1, strUsr1, strPas1

‘ —— Script START ——

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objNetwork1

Set WSHShell = CreateObject(”WScript.Shell”)
Set WSHNetwork = CreateObject(”WScript.Network”)

‘Automatically find the domain name
Set objDomain = getObject(”LDAP://rootDse”)
DomainString = objDomain.Get(”dnsHostName”)
WinDir = WshShell.ExpandEnvironmentStrings(”%WinDir%”)

‘Grab the user name
UserString = WSHNetwork.UserName

‘Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject(”WinNT://” & DomainString & “/” & UserString)

‘Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName

‘Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

‘Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

‘Map drives
‘Note the first command uses the user name as a variable to map to a user share.

WSHNetwork.MapNetworkDrive “p:”, “\\server\users\” & UserString,True
WSHNetwork.MapNetworkDrive “s:”, “\\server\standards”,True
WSHNetwork.MapNetworkDrive “X:”, “\\server\company”,True

‘Now check for group memberships and map appropriate drives

For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
‘Check for group memberships and take needed action
Case “grp-Admin_tools”
WSHNetwork.MapNetworkDrive “w:”, “\\server\share”,True
WSHNetwork.MapNetworkDrive “u:”, “\\server\share”,True

Case “grp-temp-user”
WSHNetwork.MapNetworkDrive “w:”, “\\Server\Share”,True
Case “grp-FTP-root-rw”
Set objNetwork = WScript.CreateObject(”WScript.Network”)
strLocalDrive = “M:”
strRemoteShare = “\\server\share”
strPer = “FALSE”
strUsr = “username”
strPas = “password”
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas

Case “grp-ftp-root-r”
Set objNetwork1 = WScript.CreateObject(”WScript.Network”)
strLocalDrive1 = “L:”
strRemoteShare1 = “\\server\share”
strPer1 = “FALSE”
strUsr1 = “username”
strPas1 = “password”
objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1, strUsr1, strPas1

End Select

Next

‘=====================================
‘Add On Code goes above this line

‘Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
Set objNetwork = Nothing
Set objNetwork1 = Nothing

‘Quit the Script
wscript.quit

‘ —— Script END ——

Logon scripts

In a Windows 2003 Active Directory environment there are fours types of logon script. You must select the correct logon script for what you want to achieve.

  1. Group Policy logon / logoff scripts.
  2. Group Policy Computer startup / shutdown scripts.
  3. Domain User logon scripts.
  4. Local user logon scripts.

Type 1: Group Policy logon / logoff scripts

This script executes when a USER logs on or logs off. It executes with that users privileges.

Type 2: Group Policy Computer startup / shutdown scripts

This script executes when the COMPUTER starts up or shuts down. It executes in context of “Local System Account” so it has enhanced privileges.

Type 3: Domain User logon scripts

This script executes when a domain user logs on. The difference is type 3 scripts work on all Windows versions whereas type 1 only works with Windows 2000 and up.

Type 4: Local user logon scripts

This script as the name suggest, only executes when the user logs on locally.