How do we map network drive automatically using Nant script?
Use the exec task with net.exe command.
The following example attempts to map drive P: to network location = \\192.168.12.1\c$ using domain = testDomain and domainUserLogin = userid with password = bob.
The " is to enclosed the network path and the password.
<exec program="net" commandline="use P:$html_quot$\\192.168.12.1\c$ $html_quot$ /user:testDomain\userid $html_quot$bob$html_quot$ ">
</exec>
The actual dos command to map network drive look like this:
net use P: "\\192.168.12.1\c$" /user:testDomain\userid "bob"
How to disconnect the network drive then?
Use the following dos command to disconnect drive P :
net use P: /DELETE
Nant script equivalent:
<exec program="net" commandline="use P: /DELETE">
What if we want to verify the map drive existed?
<if test="${directory::exists('P:')}">
<exec program="net" commandline="use P: /DELETE "/>
</if>
Dos command reference [net use] to map network drive
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment