QTP Vbscript function to map and unmap/remove network drive with user name and password

By | June 6, 2009

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.

– drive_mapping(“sharedirectoryname”)

‘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:
if(ObjFSO.DriveExists(strLocalDrive)) then

objNetwork.RemoveNetworkDrive strLocalDrive, True, True

end if

‘Following command will map the drive.

objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, true, strUsr, strPas

end function
—————————————————————
You are always welcome if you face any issue with above VB script function.

If you like this article, You can subscribe through mail.

2 thoughts on “QTP Vbscript function to map and unmap/remove network drive with user name and password

  1. Anonymous

    I need to schedule smoke script which is stored Network Drive daily basis. I m using MS DOS Batch Script to Schedule the script which in turn call VB script and Runs the Script.
    IF the script stored in Local Drive it works. But not from Network Drive can u Help me regarding this????

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *