net use in c#

D

DBC User

It looks like when you run an application as admin, the mapped drive
information is lost, in other words the program will not be aware of
all the logical drives in the box. Only way I make other application
to be aware of this logical drive is by running dos prompt (cmd) 'as
admin' prior to running the application and then map all the required
drives using 'net use'

I would like to know can I accomplish this through a C# program? I do
not want the users to do it manually everytime they need to run the
program in admin mode.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

What you are doing doesn't make sense. Drive mappings are done on a
per-user basis for the machine, they are not propogated across all accounts.
So if you are running as an administrator, that account will have a separate
set of drive mappings than for another user.

Why are you trying to do this?
 
W

Willy Denoyette [MVP]

DBC User said:
It looks like when you run an application as admin, the mapped drive
information is lost, in other words the program will not be aware of
all the logical drives in the box. Only way I make other application
to be aware of this logical drive is by running dos prompt (cmd) 'as
admin' prior to running the application and then map all the required
drives using 'net use'

I would like to know can I accomplish this through a C# program? I do
not want the users to do it manually everytime they need to run the
program in admin mode.

Thanks.


Drive mappings are per logon session, this means that when when you
establish a use session (map a drive) in the logon session of BOB, that this
mapping is only visible in the logon session of BOB.
You can map the drive from within an application that runs as
"Administrator" by issuing a "net use ..." command using
System.Diagnostics.Process.Start. The question is why not simply use an UNC
path instead of mapping a drive.

Willy.
 
L

Levidikus

It looks like when you run an application as admin, the mapped drive
information is lost, in other words the program will not be aware of
all the logical drives in the box. Only way I make other application
to be aware of this logical drive is by running dos prompt (cmd) 'as
admin' prior to running the application and then map all the required
drives using 'net use'

I would like to know can I accomplish this through a C# program? I do
not want the users to do it manually everytime they need to run the
program in admin mode.

Thanks.

If this is for all users, you could always add it to the logon script.
 
D

DBC User

Drive mappings are per logon session, this means that when when you
establish a use session (map a drive) in the logon session of BOB, that this
mapping is only visible in the logon session of BOB.
You can map the drive from within an application that runs as
"Administrator" by issuing a "net use ..." command using
System.Diagnostics.Process.Start. The question is why not simply use an UNC
path instead of mapping a drive.

Willy.

This application has to interact with one of the 'very old' leagacy
application which only accepts drive letter and doesn't like UNC path.
 
C

Chris Shepherd

DBC said:
This application has to interact with one of the 'very old' leagacy
application which only accepts drive letter and doesn't like UNC path.

Why not simply enumerate the first available free drive letter and cause
that to be mapped on an as-needed basis?

This is really not a great approach, but at least it saves you from
having to change logon scripts for every user and would allow the old
application to work. Another thing to try would be reverse enumeration
(ie: start at Z: and work your way back).

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top