[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

How do u create a logon script for drive mappings and to run an .exe ?

I am working in a mixed win2000/2003 server environment with mixed 2000/xp client machines.  
I need to create a logon script so that an ou of users have drive mappings setup and an .exe runs every time they logon.
The script will be deployed using group policy. I have no experience of writing scripts.

Please, can anyone help me?
0
gpersand
Asked:
gpersand
1 Solution
 
bilbusCommented:
'==========================================================================
'
' Your script name
'
'==========================================================================


ON ERROR RESUME NEXT

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

'Edit the next line with your domain name
DomainString = "DomainName"
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"

'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"

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

'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",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
    'In this example below, ADMIN and WORKERB are groups.
        Case "Admin"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerB"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
    End Select
Next


'Install Printers
WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"

'Remove an old printer
WSHNetwork.RemoveWindowsPrinterConnection "\\ServerOld\HP5si"

' This section of script will prevent the baloon window that appears when printing
' to a network shared printer after XP Service Pack 2 is installed.
'=====================================

Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"

'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing


'Quit the Script
wscript.quit
0
 
mredfelixCommented:
add the script in netlogon..

u can do all this through group policy..
0
 
gpersandAuthor Commented:
I deeply apologise for my late reply. I have recently moved home and have not had an internet connection.

The script you have written is a bit too complicated making it difficult for me to understand how to use it properly.

Could you give me a script in .bat format so I can add it to the netlogon share on a dc.
All the script needs to do is map network drives.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now