Hi everyone, I hope someone here can help... I've been going through the net for a VBscript to use at logon to add a printer based on the security group that the user is in. After a few hours of searching and tweaking the code (I have very very basic knowledge of VBScript) I finally managed to have it working. But now we need it to see if the Computer name is in the security group instead of the user to determine which printer it needs and I have no idea how to code it and I've spent the last 2 days trying to find an answer but can't seem to find anything that actually works.
Thanks in advance to anybody who can help me out
Here's a sample of my code:
On ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, objUser, Path
Set WSHShell = CreateObject("WScript.Shell" )
Set WSHNetwork = CreateObject("WScript.Network" )
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse" )
DomainString = objDomain.Get("dnsHostName" )
'Fait référence au dossier spécial "Bureau"
Set oFSO = CreateObject("Scripting.FileSystemObject" )'Wscript.CreateObject("Scripting.FileSystemObject" )
strDsk = WshShell.SpecialFolders("Desktop" )
'Find the Windows Directory
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 objUser = GetObject("WinNT://" & DomainString & "/" & UserString)
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'Below is an example of how to set the default printer
'WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
For Each GroupObj In objUser.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
'Note the use of all upper case letters as mentioned above.
'Note also that the groups must be Global Groups.
'Clean Up Memory We Used
set objUser = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing