Thursday, February 22, 2007

Nant script map/un-map network drive automatically

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

Good MS-DOS Batch tips

http://smallvoid.com/tweak/dos/tips.html

Wednesday, February 14, 2007

Hide Office document Design mode

When you open a Ms Office Excel, Word document that has embedded controls (combo box, check box and etc) , it always shows the Design toolbar. This is very annoying.

I have 'googled' for answer and no working solution found. I decided to attempt it myself and it works. However, it requires macro execution coz i did it using VBA.

I have tried VBA ActiveDocument.ToggleFormsDesign . Doesn't work.

Solution:
- Open the office document.
- Open the VBA Editor (Alt-F11).
- Add the following to the document_open events. Double click ThisDocument (under Microsoft Word Object).


Private Sub Document_Open()
CommandBars("Control Toolbox").Visible = False
CommandBars("Exit Design Mode").Visible = False
End Sub
- Exit VBA Editor.
- Save the document.
- Voila. Done.