Map Network Drive in code

UG Guru

Member
Joined
Oct 18, 2005
Messages
9
Im currently trying to convert an old vbs file into .net
The file is a remote installation script for some software.
It uses wmi to install the program remotely however wmi cant install from a mapped drive and we dont want to have to insert the CD on all of the remote machines (there are quite a few).
To get around this the script maps the remote c$ copies the installation files, installs the program and then removes the installation files. It then moves onto the next remote host in the list.

How would I go about creating the mapping to the remote c$ to the U: drive of the local machine used to install the program in .net??
The mapping will need to pass a user name and password.

Cheers
 
Can you invoke subst.exe (system32 program) through the shell to do this?
 
marble_eater said:
Can you invoke subst.exe (system32 program) through the shell to do this?

Not sure if I can, or if I want to. Id prefer not to make a call to a command line argument.

Ive managed to work out how to get the wsh runtime library referenced in my project and used the same/similar scripting code to get the desired effect.

The reference I need in my project was a com reference to the windos script host object model. This added iwshruntimelibrary as a reference in my project

[VB]
Imports IWshRuntimeLibrary

sub main()

Dim neto As New WshNetwork

map a host admin share drive to u: using a username and password
neto.MapNetworkDrive("u:", "\\myhost\C$", , "myhost\user", "password")

remove mapping
neto.RemoveNetworkDrive("u:")

end sub

[/VB]

This seems to do the trick.
 
Last edited by a moderator:
I would much rather run use a standard Windows command than add an extra dependancy (and extra code) to my project, but thats just me.
 
The WSH Runtime library is inbuilt into windows just like subst however subst has issues on win 2000 server with no fix.
After a bit of research Ive found net use would be a better alternative.

However I prefer to use something that does this in code as I can control timing of events in code better than having to check to see if the shell has finished.

Also if an error happens in the shell Its harder to get that error back into the app to trap and accomodate it isnt it? All Id be able to tell is that the shell failed?

I may be missing some tricks or not understanding the implications of using WSH in my code though. After all Im no expert.
 
Well, those are some good points. Maybe you are better off using WSH DLLs after all; I just hate using DLLs. I cant stand dependancy and version issues.
 
How about using "net use" and shell a .bat file. any other commands could be formated there i.e. user name passwork blah blah blah.

Your thoughts

ZeroEffect
 
Back
Top