I am not a scripter....but have been trying to get a generic login script to work and am having some trouple with it.
What I am trying to do is fulfill these requiremnt:
1) map printers based on group mebership
2) map nework drives based on group membership
3) map generic drives to all users
4) map generic printers to all users
5) delete all network and IP printers
6) set default printer to a network printer (of choice) unless they have a local printer then set the default printer to that.
Enclosed is my script that I have been using .... I have made it generic to protect the innocent.
Could the community look at it not laugh outloud and help me with it? I think that I may have inseted code that is not needed but can not tell. As I just do not know.
feel free to use it if you would like.
'**********************************************************************************
' Sets Environment Variables
'*********************************************************************************
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Domain = WSHNetwork.UserDomain
UserName = ""
While UserName = ""
UserName = WSHNetwork.UserName
MyGroups = GetGroups(Domain, UserName)
Wend
'*********************************************************************************
' Main Process:
'*********************************************************************************
GrpMeb UserName
ShowBox
Wscript.Quit
'*********************************************************************************
'Delete All Network Printer Maps:
'*********************************************************************************
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
On error resume next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oDrives.Count - 1 Step 2
WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo oPrinters.Item(i+1)
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)
Next
'*********************************************************************************
'Function: GetGroups
'*********************************************************************************
Function GetGroups(Domain, UserName)
Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
GetGroups=""
For Each objGroup In objUser.Groups
GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
Next
End Function
'********************************************************************************
'Function: InGroup
'********************************************************************************
Function InGroup(strGroup)
InGroup=False
If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
InGroup=True
End If
End Function
'*********************************************************************************
' MapDrives Subroutine (should not have to change anyting)
'*********************************************************************************
Sub MapDrive(sDrive,sShare)
On Error Resume Next
WSHNetwork.RemoveNetworkDrive sDrive, 1, 1
wscript.sleep 1000
Err.Clear
WSHNetwork.MapNetworkDrive sDrive,sShare
End Sub
'********************************************************************************
'Map Network Drives:
'********************************************************************************
Sub GrpMeb(UNAME)
MapDrive "h:", "Enter UNC of Path To Map"
'********************************************************************************
'Map Network Drives Based On Username:
'********************************************************************************
'IF UserName = "put user name here" then MapDrive "Enter Drive Letter Here With a :", "Enter UNC Of Path To Map"
'********************************************************************************
'Map Network Printers:
'********************************************************************************
Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "ENTER UNC OF PRINTER HERE"
'********************************************************************************
'Set Default Printer:
'********************************************************************************
' Set the default printer now
'net.SetDefaultPrinter "Enter UNC of Printer Here"
'********************************************************************************
'Syncronizes Time:
'********************************************************************************
strCmd = "net.exe time mserver /set /yes >null"
WshShell.Run strCmd, 0
End Sub
What I am trying to do is fulfill these requiremnt:
1) map printers based on group mebership
2) map nework drives based on group membership
3) map generic drives to all users
4) map generic printers to all users
5) delete all network and IP printers
6) set default printer to a network printer (of choice) unless they have a local printer then set the default printer to that.
Enclosed is my script that I have been using .... I have made it generic to protect the innocent.
Could the community look at it not laugh outloud and help me with it? I think that I may have inseted code that is not needed but can not tell. As I just do not know.
feel free to use it if you would like.
'**********************************************************************************
' Sets Environment Variables
'*********************************************************************************
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Domain = WSHNetwork.UserDomain
UserName = ""
While UserName = ""
UserName = WSHNetwork.UserName
MyGroups = GetGroups(Domain, UserName)
Wend
'*********************************************************************************
' Main Process:
'*********************************************************************************
GrpMeb UserName
ShowBox
Wscript.Quit
'*********************************************************************************
'Delete All Network Printer Maps:
'*********************************************************************************
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
On error resume next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oDrives.Count - 1 Step 2
WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo oPrinters.Item(i+1)
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)
Next
'*********************************************************************************
'Function: GetGroups
'*********************************************************************************
Function GetGroups(Domain, UserName)
Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
GetGroups=""
For Each objGroup In objUser.Groups
GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
Next
End Function
'********************************************************************************
'Function: InGroup
'********************************************************************************
Function InGroup(strGroup)
InGroup=False
If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
InGroup=True
End If
End Function
'*********************************************************************************
' MapDrives Subroutine (should not have to change anyting)
'*********************************************************************************
Sub MapDrive(sDrive,sShare)
On Error Resume Next
WSHNetwork.RemoveNetworkDrive sDrive, 1, 1
wscript.sleep 1000
Err.Clear
WSHNetwork.MapNetworkDrive sDrive,sShare
End Sub
'********************************************************************************
'Map Network Drives:
'********************************************************************************
Sub GrpMeb(UNAME)
MapDrive "h:", "Enter UNC of Path To Map"
'********************************************************************************
'Map Network Drives Based On Username:
'********************************************************************************
'IF UserName = "put user name here" then MapDrive "Enter Drive Letter Here With a :", "Enter UNC Of Path To Map"
'********************************************************************************
'Map Network Printers:
'********************************************************************************
Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "ENTER UNC OF PRINTER HERE"
'********************************************************************************
'Set Default Printer:
'********************************************************************************
' Set the default printer now
'net.SetDefaultPrinter "Enter UNC of Printer Here"
'********************************************************************************
'Syncronizes Time:
'********************************************************************************
strCmd = "net.exe time mserver /set /yes >null"
WshShell.Run strCmd, 0
End Sub