Tom's Hardware > Forum > Applications > Programming > Find computer name to add printer
Word :    Username :           
 

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


'CONSTANTS
'Const PERSONNAL_DRIVE_LETTER = "P:"
Const HKEY_LOCAL_MACHINE = &H80000002
'Const PERSONAL_DRIVE_SERVER = "172.20.200.101"


'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.




'##########################################
'## Printer ##
'##########################################

Case UCase("Prnt_Informati" )
WSHNetwork.AddWindowsPrinterConnection "\\fsmaster\Informati"
'WSHNetwork.SetDefaultPrinter "\\fsmaster\Informati"

Case UCase("Prnt_acastilloux" )
WSHNetwork.AddWindowsPrinterConnection "\\acastilloux\acastilloux"

'##########################################
'## network drive ##
'##########################################

'Case UCase("ARO" )
'WSHNetwork.MapNetworkDrive "F:", "\\172.20.200.101\id", True 'Logiciel de base de donner pour les Tracerts d'Aro

'WSHNetwork.MapNetworkDrive "G:", "\\172.20.200.101\idb", True 'Logiciel de base de donner pour les Tracerts d'Aro

'WSHNetwork.MapNetworkDrive "Y:", "\\172.20.200.101\c-bureau", True

'Case UCase("ARO-ADMIN" )
'WSHNetwork.MapNetworkDrive "X:", "\\172.20.200.101\Adm$", True

End Select
Next


'Clean Up Memory We Used
set objUser = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing


'Quit the Script
wscript.quit

Sponsored Links
Register or log in to remove.
Tom's Hardware > Forum > Applications > Programming > Find computer name to add printer
Go to:

There are 1262 identified and unidentified users. To see the list of identified users, Click here.

Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them