Question

Network printer & drivemapping logon script

Asked by: ecszone

I want a vb script that runs something like this.
I understand "ingroup" is something used by a program called kix?   SO i need the vb or whatever equivilent

I found lots of examples online but did not know how to modify it.  I dont know anything about vb.  Sometime si can hunt out what are changeable variables if its sepcified.. but I cant seem to get this working.  I will basicly check AD group membership and if they have it, map the printer/drive.  This shoudl be way easier than it is.  I cant belive i couldnot find something like this that i could understand  :(   help greatly appreciated!   Please make it clear what I need to change. (server name, group name etc)

If InGroup("Domain Users") then
Use m: "\\server\public"
EndIf
 
If InGroup("Domain Users") then
Use P: "\\vault\%username%.%userdomain""
EndIf
 
Set objNetwork = CreateObject("WScript.Network")
 
If InGroup("Shipping") then
objNetwork.AddWindowsPrinterConnection "\\server\Shipping"
EndIf

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-11 at 07:23:18ID24643205
Tags

visual basic scripting citrix windows networking

Topics

VB Script

,

Scripting Languages

,

Windows Networking

Participating Experts
2
Points
500
Comments
12

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. black screen on SiS 5597 X startup
    Linux-Red Hat 6.1 screen blanks out on starting up X AMD K-6 266 Mhz 64 MB RAM onboard SiS 5597 video and CMI 8330 sound, USR 56k ISA modem, Lexmark 1100 printer and Visioneer 3100B scanner Mike Burgess mwburgess@teacher.esc4.com While the video adapter works for a few boot...
  2. Printer Logon Scripts
    My shop has multiple departments (sales, service, corporate, supplies, and IT). I would like to create logon scripts assigning certain printers to each department. For the administrator I would like to have all the print drivers no matter what PC I logon on to.
  3. logon scripts printers and network drives
    I have a 2000 server with a hp local printer, the server is being used as a print server and sometimes when users logon on they cannot see it. Therefore it would be nice to know how to put this into a logon script. Also there are drives that are shared but one user cannot see...
  4. HP4 SI printer text on bottom of page greyish and smuged
    Hello, My HP4 SI printer has been acting strange laterly. The printer smugeds the text on the bottom of the page sometimes. I would say it prints 1 out of 25-30 pages like that. I have tried changing the toner - nothing happened. Tried cleaning the machine - no change. ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: wiscomPosted on 2009-08-11 at 07:46:34ID: 25069677

Hi,

Try this one : FastTrack Scripting Host

FastTrack Scripting Host is a complete replacement for VBScript/WSH, Bat files, PowerShell and all other scripting tools. Once you tried FastTrack, you will never use any of them again. You can create logon scripts, install scripts, backup scripts, administrative tasks and anything else you use scripts for with awesome end-user GUI, easier than you could ever imagine! You don't need programming skills and you don't need to deploy anything to the clients. Your scripts will be very easy to read and will be less than 10% in size of what you already have. If you think this is too good to be true, just download it and try it out yourself! Find out why we already serve more than a million workstations.

http://www.fasttrackscript.com/

You can download a full trial version !!!

Go for it.

A/

 

by: selva_konguPosted on 2009-08-11 at 08:12:01ID: 25069966

;=============================================
;Map Network Drives
;=============================================

If InGroup("_Drive_S_Drive")
Use S: "\\SERVER\Data"
EndIf

If InGroup("_Drive_P_Drive")
Use P: "\\SERVER\Public"
EndIf

;=============================================
;Map Printers
;=============================================

If InGroup("_Printer_HP_M1522NF")
ADDPRINTERCONNECTION ("\\SERVER\HP Laserjet M1522NF")
EndIf

If InGroup("_Printer_HP_P2014N")
SHELL 'con2prt /cd "\\SERVER\HP Laserjet P2014N"'
EndIf

save the above code in connect.kix file and read the following guide

If InGroup("_Drive_S_Drive")
Use S: "\\SERVER\Data"
EndIf

\\SERVER\Data - is Share path

This means it will map the S:\drive if the user is part of the "_Drive_S_Drive" security group in Active Directory. This is helpful if you are wanting to map a network drive based on a user's security group membership. Therefore, if they are not part of that group, that drive doesn't get mapped for them. If they try to map it manually, it won't let them because you would have put security on that share.
*****************************************************************************
If InGroup("_Printer_HP_M1522NF")
ADDPRINTERCONNECTION ("\\SERVER\HP Laserjet M1522NF")
EndIf


This means it will map the printer (HP Laserjet M1522NF) if the user is part of the "_Printer_HP_M1522NF" security group in Active Directory. This is helpful if you are wanting to map a printer based on a user's security group membership. Therefore, if they are not part of that group, that printer doesn't get mapped for them. If they try to map it manually, it won't let them because they won't have the permissions to. You can also change the group to be "Domain Users" instead. Then add all printer shares to it. What that then means is everyone will automatically get all the printers in their organisation mapped for them during login.
*************************************************************.
If InGroup("_Printer_HP_P2014N")
SHELL 'con2prt /cd "\\SERVER\HP Laserjet P2014N"'
EndIf

This means it will set the HP Laserjet P2014N printer as the users default printer if the user is part of the "_Printer_HP_P2014N" security group in Active Directory. This calls on the con2prt executable to connect to that printer and set it as the users default printer. More information about the con2prt tool can be found here - con2prt.exe - Map, delete, and set default printer. This is helpful if you want to automatically set a user's default printer for them. It works well if you create this for all your printers and add users to their appropriate group. Then, if the user moves to a different location in the building and needs a different printer as their default, just add them to the other printer group.


The easiest way is in your normal login script, call on the kix file. The example kix file mentioned on page 1, I save as connect.kix. What I then do is create a login.bat batch file (or you can modify your existing login batch file) and in that file, include this one line:


%0\..\kix32 %0\..\connect.kix
 
The line above just calls on the KIX32.exe program (which also needs to be installed on the same location as the login.bat file, generally on the servers's NETLOGON share) to run the connect.kix file

you can down load the sample kix file and KIX32.exe and con2ptr.exe from following link

http://thisishelpful.com/plugins/p13_download_manager/getfile.php?categoryid=10&p13_sectionid=1&p13_fileid=5&p13_versionid=6

 

by: ecszonePosted on 2009-08-11 at 08:23:30ID: 25070113

Selva, I dont have kix. I dont even know what it is.
im looking for a simple method that does not require any additional software.
We dont use netlogon.. that was for windows NT4??  we use active directory. "sysvol".
I mean netlogon still exists but i use GPO to push out scripts.

 

by: ecszonePosted on 2009-08-11 at 08:27:40ID: 25070156

wiscom im not looking to spend alot of money to do this simple task.  
i could do this on my own using a gpo for every group i want a script applied to. That waht Ill do if nobody can help me with this.

 

by: selva_konguPosted on 2009-08-11 at 08:33:51ID: 25070220

'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : http://www.thespidersparlor.com
' Copyright (c) 2003-2007
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'          Maps and disconnects drives and printers
'
'==========================================================================
ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'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 UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName


'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:", True, True

'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
   WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
'Note alternate mapping code in Add-In section that allows
'friendly renaming of drive mappings

WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True
'Map a shared drive to a resource that requires separate username and password
WSHNetwork.MapNetworkDrive "Y:", "\\servername\share", "False", "username", "password"

'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.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.
       Case "ADMIN"
           WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
       Case "WORKERB"
           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

'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
   If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
     WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
   End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next

'Remove a specific printer
WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
                               
'Install A Printer
WSHNetwork.AddWindowsPrinterConnection
\\Server\HP5si


'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
 
'Quit the Script
wscript.quit

 

OK, so now you have a bunch of nifty code.  So what to do with it right?

OK, first copy the text and put it into notepad.  Save the file as something useful like "loginscript.vbs" and use the quotes around the name as shown here.  Using the quotes in notepad will prevent notepad from adding a TXT extension on the name.

OK, now you are ready to put the script on your server.  If you started navigating to the Netlogon share forget it.  Time to use GPOs!

Creating a new GPO in Windows 2000,2003 and 2008 is a bit different.

In Windows 2000, you want to right click your domain name in AD Users & Computers.  Choose properties.  Click the GPO tab.  

Click New.  Type Login Script.  Click the Edit button.

Windows 2003 and 2008 users will want to open up the GPMC, Start, Administrative Tools, Group Policy Manangement Console (GPMC).  

Right click your domain and choose Create and Link a GPO here.  Type Login Script.  Right click Login Script and choose Edit.

If you are using Windows Vista, Windows 7 or Server 2008 you will need to consider additional GPO settings to work with the enhanced security introduced by Vista.  The following Microsoft Technet article discusses these changes and how to configure GPOs to allow drive mappings etc. to work. http://technet.microsoft.com/en-us/windowsvista/aa940985.aspx
OK, moving on you want to maximize your performance, so if you are only going to use this GPO for the login script, right click Administrative Templates under either the Computer or User container. Click Add/Remove Template and remove ALL templates.  

You won't need them and they only beef up the size of your GPO which slows down replication.

OK, now drill down in the User Configuration.  Choose Windows Settings, Scripts, Login.  Double click Login.
Click Show Files.  Paste your script in this location.
Close the explorer window that you just pasted into.  Click the browse button and select your script.  You are now done.

By default your new GPO is applied to All Authenticated Users.  You may wish to modify the security settings as needed in your environment.

 

by: ecszonePosted on 2009-08-11 at 08:33:58ID: 25070221

im actually taking a quick look at kix.  i see from your link its free.  i have not ruled this out yet.

 

by: ecszonePosted on 2009-08-11 at 08:35:59ID: 25070245

ok going to dig through this vbs and ill let you know how i make out! looks like it has some nice noob instructions at the bottom :D

 

by: selva_konguPosted on 2009-08-11 at 08:39:50ID: 25070300

For more details please refer the following link

http://www.tek-tips.com/faqs.cfm?fid=5798

 

by: ecszonePosted on 2009-08-11 at 15:55:21ID: 25074293

stuck.
assume servername =server  user=bob domain=microsoft

my user drive path is similar to this path
\\server\users\bob.microsoft
i tried this
WSHNetwork.MapNetworkDrive "U:", "\\server\users\ & UserString & "." & DomainString",True
getting path not found.

via cmd i would accomplish this with \\server\users\%username%.%userdomain

 

by: ecszonePosted on 2009-08-11 at 16:16:35ID: 25074427

I also stole the code from map drives using group membership. can i do that/
it works as far as mapping printers. but it is not setting a default! :(

see below


'***********************Map Printers based on group************************************************
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.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.
       Case "PRINTGROUP-SHIPPING"
           WSHNetwork.AddWindowsPrinterConnection "\\server\SHIPPING"
       Case "PRINTGROUP-SHIPPING"
	   WSHNetwork.SetDefaultPrinter "\\server\SHIPPING"

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: selva_konguPosted on 2009-08-11 at 21:09:54ID: 25075701

First install the printer and then set the default printer
try this
       Case "PRINTGROUP-SHIPPING"
           WSHNetwork.AddWindowsPrinterConnection "\\server\SHIPPING"
           WSHNetwork.SetDefaultPrinter "\\server\SHIPPING"

 

by: ecszonePosted on 2009-08-12 at 08:15:33ID: 25079590

That fixed the printer problem.  did you see my question above that?  about
about maping drive with the folder name being username.domainname?

if you dont know ill accept your answer and repost.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...