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

problems with simple vb script

Status
Not open for further replies.

heskez

MIS
Aug 8, 2007
9
NL
Hi, I'm having problems with a login script on a W2k3 Server. I would like a simple login script to set a new user with correct profile and homedrive setup when the new user logs on.

I managed to gather some info and combined it into this script:

ON ERROR RESUME NEXT

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


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString = WSHNetwork.UserName

strUser = objUser.userstring
strHomeDirectory = "\\ADD001\home\" & struser
objUser.homeDirectory = strHomeDirectory
objUser.homeDrive = "H:"
objUser.SetInfo

Unfortunatley this doesn't do the trick..

I am still a rookie concering vbscripting, so I'd appreciate some help in here.

 
What is supposed to be objUser ?
Tip: Use the Option Explicit instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for you comment.

Do you mean something like this?

Option explicit

strUser = objUser.userstring
strHomeDirectory = "\\ADD001\home\" & struser
objUser.homeDirectory = strHomeDirectory
objUser.homeDrive = "H:"
objUser.SetInfo

objuser is supposed to be the queried LDAP Value form the Active Directory.

I think I'm mixing op 2 variables.

When I replace the objuser for struser should that be fine?

And is the goal, providing a useraccount with homedir during logon, as easy to achieve as I think it is? Or do I need more advanced scripting technologies?
 
objuser is supposed to be the queried LDAP Value form the Active Directory
Which query ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I notice I didn't post the correct script. I mean this one:

On Error Resume Next

Sub AssignHomeDir()
Set objOU = GetObject("LDAP://rocmn.lan/OU=scripttest,DC=rocmn,DC=lan")
ObjOU.Filter= Array("user")
For Each objUser in objOU
strUser = objUser.Get("sAMAccountName")
objUser.Put "homeDirectory", "\\ADD001\home\"& strUser
objUser.Put "homeDrive", "H"
objUser.SetInfo
Next

End Sub
 
It looks like the scipt is executed but nothing happens..
No error messages or anything. It just dies silently.
 
No error messages or anything
What happens if you comment out the On Error Resume Next instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Change at least this.
>objUser.Put "homeDrive", "H"
[tt]objUser.Put "homeDrive", "H[highlight]:[/highlight]" 'colon is required[/tt]
 
Thanks, I'll change it. I'm still wondering if it is possible to achieve a goal like this with such a small amount of code..
 
>What happens if you comment out the On Error Resume Next instruction.
>>Exactly the same...
I take it no runtime error??? You put the block in a sub, I hope you did call the sub???

Now, there are hidden conditions for the script to succeed.

[1] You've to have the share setup in place for the unc.

[2] For win2000+, the mapping is automatic during logon. But for win9x, you've to map it every time during logon using figuratively this.
[tt] createobject("wscript.network").MapNetworkDrive objUser.HomeDrive, objUser.HomeDirectory
[/tt]
 
Sub is not called. I don't know how to do this in this context..

 
>Sub is not called. I don't know how to do this in this context..
I don't know what to say! Maybe you should consult your colleagues after all. Doing this is not risk-free, may not be disastrous if going wrong but certainly a lot of annoyance for those users inside the ou. Experimental setup? okay?
[tt]
[blue]AssignHomeDir[/blue]

Sub AssignHomeDir()
'etc etc
End Sub
[/tt]
 
Thanks, I've fixed it.
No users are harmed, I've created a test server setup.

I'm now getting en error on line 6 wich says:
Can't find object on the server

Which is this line of the code:

Set objOU = GetObject("LDAP://rocmn.lan/OU=scripttest,DC=rocmn,DC=lan")

I'm wondering If this is the right way to do it because it affects all users in the OU? I need only the current logged on user.
 
I'm getting closer..

After loggin on as a normal user (script applied on A useraccount in the ou) I'm getting an access denied error on line 10 which is this line:

Set info

Maybe a startup script intead of a logon script will do the trick?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top