Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Yet Another Logon Script Question 3

Status
Not open for further replies.

HessA

MIS
Mar 17, 2005
176
US
I have Markdmac's logon script edited for my use and I love it. However there are at least 2 things right now I would like to add.

How do I add a line to map a user's home directory as H: drive in Vbscript?

Is there a way to choose which printer that is connected via the logon script becomes the default? (at the moment whichever printer I have set to connect first is the one that becomes the default)

Thanks in advance,

Aaron

 
These should help.

To map a network drive.

WSHNetwork.MapNetworkDrive "H:", "\\server\share"

To set a default printer

Network.SetDefaultPrinter "\\server\Printer"

"Horsey to king bish three
 
I haven't seen Marks VB script but i imagine it's fairly comprehensive as usual, so those might help but they might not depending what he has already set in his script.

"Horsey to king bish three
 
The default script line will work fine. However the drive mapping one won't. I will be more specific. I want something like in dos where it's /home blah blah blah where it picks the path form the users profile tab in AD. Or automatically uses a share name equal to the username. Otherwise I would have to have a line for each individual users to map H as all the share names are different. Thanks very much for the post the printer line is great I will add that right now.

Thanks,

Aaron
 
Not a problem. My script already grabs the user name as a variable, so you can map that way. Something like this:

Code:
WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True

I keep promising myself to move my script to an FAQ some time this week. Gotta remember to add this as an example. :)

I hope you find this post helpful.

Regards,

Mark
 
Mark I had a question about the line you posted above. I know that server and users needs modified by me but I am unsure now. If I specify a specific user then the line is good only for that user? What am I getting wrong? I think I am missing something that I am not understanding.

Thanks,

Aaron
 
As long as you have the following lines in your login script, you should be fine:

Code:
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Grab the user name
UserString = WSHNetwork.UserName

In Mark's login script, these identify the domain, and the username that logged into the domain. There should not be any "constants" that you put in there. Basically, I would go back to Mark's login script and recopy what is there.

If need be, here is a link:


FAQ329-5798
 
Thanks Tfg13 it seems I was using a truncated version of Mark's script I am checking it against the one in the fact for any missing lines that pertain to getting the Username enumerated for that line to work for the mapping. Thanks for the link.

Aaron
 
Hope you find the FAQ helpful. Let me know if you still don't understand something after reading through it.

I hope you find this post helpful.

Regards,

Mark
 
Tfg & Mark

I must be missing something obvious. I have everything required for the drive mapping but I am still unsure how to modify the H: drive mapping line so that it dynamically maps for whoever logs in. I am going to post my script could one of you see if there is anything missing or possibly in the wrong spot. When I first added the default printer line the Tfg posted I had it in the wrong spot and after putting it in the right part of the script it worked great. So I may have just inserted a line in the wrong spot. Thanks again guys.

ON ERROR RESUME NEXT

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


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\192.170.70.19 /set /y"


'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
WSHNetwork.MapNetworkDrive "U:", "\\salinesnap1-new\salineshare",True
WSHNetwork.MapNetworkDrive "w:", "\\salinesnap1-new\mtishare",True
WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
Case "Domain Admins"
WSHNetwork.MapNetworkDrive "m:", "\\salinesnap1-new\mis",True
'Case "WorkerB"
'WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
WSHNetwork.SetDefaultPrinter "\\nav-gtwy-dc\mis"
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 Printers
WSHNetwork.AddWindowsPrinterConnection "\\nav-gtwy-dc\SalFrontCopy"
WSHNetwork.AddWindowsPrinterConnection "\\nav-gtwy-dc\MIS"
WSHNetwork.AddWindowsPrinterConnection "\\nav-gtwy-dc\FrontColor"
WSHNetwork.SetDefaultPrinter "\\nav-gtwy-dc\mis"

' This section of script will prevent the baloon window that appears when printing
' to a network shared printer after XP Service Pack 2 is installed.
'=====================================

Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"

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

Call WSHShell.Run("cmd.exe /C \\server\dir\dir\dir\exe")

'Quit the Script
wscript.quit
 
Ah, you made me sad. You removed my credit for my script. [sad]

But to try and help you we need to know more about your environment.

The question is is your server name Server?

Is there a share on Server called Users?

Also, why do you have this line Call WSHShell.Run("cmd.exe /C \\server\dir\dir\dir\exe")?

Do you really name directories Dir and nest them with the same name 3 levels down?

I hope you find this post helpful.

Regards,

Mark
 
Actually that cmd line was the line you gave me to run an audit software during the script I probably forgot to modify my specifics as in the server name and the directory name. You'll also be happy to know that your credit is on my script I just didn't include it in the copy and paste I did on that post. But it is on the script on my server =)

Ok the server name is \\salinesnap1-new\
There is no share called users that was the placeholder you used in the post where you gave me the line to add to the script. The user directories are all shared with the username as the name of their shared home directory. I was unclear what to edit the line with. The server is clear it would be the one I just mentioned but if I specify the actual share for the user I don't understand how it would dynamically map for which ever user had logged in. My understanding by the earlier enumeration of the username in the script some how that is used to decide what directory is mapped. But if I specify the specific share to map I don't understand how it would be dynamic. Any light you can shed would be great.
 
HessA,

Change this line
Code:
WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True

To this line
Code:
WSHNetwork.MapNetworkDrive "H:", "\\salinesnap1-new\" & UserString,True


In the original example, it would require a share called users. For example \\salinesnap1-new\users and then under that it would append the user name. Since your user names exist as shares directly off of the server, then there is no need for this extra directorty reference.

This script does many things, if you look at the top where it sets the UserString, it does so by just looking at the network login name. We use that information to bind to the user object to determine what groups the user belongs to, but we have already established the username, so we can use that as a variable elsewhere.

Thanks for keeping the credit. I'm happy again. :)

I hope you find this post helpful.

Regards,

Mark
 
Rock on that's the question I needed answered and of course it makes perfect sense now. BTW I modified that .exe call at the cmd line you gave me and amazingly enough when I didn't have \\server\dir\dir\dir\exe and had my server name directory names and the actual executable name in there it works lol. So thanks for pointing out 2 things!

Aaron
 
Glad that worked.

If you have not checked the FAQ recently you may want to do so. I've been adding "Add Ons" about 1 a day.


I hope you find this post helpful.

Regards,

Mark
 
I will take a peak at the FAQ to see if anything new I want to do is in there. There is definitely more I plan to do with my script. It's been a little hard learning it because it is new. But with your help it's been deceptively easier. I can't say how much your posts and code and faq have helped me so far.

Thanks,

Aaron
 
For testing purposes, I want to map several network drives, but test it on my account prior to implementing.

Reading through, I wasn't sure how to specify a single user in the domain and execute the script.

Would appreciate an example of that, and very good job on the FAQ.
 
I created an OU put myself in it and applied a new Group Policy to it that included the script I have been perfecting.

Aaron
 
You can do what Aaron (HessA) did or you can also do this since we are already grabbing the user name:

'User Specific Actions
If Ucase(UserString) = "QUARKIT" Then
Commands you want to execute
End If


If you want to do more than one user for a one-off situation you should use a Select Case statement as I have doen for the groups.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top