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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a login script 5

Status
Not open for further replies.

RockChalk

Technical User
Sep 18, 2003
136
0
0
US
I tried reading thru all the post about login scripts and I don't understand. Can someone tell me how to take a simple login script that maps our users to a userdata folder?

Here is the script.
net use H: \\servername\userdata

I saw that you ready shouldn't use your main domain controller to handle scripts. Is that right?

RC
 
If all you want to do is map a drive, here is what you will need.

Code:
On Error Resume Next
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True

If you want a more comprehensive solution, give this script a try.

Code:
'==========================================================================
'
' NAME: LogonScript
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================


ON ERROR RESUME NEXT

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
DomainString = "DomainName"
UserString = WSHNetwork.UserName

Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

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


WSHNetwork.RemoveNetworkDrive "F:"

wscript.sleep 300

'Maps drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",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
	Case "Admin"
		WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
	Case "WorkerB"
		WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True

End Select

Next


'Install Printers

WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"

set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing

wscript.quit

Regarding where to put this, add your script to a Group Policy. It will automatically replicate to all DCs.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I am assuming you need the simple answer.
The login script is in the \WINNT\System32 directory and is called "Usrlogon.cmd".
 
if you are using active directory:

create a file that has
net use h: \\server\sharename

call it logon.bat

put that file in \\domaincontrollername\netlogon

then you can map the script using AD users and computers in the account settings.....or use group policy

 
I would personally advise against using BAT or CMD files.

VBScript has in my opinion become the new standard both because of performance and flexibility.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
markdmac,

I do not disagree with you that vbscript is more flexible or performs better. No offense to Rockchalk, but do you think that if someone has questions about setting up logon scripts, that they have taken the time to learn VBscript?

Sometimes the best answer is the one that is most practical for a user's level.
 
Our AD has numerous scripts setup as "swabs" descibes, and we use solely VB Scripts... if you know how to write them, you can practically tell their PC to wipe thier nose for them with a good script!

Anyway, I would have to say that SWABS description was best, and that VBS is better than Batching the scripts. And yes, the scripts will be replicated automatically just in case one of the Controllers dies.
 
Hi guys.

I'm a newbie and would like to get started on a script, I know a little VB and VBA so I am hoping VBS is not that much of a jump. Also, for what I need, I hope I don't need to know much VBS anyway.

Put simply:

Running Windows 2003 SBS as DC and would like it to map a few drives for users as they logon.

I want to create custom user groups as these will have privileges set-up on folders residing on the DC or a slave on the DC for file storage of different types.

Is it possible to create a script that will only map certain drives for certain user groups...?

I'm willing to spend some time on this and will probably want to run some anti-virus software or some such thing at some point but for now, mapping drives will keep me happy.

Any help at all would be greatly appreciated. [colorface]


-----------------------
Michael Mason
Arras People
-----------------------
 
HarlequinAtWork, I would suggest Kixtart ( While VBScript is great, I honestly prefer using Kix for 100% of my scripting. It has built in fuctions to enumerate groups and handle all of the things that you might want to do in a login script.

It's very dynamic, and very powerful.

For the original question, in kix the script would look like;

use H: "\\servername\userdata"

If you wanted to get fancy and add logic you'd just do;

if InGroup("GetHDrive") = 1
use H: "\\servername\userdata"
endif

And build any other logic that you want from there. It's very easy to set up, you just download the runtimes, dump them in the netlogon share, and add the script to the users profile. (You'll find Login Script path on the profile tab of the users properties in AD).

I'd really suggest checking it out.
 
Thanks Travis.

I knew my learning curve would be steep but have been using Tek-Tips for development stuff for a while now.

I'll post a reply over the next few days and let you know how I got on if that's OK.

-----------------------
Michael Mason
Arras People
-----------------------
 
I posted a script above that does exactly what you are asking for. Did you review the entire thread?

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thanks Mark

I missed the "Groups" section...!

I assume I simply replace the batch file with a VBS file.Also, the standard batch file calls out an EXE file in the first line. Any idea what this is because if a regul;ar user logs on it comes up with a dialog box saying they do not have admin priviliges to run a proram (it doesn't say which program) I am assuming this is the program called out in the logon batch file though.

-----------------------
Michael Mason
Arras People
-----------------------
 
When you implement this as a login script in a Group Policy it can run with elevated priviledges. There is a GPO setting for that.

You will want to use Wscript.shell with a Run command
For example:
Call WSHShell.Run("cmd.exe /C md C:\MyDir")

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
markdmac is coming up with some good stuff. I myself am with markdmac on scripting. To me, WorldofJohnBoy's comment about wiping people's noses is right on. You can do so much more with scripts than .bat. For example, having a database populated with requested information (processor speed, RAM, who is in the administrator group, etc., etc.)on all of the PC's in your OU or domain. I'm not so sure you can do that with a .bat, but then again, I never tried because VBScript was just easier.

Scripting makes life easier. As a friend of mine said, scripting allows for more BT (Beach Time).
 
LMAO...!

I've developed a few VB apps over the past few months and although Third party apps are friendly, I fell that I really need to get to grips with VBS. That way, if it goes wrong I can roll up my sleeves and put it right (I hope).

Again, thanks for the posts.

-----------------------
Michael Mason
Arras People
-----------------------
 
Mark,
Looking at your above script i came up with a couple of questions.
1. The script looks perfect for my scenerio, which is as follows; we have groups that get specific drive mappings and we have a few generic mappings that all get. This should pretty much do all that now, right?

2. I am new to vbs, second week of learning actually, and was wondering if you had any tips for me. We are implenting AD2003 next week and we want to convert our current login scripts which use KixTart.

Thanks in advance,
 
Great, I will be able to test it today... I have modified it to reflect our enviornment. Today we are creating our domain and test accounts. One question I have is; At the bottom of the script there are five set objects. what can i do with them ?

Thanks,
 
You are refering to:

set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing


This is just a good practice to clear the memory used by the script before actually exiitng the script. It will work without them, but I've been working on improving my error checking and best practices, so I have put that in.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top