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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map printers based on computer membership

Status
Not open for further replies.

dinsone

MIS
May 22, 2008
6
NO
hi i'm having a problem with my logon script. I vant i to add printers based on computer membership instead of having them added based on computer name


As you se managment is hard if the script is going to grow much more
_______________________________________________________________________________________
on error resume next

'---------------------------------------------------------------------------------------
'User customizable strings
strFileServer = "vskfs1"
strPrintServer = "vskdc1"
strShareFelles = "felles"

Set objWshNetwork = WScript.CreateObject("WScript.Network")
Set objADSysInfo = WScript.CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.Username)
Set net = CreateObject("WScript.Network")

'---------------------------------------------------------------------------------------
'Skolens dataregler
regler = msgbox("Ved bruk av dette system godtar du skolensdata reglemang," & vbCrLf & _
"brudd på reglemang fører til umiddelbar bortvisning fra datarom"& vbCrLf & _
"eller inndragelse av datautstyr. Straffeperioden variere etter misbruk"_
& vbCrLf & vbCrLf & "Godtar du dette", vbYesNo, "Viktig")
if regler = vbNo then

Dim objShell, strComputer, strInput
Dim strShutdown
strShutdown = "shutdown -l"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown

end if


'---------------------------------------------------------------------------------------
'Enumerate user's groups
'Uses backets to uniquely distinguish group names
For Each objGroup In objUser.Groups
strGroups = strGroups & "[" & objGroup.Name & "]"
Next

'---------------------------------------------------------------------------------------
'Enumerate current drives and printers
Set colDrives = objWshNetwork.EnumNetworkDrives
Set colPrinters = objWshNetwork.EnumPrinterConnections

'---------------------------------------------------------------------------------------
'Remove existing drives and printers
For i = 0 To colDrives.Count - 1 Step 2
objWshNetwork.RemoveNetworkDrive colDrives.Item(i), True, True
Next
For i = 1 To colPrinters.Count Step 2
objWshNetwork.RemovePrinterConnection colPrinters.Item(i), True, True
Next

'---------------------------------------------------------------------------------------
'Finds computer name and outputs it to strHOSTNAME
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set net = CreateObject("WScript.Network")
For Each objItem in colItems
strHOSTNAME = objItem.Name
NEXT

'---------------------------------------------------------------------------------------
'Function to check for group membership
Function InGroup(groupName)
InGroup = False
If InStr(strGroups,"[" & groupName & "]") <> 0 Then
InGroup = True
End If
End Function

'---------------------------------------------------------------------------------------
'Check for group membership and run associated commands
'Calls InGroup Function
'---------------------------------------------------------------------------------------

':::::::::::::::::::::::Midlertidig::::::::::::::::::::::::::
'Eksamens bruker
'Map HomeFolder


if InGroup("CN=Eksamen") Then
objWshNetwork.MapNetworkDrive "H:", objUser.homeDirectory
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C01"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C02"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C03"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C04"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ5Si_8KL"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ5Si_9KL"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP1022N_9KL"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
End if

if InGroup("CN=std") Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C01"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C02"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C03"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ1320_C04"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ5Si_8KL"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HPLJ5Si_9KL"
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP1022N_9KL"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
End if

'---------------------------------------------------------------------------------------
if InGroup("CN=HOMEFOLD") Then
'Map HomeFolder
objWshNetwork.MapNetworkDrive "H:", objUser.homeDirectory
End if

if InGroup("CN=PUBLICFOLD") Then
'Map PublicFolder
objWshNetwork.MapNetworkDrive "F:", "\\" & strFileServer & "\" & strShareFelles
End if

'---------------------------------------------------------------------------------------

'Checks computername, and sets default printer to "HpLjP2015N_K&H" (Kunst & håndverk)


