.NET Framework - Map network drive for user using VB/ASP.NET
Asked By BrianNicholso on 29-Jun-08 04:45 PM
I'm trying to create an admin page that can run miscellaneous scripts for
our IT department. Currently, I'm trying to create a script that can map a
network drive for a user (e.g. a form where I can input \\path\folder, drive
letter, and domain\user). Is this possible? If so, can someone point me in
the right direction?
Mark Rae [MVP] replied on 29-Jun-08 06:12 PM
Not natively through ASP.NET, for fairly obvious security reasons - remember
that web app cannot have any direct interaction with client machines due to
the disconnected architecture of the web...
To achieve this you'd need to look at something like a custom ActiveX
control - can't recommend it...
Junior replied on 29-Jun-08 06:51 PM
If you get to Technet as well as elsewhere you will learn about PowerShell
which has become the optimal way to use the framework for administrative
Mark Rae [MVP] replied on 29-Jun-08 07:25 PM
PowerShell won't allow a web app map a network drive via a client browser
without using ActiveX and seriously ramping down the security level - at
that point, you may as well not bother...
BrianNicholso replied on 30-Jun-08 09:05 AM
Forgive my ignorance as I am very new to ASP.NET, but what would be the
security problems of a web app that uses IIS with Integrated Windows
Authentication? Also, I thought that mapping network drives was a
user-specific task (not machine-specific) -- if that even makes a difference.
Thank you for your help.
Mark Rae [MVP] replied on 30-Jun-08 09:26 AM
It's not the web app per se - it's the browser. All modern browsers are
specifically designed to prevent *any* direct interaction with the user's
hardware other than for things like cookies etc. The fact that you're using
Windows authentication in an intranet environment is of no concern to the
browser, which is the same browser that you use to go out onto the public
Internet and do your on-line banking etc - the browser itself doesn't
understand the difference. All it knows how to do is send an HttpRequest to
a webserver and then process and display the HttpResponse which the
webserver streams back to it - makes no difference whether that webserver is
in your comms room or half-way round the world.
To give you a rather extreme example, imagine a web app which could stream
down an instruction to the client browser to run the equivalent of "format
c:" on the client machine...
Mapping a network drive involves direct interaction with the client machine
as far as the browser is concerned, so it's not permitted.
Junior replied on 30-Jun-08 09:50 AM
So you are the kind of guy who makes excuses rather than finding an
acceptable way to get things done?
BrianNicholso replied on 30-Jun-08 09:54 AM
I kind of understand what you're saying, but I didn't think I was using the
browser itself as a means to perform the task -- I don't want the drive to be
mapped on the client computer that's actually going to the web app. I was
considering something like an admin page where the admin could enter certain
things like a network path, username, etc., and the app would use these
values in a VB script which could then perform the function (as if we weren't
using a web app to begin with), e.g. using something similar to VBScript's
I apologize if you knew this already and I misunderstood your post.
Junior replied on 30-Jun-08 10:00 AM
BrianNicholso replied on 30-Jun-08 10:22 AM
I have no experience at all with PowerShell (I have very little experience
with ASP.NET as it is), but if it's able to do this through ASP.NET then I'm
interested. Do you happen to know how it can be done? After a quick search,
I found articles mentioning the same MapNetworkDrive that exists in VBScript
-- the problem with this method is that it requires the password of the user
I'm mapping a drive to.
Mark Rae [MVP] replied on 30-Jun-08 10:30 AM
[top-posting corrected again]
Go on, then, I'll bite...
Please demonstrate how you can use PowerShell via an ASP.NET web app to map
a network drive on the client machine...
Mark Rae [MVP] replied on 30-Jun-08 10:34 AM
Please clarify on which machine you intend to map a network drive: the
client machine, the web server or a different machine altogether...
BrianNicholso replied on 30-Jun-08 10:59 AM
From my understanding of mapped network drives, they're done per user; the
drives aren't mapped on the actual machine. If by which machine I intend to
use to map it you meant the machine that will do the actual mapping, I
suppose the web server will do that. Basically, I want to be able to use
administrative rights over some web application that allows me to map a
network folder to a drive for a specified user.
Mark Rae [MVP] replied on 30-Jun-08 11:22 AM
I wonder if we are we getting bogged down in nomenclature here...?
The term "mapped network drive" means, to me at least, that there is a share
(usually a folder on a remote fileserver) something like
\\fileserver\sharedfiles\Mark which I want to access as if it were a local
drive on my machine. So I map a drive letter to it, e.g. P:\, which then
appears in Windows Explorer...
This means that I can then refer to files stored on the remote share using
the syntax e.g. P:\MyDocument.docx rather than having to type
Is that what you mean?
If so, then the mapped drive is on my machine...
brucebarke replied on 30-Jun-08 11:23 AM
it sounds like you are trying to update the users profile and maybe the login
script. this can be done if the web site appdomin runs as a network admin or
you use kerberos and an admin logs on. see the wmi library for the routines.
you will need to switch to a nt admin forum to learn how to use wmi.
-- bruce (sqlwork.com)
brucebarke replied on 30-Jun-08 11:34 AM
while powershell is a handy for creating admin scripts, spawing a powershell
script to perform admin operations from a website is a pretty sketchy
programming practice, sign of a true hack.
if asp.net ever supports powershell as a language, then this might make
sense, but currently perl (which asp.net supports) would be a better choice
if you wanted to use an admin scripting language.
-- bruce (sqlwork.com)
BrianNicholso replied on 30-Jun-08 11:46 AM
All right, I apologize -- the example I was thinking of was NET USE, which
takes a domain\username as a parameter rather than the computer name, but I
guess it finds the computer that the specified user is on and makes the
changes there. In any case, in response to your question, I was referring to
a different computer altogether.
Mark Rae [MVP] replied on 30-Jun-08 12:09 PM
Hmm - I don't believe this is correct.
As I understand it, the domain\username parameter is used to specify the
credentials under which the NET USE command will run - the network drive
will still be mapped on the machine on which the NET USE command is being
E.g. an "ordinary" domain user might not have sufficient privileges to map a
network drive due to policies etc, but a domain admin can pop a command
prompt and issue the NET USE command by supplying his domain admin
BrianNicholso replied on 30-Jun-08 12:16 PM
Ah okay...that would make more sense then.
BrianNicholso replied on 30-Jun-08 12:33 PM
Thanks for the tips...I will see what I can do with WMI.
Patrice replied on 30-Jun-08 12:44 PM
Seen a similar discussion in the vb group. Please avoid multiposting as it
creates two independent threads that could waste our time (we have no idea
what is going on on the other side).... If you really have to, please
crosspost instead (i.e. post the *same* message to two groups) so that we
have a *single* discussion about the issue you raised....
message de groupe de discussion :
BrianNicholso replied on 30-Jun-08 01:22 PM
All right -- I will admit that I have never used newsgroups previously to post my
questions and I am unaware of the conventions. I apologize for the
Junior replied on 30-Jun-08 03:42 PM
PowerShell is Microsoft's newest approach to system administration and is
meant to supercede the cmd shell and VBScript both of which remain present
but are lame in comparison. PowerShell requires .NET 2.0 as it uses the
classes from the framework.
To others in this topic I do not say that PowerShell commands (cmdlet) run
through the browser but IMO should be learned by anybody who has system
administration responsibilities. Visual tools to use PowerShell are
available but need to mature.
Technet Magazine and http://technet.com is where a lot can be learned and a
quick look can be gained using the site filter
Kirk Barnett replied on 03-Oct-08 01:17 PM
I am looking to map a network drive on the CLIENT machine. Our plan is to have the user connect to VPN, then go to a web page, click a button & map network drives (i.e. p: \\servername\public). So, ultimately, the CLIENT machine has the drive showing up under 'My Computer.' Does PowerShell allow this to occur? thansk.