473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Mapping a Drive

Hello all:

Is there a way to map a drive programatically in .NET?

The reason why I ask is I am trying write a program that can map local
c: drive of each computer on our domain so that I can access a certain
file, open it, and read its contents.

Thanks,

- John -
Nov 16 '05 #1
3 1549
John,

I can think of a couple of ways of doing this (there may be more). One is
to use the System.Diagnostics.Process class to invoke NET USE and map the
drive that way (I have posted a sample of doing this below). The second way
is to use PInvoke to accomplish the mapped drive (I have posted a link to an
article detailing this.

I hope this helps.
--------------------

--PInvoke way
http://www.dotnet247.com/247reference/msgs/4/22781.aspx

--Process way

ProcessStartInfo pi = new ProcessStartInfo();
pi.FileName = "NET";
pi.Arguments = "USE \\<servername> /user:<username>";
Process p = new Process();
p.StartInfo = pi;
p.Start();
Nov 16 '05 #2
Dan
Here is an artical that I found and have used in production for quite
sometime. It has worked great. The only issues I had was using this from
multiple threads. Make sure you handle the synchronization issues that may
arrise.

http://dotnetjunkies.com/WebLog/bsbl.../24/26730.aspx
Dan
"John Smith" wrote:
Hello all:

Is there a way to map a drive programatically in .NET?

The reason why I ask is I am trying write a program that can map local
c: drive of each computer on our domain so that I can access a certain
file, open it, and read its contents.

Thanks,

- John -

Nov 16 '05 #3
Thanks, guys I have the mapping part working now and I know how to get
to a certain file and start reading from it but how do you seek the
pointer to a certain line in a text file?
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vladimir | last post by:
How I can get the information about mapping path of the substituted drive from C# code. For example I have created the substitution using the command: C:\>subst r: "C:\Program Files" C:\>subst...
3
by: Chris Fink | last post by:
Hi, Attempting to determine if a drive mapping is present, and if it is not, want to connect it. Anyone familiar with the .net classes that I would use to accomplish this? Thanks in advance....
1
by: Tim | last post by:
I need to be able to control drive mapping on a win2000 server with C#. I will need to be able to check for it's existence (think I figured this out) and most importantly create a mapping to a...
1
by: John Smith | last post by:
Hello all: Is there a way to map a drive programatically in .NET? Thanks, - John -
1
by: Johan | last post by:
My problem is that I want to set file permission on a file on the network using WMI, but the folder might not be mapped which ,as far as I know, WMI needs. So my solution to this would be to map...
2
by: Tomas Vera | last post by:
Hello All, I have a web application that is required to copy a file from the WebServer to a remote web server (staging server to production server). I've created an application that maps the...
0
by: fndjoum | last post by:
When using Visual Studio 2005, I was able to read the text file if it's in my local c:\ drive ifstream myfile; myfile.open("C:\\test.txt"); --------------> this works on local drive ...
13
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I am actually trying to get the UNC path of the main module of a process running from a mapped drive, and I am trying to do this from a service. The ProcessModule class only provides the full path...
10
by: =?Utf-8?B?Z3JlYXRiYXJyaWVyODY=?= | last post by:
Sorry about that previous one. I pressed enter too early. How does one go about mapping a network drive in C#. i know you use MapNetworkDrive in scripting languages, but i'm not sure how to do it...
0
by: Daffydd | last post by:
Hi all, This one's driving me up a wall! We have a small office network, Windows SBS 2003, nothing fancy - recently upgraded from an old Compaq running Novell. Back in the day we used the "F"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.