QTP Vbscript function to map and unmap/remove network drive with user name and password :
Hi friends I want to share you one more advance qtp script. I hope you will learn lots of things from this post.
Problem: How to map and unmap/remove network drive with user name and password in VBscript using QTP.?
Solution: Modify server name, user name and password and just write following function in Test file of QTP.
‘Call above function in your Test file of QTP with directory name that you want to share as argument.
Public function drive_mapping(byval strShareName)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objNetwork = CreateObject(“WScript.Network”)
strLocalDrive = “E:”
strRemoteShare = “\\server\”&strShareName&””
strUsr = “myusername”
strPas = “mypassword”
‘Following loop will remove the maaped drive on E:
objNetwork.RemoveNetworkDrive strLocalDrive, True, True
‘Following command will map the drive.
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, true, strUsr, strPas
You are always welcome if you face any issue with above VB script function.