if InStr( strHOSTNAME, "MAN0843" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0839" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0840" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0852" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0846" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0851" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0845" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0847" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0849" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0844" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
Else
if InStr( strHOSTNAME, "MAN0848" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if

'---------------------------------------------------------------------------------------
'"hpLj2015N_DataLab" (Store datarom)

'Lærer maskin = MAN0683
If InStr( strHOSTNAME, "MAN0683" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0692" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0672" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0671" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0677" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0674" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0700" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN00698" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0670" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0676" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0667" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0666" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0697" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0691" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0664" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0699" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0679" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0708" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0663" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0696" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0701" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0690" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0684" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0685" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
if InStr( strHOSTNAME, "MAN0689" ) <> 0 Then
objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
Else
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
'---------------------------------------------------------------------------------------

'---------------------------------------------------------------------------------------

MsgBox "Innlogging vellykket" & vbCrLf & vbCrLf & "Klokka: " & time & vbCrLf & _
"Dato: " & date & vbCrLf & "På maskin: " & objWshNetwork.ComputerName & _
vbCrLf & "Brukernavn: " & objWshNetwork.UserName , 64, "Melding fra IT-ansvarlig (Kim)"
 
All of the code you need you should be able to find in my FAQs.

faq329-5798
faq329-5908

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.
 
How about something simple and quick? Here's a replacement for the nested If statements you have.

Code:
Select Case strHOSTNAME
	Case	"MAN0843","MAN0839","MAN0840","MAN0852","MAN0846","MAN0851","MAN0845", _
			"MAN0847","MAN0849","MAN0844","MAN0848"

		objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"
		net.SetDefaultPrinter "\\" & strPrintServer & "\" & "HpLjP2015N_K&H"

	Case	"MAN0683","MAN0692","MAN0672","MAN0671","MAN0677","MAN0674","MAN0700","MAN00698", _
			"MAN0670","MAN0676","MAN0667","MAN0666","MAN0697","MAN0691","MAN0664","MAN0699", _
			"MAN0679","MAN0708","MAN0663","MAN0696","MAN0701","MAN0690","MAN0684","MAN0685", _
			"MAN0689"

		objWshNetwork.AddWindowsPrinterConnection "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"
		net.SetDefaultPrinter "\\" & strPrintServer & "\" & "hpLj2015N_DataLab"

End Select

While reinventing the wheel may be fun and educational, it may also be a waste of time.

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Hmm i did not find anything that mad it possible for me to find the computer membership. I have organised AD whit different OU`s for every conference rom and different classrooms. The only thing i need now is to be able to use this logon script whitout having to add lines every time a new computer is put into the system. I want to be able to only make a group membership in ad to add printers.
 
Bind to the computer, then enumerate the membership like demoed for users in the FAQ.

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.
 
Here's approximately what you are looking for...

Code:
Option Explicit

Dim objNetwork, strComputer, strDomain, strServer, objComputer, objDict, objGroup

Set objNetwork = CreateObject("WScript.Network")

strComputer = objNetwork.ComputerName
strDomain = objNetwork.UserDomain
strServer = "Server1"

Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer & "$,user")

Set objDict = CreateObject("Scripting.Dictionary")

For Each objGroup In objComputer.Groups
	objDict.Add objGroup.Name, "-"
Next

If objDict.Exists("Group1") Then
	objNetwork.AddWindowsPrinterConnection "\\" & strServer & "\Printer1"
	objNetwork.SetDefaultPrinter "\\" & strServer & "\Printer1"

ElseIf objDict.Exists("Group2") Then
	objNetwork.AddWindowsPrinterConnection "\\" & strServer & "\Printer2"
	objNetwork.SetDefaultPrinter "\\" & strServer & "\Printer2"

Else
	WScript.Echo "Not a member of a printer group"

End If

Just beware of 2 problems... 1) If the computer is a member of [red]no[/red] groups, it will get no printers, and 2) if the computer is a member of multiple groups, the last one in the list will end up as the default printer.

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I do not get the script "PScottC" wrote to work. :(.
I only get errors when im pasting it into my script
 
You will need to fix this line:
Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer & "$,[red]user[/red]")

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.
 
You will need to fix this line:
The reason "user" is there is because I am treating the computer account as a user (which in AD terms is mostly true). What I am doing is appending a "$" to the computer name, which allows me to do this. (ie. Computername: foo = username: foo$)

To use the code I posted above, you must do a couple of things:

1) Create groups in AD that will be associated with a particular printer.
2) Each computer that will be subject to this script needs to be added to one (and only one) of the groups created in step one.
3) Replace parts of my code with the appropriate information (groupX with group name created in step 1, PrinterX with the name of your printer, ServerX with your server name, etc...)

Code:
strServer = "[red]Server1[/red]"
If objDict.Exists("[red]Group1[/red]") Then
    objNetwork.AddWindowsPrinterConnection "\\" & strServer & "\[red]Printer1[/red]"
    objNetwork.SetDefaultPrinter "\\" & strServer & "\[red]Printer1[/red]"

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Sorry for bother you this much. But i am not a master in coding VBS.

I get an error while running the script.
Option Explicit '### Error at this line ###
The script as it is now is added as an "Attachment
 
 http://dinsone.com/logon.txt
I took a slightly different approach to this issue at our site. We have approx 900 stations split over 150 or so rooms and my solution handles drive and printer mappings with a minimum of admin overhead - although is more complex to configure initally.

What i did was to extend the AD attributes for the OU object to include a printermappings and a drivemappings attribute. The list of appropriate drives and printers to map for each OU were then entered into these attributes (requires some coding to develop an interface to do this - but not hard). My logon script then works out where in the AD the machine is and reads back the lists of printers and drives in my attributes and adds them to the station.

The main advantages to this method are that printers and drives can be allocated anywhere in the AD tree above the current OU - so site wide printers and drives can be managed easily, and allocations are made on the OU objects themselves rather than having to go in and edit a script file.

If anyone is interested in further details let me know.

Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
>Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer & "$,user")
I think there is some confusion slipped in mixing WinNT and LDAP providers' proper nomenclature.
[tt]Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputer & "[highlight],[/highlight][red]computer[/red]")[/tt]
With the correction made, at least the op could look into whether PScottC's suggestions made sense to their case.
 
Thanks for all the help.
But my biggest problem right now is the

Option Explicit

Line in the script.

Error: Expected statment
 
On the face of the error message, you must move the "option explicit" to the very top of the script file, before anything else except comment.
 
markdmac would this code of your's not be a better solution similar to what PScottC is suggesting?
BTW has it been added to your FAQ's?

and lastly dinsone I'm no coder like Mark, tsuji and PScottC but generally functions/subs should be at the end of a script, and declare Global variables at the top
e.g Dim objNetwork:Set objNetwork = CreateObject("WScript.Network")

Code:
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
strComputer = WSHNetwork.ComputerName
Set ComputerObj = GetObject("WinNT://" & DomainString & "/" & strComputer)

For Each GroupObj In ComputerObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
    'In this example below, ADMINPC and WORKERPC are groups.
        Case "AdminPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
        Case "WorkerPC"
            WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
            'Below is an example of how to set the default printer
            WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
    End Select
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top