Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please do not laugh at my first login.vbs script.

Status
Not open for further replies.

spikestik

IS-IT--Management
Jan 28, 2003
59
0
0
US
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





 
Could you define the specific problem you are having?

C
 
Craig

Thank you for the response.
The problem that I am having is

1)that I think there is excess code in my script.
2)i am not sure how to test for a local printer and assign it as default or if there is not one to assign a network printer.
3)not sure how to test for and add group membership printers and drives.

basically I need someone to look it over and tell me what I am missing ... maybe re-work to help me improve it ... make suggestions....etc.

Chris
 
I'd say don't reinvent the wheel. Check out my FAQ. faq329-5798

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top