I just hate it, when a script simply stops working, ’cause Windows lost the mapping to a network drive.  Especially, when you have to use another userid and password, so the connection cannot be restored automatically.

Recently I found a solution to my problem.

Apparently you can use OLE Automation with the Windows Script Host (WSH)

So I’ve written the following workspace script:

/>
| params objNetwork |
params := (Array new: 5)
 at:1 put: 'U:' ;
 at: 2 put: '\\remotemachine\Share';
 at: 3 put: false;
 at: 4 put: 'myuserid';
 at: 5 put: 'mypassword';
 yourself.

objNetwork := (OLEObject newLongTypeName: 'WScript.Network') dispatcher.
objNetwork call: 'MapNetworkDrive' params: params.

The WSH has several useful methods and properties. More information about the WSH can be found here.

Some other examples are:

objNetwork := (OLEObject newLongTypeName: 'WScript.Shell') dispatcher.
objNetwork at: 'CurrentDirectory'.

or

objNetwork := (OLEObject newLongTypeName: 'WScript.Shell') dispatcher.
objNetwork call: 'Exec' params: (Array with: 'calc').


Have fun,

Andreas
———————————————
Quis Custodiet Ipsos Custodes?