Login Script use Visual Basic Script – Sample

Posted on


‘    Script:   Test.vbs
‘    Purpose:  Login domain         
‘    Author:   Deddy Iswara
‘    Date:     1 April 2007
‘————————————————-

Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strUserName, str1, str2
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive

strDriveLetter1 = “M:”
strDriveLetter2 = “N:”
strDriveLetter3 = “O:”
strRemotePath1 = “\\server\app
strRemotePath2 = “\\server\public
strRemotePath3 = “\\server\usertemp$\

Set objShell = CreateObject(“WScript.Shell”)
Set objNetwork = CreateObject(“WScript.Network”)
Set CheckDrive = objNetwork.EnumNetworkDrives() 

str1 = strRemotePath1 & “$”
str2 = strRemotePath2 & “$”
strUserName = objNetwork.UserName

On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count – 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter _
Then AlreadyConnected =True
Next

If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter1
objNetwork.RemoveNetworkDrive strDriveLetter2
objNetwork.RemoveNetworkDrive strDriveLetter3
objNetwork.MapNetworkDrive strDriveLetter1, str1
objNetwork.MapNetworkDrive strDriveLetter2, str2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 & strUserName
Else
objNetwork.MapNetworkDrive strDriveLetter1, str1
objNetwork.MapNetworkDrive strDriveLetter2, str2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 & strUserName
End if

Wscript.Quit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s