need help with a VBscript
johnnyg5646
Member Posts: 173
in Off-Topic
I'm trying to write a vbscript that looks at user's OU and maps a specific printer based on that OU membership. I've done this in the past with a computer's OU and it has worked great. But now I have a need to do it based on a user.
This is what I had for a computer's OU
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName
arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)
Set objNetwork = CreateObject("WScript.Network")
'ALL OU'S ARE CASE SENATIVE!!!
Select Case strComputerOU
Case "P208"
objNetwork.AddWindowsPrinterConnection "\\nwprint\nw-0026"
objNetwork.SetDefaultPrinter "\\nwprint\nw-0026"
MsgBox "Printer NW-0026 has been mapped to your computer!"
Not sure what I would need to chage to make it apply to a user's OU rather than a computers. Any help will be appreciated. Thanks everyone!!
This is what I had for a computer's OU
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName
arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)
Set objNetwork = CreateObject("WScript.Network")
'ALL OU'S ARE CASE SENATIVE!!!
Select Case strComputerOU
Case "P208"
objNetwork.AddWindowsPrinterConnection "\\nwprint\nw-0026"
objNetwork.SetDefaultPrinter "\\nwprint\nw-0026"
MsgBox "Printer NW-0026 has been mapped to your computer!"
Not sure what I would need to chage to make it apply to a user's OU rather than a computers. Any help will be appreciated. Thanks everyone!!
BS - Computer Science
MS - Computer Information Systems
_________________
MS - Computer Information Systems
_________________
Comments
-
Claymoore Member Posts: 1,637Is this on a Novell network?
If not, have you considered using Group Policy rather than VBScript? -
johnnyg5646 Member Posts: 173Is this on a Novell network?
If not, have you considered using Group Policy rather than VBScript?
It's an AD network, but there are some complicated political reasons as to why I can't use group policy because this is a state college. It's all very messy and this is the easiest way to address the issue for the one classroom that requires this setup.BS - Computer Science
MS - Computer Information Systems
_________________ -
Claymoore Member Posts: 1,637How about just a .cmd file with the net use command?
net use lpt1: [URL="file://\\server\printer"]\\server\printer[/URL] -
johnnyg5646 Member Posts: 173If i wanted it to look at active directory and have it say if user name starts with "0" do this, if it doesn't then do this....
how would i code that?BS - Computer Science
MS - Computer Information Systems
_________________ -
doom969 Member Posts: 304Quest as a set of cmdlets that would make this easy to do in powershell.
PowerShell Commands (CMDLETs) for Active Directory by Quest Software
Of course it all depends if you have powershell deployed on the workstations....Doom969
__________________________________________________________
MCP (282 - 270 - 284 - 290 - 291 - 293 - 294 - 298 - 299 - 350)
MCTS (351 - 620 - 622 - 647 - 649 - 671)
MCSA / S / M - MCSE / S
MCITP (EST - EA ) - MCT
A+ - IBM - SBSS2K3 - CISCO_SMB
CompTIA : A+ -
sprkymrk Member Posts: 4,884 ■■■□□□□□□□These users wouldn't all happen to be a member of a certain windows group would they? If so, you could use a script with "ifmember.exe".
IFMEMBER Students
IF ERRORLEVEL 1 net use lpt1 \\server\printer1
IFMEMBER Teachers
IF ERRORLEVEL 1 net use lpt1 \\server\printer2All things are possible, only believe. -
unclerico Member Posts: 237 ■■■■□□□□□□johnnyg5646 wrote: »I'm trying to write a vbscript that looks at user's OU and maps a specific printer based on that OU membership. I've done this in the past with a computer's OU and it has worked great. But now I have a need to do it based on a user.
This is what I had for a computer's OU
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.ComputerName
arrComputerName = Split(strName, ",")
arrOU = Split(arrComputerName(1), "=")
strComputerOU = arrOU(1)
Set objNetwork = CreateObject("WScript.Network")
'ALL OU'S ARE CASE SENATIVE!!!
Select Case strComputerOU
Case "P208"
objNetwork.AddWindowsPrinterConnection "\\nwprint\nw-0026"
objNetwork.SetDefaultPrinter "\\nwprint\nw-0026"
MsgBox "Printer NW-0026 has been mapped to your computer!"
Not sure what I would need to chage to make it apply to a user's OU rather than a computers. Any help will be appreciated. Thanks everyone!!
Set objSysInfo = CreateObject("ADSystemInfo")
strADsPath = objSysInfo.UserName
'split the string on the comma
arrUserName = Split(strADsPath, ",")
'pull out the users OU
strUserOU = arrUserName(1)
Set objNetwork = CreateObject("WScript.Network")
'ALL OU'S ARE CASE SENATIVE!!!
Select Case strUserOU
Case "Test"
objNetwork.AddWindowsPrinterConnection "\\nwprint\nw-0026"
objNetwork.SetDefaultPrinter "\\nwprint\nw-0026"
MsgBox "Printer NW-0026 has been mapped to your computer!"
One thing to note about this is if you have an OU structure that has multiple OU's labeled, for example, Test then you may get incorrect printer mappings as one path may be Test -> Seventh_Floor -> Company_Users and another may be Test -> Eighth_Floor -> Company_Users. Users of both Test OU's will get the same printers so you may want to match a longer path than just the users immediate OU. I hope I'm making sense.Preparing for CCIE Written