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!

Logon to domain and map drives

Status
Not open for further replies.

rubbersoul

IS-IT--Management
Mar 20, 2003
88
CA
What I need to do is write a script that will pop up a box prompting for a username password and domain....once there it'll take those values and use them in the rest of the script to map a drive to the local machine.

I've connected to my network using a VPN client and can ping everything....however I need to authenticate in order to map drives.....this is what I have so far and it's not working. The index.htm pops up and I put in my username, password and domain....but then it errors out when it trys to run the rest of the script....help please




Dim strUserName
Dim strPassword
Dim strDomain

Set objExplorer = WScript.CreateObject _
("InternetExplorer.Application", "IE_")
objExplorer.Navigate "file:///c:\scripts\index.htm"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 250
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
Do While (objExplorer.Document.All.OKClicked.Value = "")
Wscript.Sleep 250
Loop
strUserName = objExplorer.Document.All.UserBox.Value
strPassword = objExplorer.Document.All.PasswordBox.Value
strDomain = objExplorer.Document.All.DomainBox.Value
objExplorer.Quit
Wscript.Sleep 250

Dim WSHNetwork
Dim FSO
Dim ObjGroupDict
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set strUserName = WScript.CreateObject("WScript.UserName")
'Set strPassword = WScript.CreateObject("WScript.Network")
Set strDomain = WScript.CreateObject("WScript.UserDomain")


'
' Wait until the user is really logged in...
'

strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend

strDomain = WSHNetwork.UserDomain

' Map F: drive to their home folder
WshNetwork.RemoveNetworkDrive "F:"
WScript.Sleep 100 ' 1/10 th of a second
WSHNetwork.MapNetworkDrive "F:", "\\YULSP545\" & WSHNetwork.UserName & "$"



 
[1] Your script functional parts are _not_ working together very well.
[2] How do you be so sure that strUserName, strPassword, strDomain are filled? You have to device a loop to wait until they are all filled before issuing .quit instruction.
[3] There are no such thing as WScript.CreateObject("WScript.UserName") or WScript.CreateObject("WScript.UserDomain"). If your use of wscript.network is correct, then username and domain are exposed by it. (Check the documentation.)
[4] mapnetworkdrive can be done by explicitly furnishing the user's credential. The downside is the password is in the clear, maybe that's not a concern.
documentation said:
Adds a shared network drive to your computer system.

object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword])
Arguments
object
WshNetwork object.
strLocalName
String value indicating the name by which the mapped drive will be known locally.
strRemoteName
String value indicating the share's UNC name (\\xxx\yyy).
bUpdateProfile
Optional. Boolean value indicating whether the mapping information is stored in the current user's profile. If bUpdateProfile is supplied and has a value of true, the mapping is stored in the user profile (the default is false).
strUser
Optional. String value indicating the user name. You must supply this argument if you are mapping a network drive using the credentials of someone other than the current user.
strPassword
Optional. String value indicating the user password. You must supply this argument if you are mapping a network drive using the credentials of someone other than the current user.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top