Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Script for mapping printers with username and passwords

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,27385
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script for mapping printers with username and passwords
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Script for mapping printers with username and passwords - 10/26/2005 11:37:08 PM   
  FireNacho

 

Posts: 2
Score: 0
Joined: 10/26/2005
Status: offline
Hi i started learning VBscript a couple of weeks ago. And suddenly now at work we need a litte script for mapping up Home Folders And a printer for our users.
I`ve managed to get the home folder mapping to work by using a combination of Wscript and Shell Script (Net Use)

But with the printer i have a little problem. The problem is that i need to map the printer up with a domain username and password. The users are logged on their laptops with local administrator, the computers are member of our domain but they cant log on with their domain users (for reasons i dont want to discuss here). I tought i just could use NET USE to map the printers with the same way as the home folders:

Net Use z: \\thvs02\elev05\Ahlefeldt\AF\USERNAME /user:USERNAME@DOMAIN PASSWORD

But it didnt work i think its because I have to edit something in regedit, i also thought of using:
rundll32 %systemroot%\system32\printui.dll,PrintUIEntry /in /n \\COMPUTER\PRINTERNAME /q

But by using this method you cant use a username and password to map the printer


Finally i have found this:

Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddwindowsPrinterConnection "\\SERVER\PRINTERNAME"

Is it possible to connect this way by using username and a password? How do i do it? All help is appriciated
 
 
Post #: 1
 
 RE: Script for mapping printers with username and passw... - 10/28/2005 1:51:03 AM   
  alienprotein

 

Posts: 44
Score: 0
Joined: 2/23/2005
From: USA
Status: offline
I don't know if it is possible to pass a username and password to the printer (Nor do I understand why one would need to), but I can share some of my login script what map's drives and printers. Perhaps you can add these laptops/users to a security group rather then passing a username and password.
 
This is your big problem.
quote:

The users are logged on their laptops with local administrator, the computers are member of our domain but they cant log on with their domain users (for reasons I don’t want to discuss here)
If you can get the users logging onto the domain using windows authentication then you will not need to pass a username and password to a printer.

 


How are the printers connected to the domain? (IP address or print server?)

Are the users logged on locally, able to access other network  (Domain) resources when connected to the local subnet?



**********************************************************
Option Explicit
'********************
'* Declare variables*
'********************
Dim objNetwork, objUser, strGroup, WshNetwork
Dim WScript, net
Dim currentuser
Dim Network
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set currentuser = GetObject("LDAP://" & objUser.UserName)
   strGroup = LCase(Join(currentuser.MemberOf))
'************************************
'*SETTING THE PRINTERS, FOR EVERYONE*
'************************************
Set net = CreateObject("WScript.Network")
   net.AddWindowsPrinterConnection "\\DA2UTL01\McK-15", "McK-15 (Color)"
   net.AddWindowsPrinterConnection "\\DA2UTL01\McK-20", "McK-20 (High Speed)"
   net.AddWindowsPrinterConnection "\\DA2UTL01\McK-30", "McK-30 (High Speed)"
   net.AddWindowsPrinterConnection "\\DA2UTL01\McK-40", "McK-40 (High Speed)"
'**************************************************************
'* SETTING ALL NETWORKDRIVES THAT ARE AVAILABLE FOR EVERY USER*
'**************************************************************
   objNetwork.MapNetworkDrive "q:", "\\da1fls01\files"
   objNetwork.MapNetworkDrive "H:", "\\Da2dc201\home\" & objNetwork.UserName
   objNetwork.MapNetworkDrive "G:", "\\da2dc201\working_files"
'********************************************
'*Installs Printers for the Tech Files group*
'********************************************
If isMemberOf("Tech Files") Then

   objNetwork.MapNetworkDrive "T:", "\\da1fls02\Lit_Support"
   net.AddWindowsPrinterConnection "\\DA1UTL01\AK-73 (TF)", "AK-73 (TF)"
   net.AddWindowsPrinterConnection "\\DA1UTL01\AK-74 (Color)", "AK-74 (Color)"
   net.AddWindowsPrinterConnection "\\DA1UTL01\AK-75 (TF)", "AK-75 (TF)"
   net.AddWindowsPrinterConnection "\\DA1UTL01\AK-77 (MF)", "AK-77 (MF)"
   net.SetDefaultPrinter "\\DA1UTL01\AK-73 (TF)"
End If


Function isMemberOf(group)
Dim user, found, temp
found = False
Set user = GetObject("WinNT://" & CreateObject("WScript.Network").UserDomain & "/" & CreateObject("WScript.Network").UserName & ",user")
For Each temp In user.Groups
If UCase(temp.Name) = UCase(group) Then
found = True
Exit For
End If
Next
isMemberOf = found
End Function

(in reply to FireNacho)
 
 
Post #: 2
 
 RE: Script for mapping printers with username and passw... - 11/1/2005 10:00:10 PM   
  FireNacho

 

Posts: 2
Score: 0
Joined: 10/26/2005
Status: offline
The reason i want to add the printers with a username is because we use a SafeCom printer system which gives the students a quota of 200 pages. The reason why we cannot use the domain is because of
som troubles we have with logging in becase we use wireless WPA authentication with RADIUS server. This is a project our school has, giving 180 students their own computer for use in class. And the solution here
is very bad planned. I just got hired half a year ago so i wasnt in the planning phase. But we decided to just let them map the printers with their local user (all of them have the same local username). The safecom system
recognize them all as one user so we cant use quota, but thats how we have to do it. If anybody knows how to map a printer with domain\username and password please tell me.

(in reply to alienprotein)
 
 
Post #: 3
 
 RE: Script for mapping printers with username and passw... - 11/1/2005 11:50:56 PM   
  mbouchard


Posts: 1894
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
2 possible options, both have not been tested

1. Authenticate to the server that the printer is on.  Net Use \\server /USERNAME:domain/user password then map the printer.  I know that I have done this manually when logged on as local Admin.

2. Take a look at AutoIT, www.hiddensoft.com, it has a function called RunAsSet, which essentially initializes a users crendtials during a Run operation.  I have used this to elevate a regular user to admin which allowed me to run a vbscript as an admin.  If you go this route, you could create an AutoIT script that contained input boxes for the username and password of the user.  It would then use RunAsSet, set the user context, run your vbscript to map the printer then reset the userrights.


One question, have the laptop users ever connected to the domain using the "wired" NIC instead of the wireless one?  Reason I ask is that where I work, we also have had issues when trying to log onto the domain wirelessly and found that, mostly on XP, if a user logs in while physically connected to the network their username/password is cached locally.  So, they could log on as themselves where ever they are, be it in the building or at home.  They would only have access to the domain when they were are work.  Sometimes they were able to run our login script but most times, after logging on, they would need to manually run the script.  But they would have full access to the domain.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to FireNacho)
 
 
Post #: 4
 
 RE: Script for mapping printers with username and passw... - 1/10/2006 12:35:42 AM   
  Bartman

 

Posts: 11
Score: 0
Joined: 12/22/2005
Status: offline
This is a script I use to map users who are not on my domain to the shared drives.
Perhaps it will work for you printer as well.

As I am a beginner to vbs I can't guarantee this will work for you. But it has been tested and used here. But as you can see it is a very basic, simple script.

I run this locally, not across the network. I would think you could edit it to work across the network but I don't know for sure.

********** Script **********************

option explicit
dim u_name, p_word
on error resume next
u_name=inputbox("Enter your user name: ")
u_name="IMR\" & u_name
msgbox "The name you entered was " & u_name
p_word=inputbox("Enter your password: ")
'msgbox "The paswword you entered was " & p_word
Dim network
Set network = Wscript.CreateObject("WScript.Network")
'Clear network drive mappings first

'Map to the network dirves
ON Error Resume Next
network.MapNetworkDrive "N:", "\\ServerName\Apps", "True", u_name, p_word
network.MapNetworkDrive "P:", "\\ServerName\Public", "True", u_name, p_word
network.MapNetworkDrive "S:", "\\ServerName\Shared", "True", u_name, p_word
network.MapNetworkDrive "M:", "\\ServerName\Software", "True", u_name, p_word
network.MapNetworkDrive "I:", "\\ServerName\IT", "True", u_name, p_word

**************** End Script *************************

< Message edited by Bartman -- 1/10/2006 12:39:00 AM >


_____________________________

BARTMAN!
Watch it dude!

(in reply to mbouchard)
 
 
Post #: 5
 
 RE: Script for mapping printers with username and passw... - 1/10/2006 1:45:08 AM   
  DiGiTAL.SkReAM


Posts: 1170
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Try using:

'Method#1
Set oNet = WScript.CreateObject("WScript.Network")
oNet.AddPrinterConnection("Printer1","
\\server\printer",False,"domain\username","Password")

The .AddPrinterConnection allows username/password to be passed to it, but the .AddWindowsPrinterConnection method does not.

Give it shot, it may work for you.  Otherwise, I would suggest doing what mbouchard suggested with a little bit of what Bartman said, and connecting to the IPC$ share on the server and then mapping the printer like so:

'Method#2
sUserName = InputBox("Please enter domain username","User Logon Prompt")
sPassword = InputBox("Please enter the password for " & sUserName, "Password Prompt")
Set oNet = WScript.CreateObject("WScript.Network")
oNet.MapNetworkDrive "","
\\server\IPC$",False,"domain\" & sUserName,sPassword
oNet.AddWindowsPrinterConnection "
\\server\printer"

Either way should work, however I would think that method#2 would give the best results.

< Message edited by DiGiTAL.SkReAM -- 1/10/2006 1:50:10 AM >


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to Bartman)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script for mapping printers with username and passwords Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts