473,394 Members | 1,778 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,394 software developers and data experts.

Alternatives to Net Use

I'm rewriting a small utility app that, amongst other tasks, copies files
from the local machine to servers on the local network. The existing
implementation executes a batch file that executes the "net use" command to
map a drive to each destination server/share. The program then tests via "if
(File.Exists())" to ensure that the mappings were successful.

I'd like to find a better way to copy the files out to the servers... and
eliminate the batch file and "net use" altogether if possible.

Is there an easier way to map drive letters than via batch file and net use?

Is there a way to copy files without mapping a drive letter at all?

I'm developing this with .NET 3.5 beta 2, C#, and the app is to run on
Windows Server 2003.

Thanks!
Aug 20 '07 #1
9 8243
Hi,

"Smithers" <A@B.comwrote in message
news:O4**************@TK2MSFTNGP03.phx.gbl...
I'm rewriting a small utility app that, amongst other tasks, copies files
from the local machine to servers on the local network. The existing
implementation executes a batch file that executes the "net use" command
to map a drive to each destination server/share. The program then tests
via "if (File.Exists())" to ensure that the mappings were successful.

I'd like to find a better way to copy the files out to the servers... and
eliminate the batch file and "net use" altogether if possible.
You do not need to have the share mapped to the machine, you can simply use
an UNC like "\\servername\share\file"
Aug 20 '07 #2
Smithers wrote:
Is there a way to copy files without mapping a drive letter at all?
Yes. Just specify the filename with the UNC server name. So, if you
have \\server\share mapped to d: and would normally copy to the filename
"d:\myfile.dat", instead use the filename "\\server\share\myfile.dat".

Pete
Aug 20 '07 #3
I'm rewriting a small utility app that, amongst other tasks, copies files
from the local machine to servers on the local network. The existing
implementation executes a batch file that executes the "net use" command
to map a drive to each destination server/share. The program then tests
via "if (File.Exists())" to ensure that the mappings were successful.

I'd like to find a better way to copy the files out to the servers... and
eliminate the batch file and "net use" altogether if possible.

Is there an easier way to map drive letters than via batch file and net
use?

Is there a way to copy files without mapping a drive letter at all?

I'm developing this with .NET 3.5 beta 2, C#, and the app is to run on
Windows Server 2003.
A mapped drive is simply an alias for a UNC (Universal Naming Convention)
name. Just use the UNC name instead (which is cleaner anyway). IOW, if drive
"Z:" is mapped to \\ServerName\ShareName then the command:

copy YourFile Z:\SomeFolder

is the same as:

copy YourFile \\ServerName\ShareName\SomeFolder
Aug 20 '07 #4
What about authentication?
IIRC when I wrote version 1 of this utility a few years ago (and similar
apps over the years before), I had to go with mapping a drive letter because
with [net use] I could specify login credentials ("connect as user");
whereas going with a UNC assumes that the source is authenticated to the
destination (or is otherwise trusted).

-S
"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Smithers wrote:
>Is there a way to copy files without mapping a drive letter at all?

Yes. Just specify the filename with the UNC server name. So, if you have
\\server\share mapped to d: and would normally copy to the filename
"d:\myfile.dat", instead use the filename "\\server\share\myfile.dat".

Pete

Aug 20 '07 #5
Smithers wrote:
What about authentication?
Don't know. That is, not without using "net use". Maybe .NET provides
a mechanism, but I'm not aware of it.
IIRC when I wrote version 1 of this utility a few years ago (and similar
apps over the years before), I had to go with mapping a drive letter because
with [net use] I could specify login credentials ("connect as user");
whereas going with a UNC assumes that the source is authenticated to the
destination (or is otherwise trusted).
You can use "net use" without mapping a drive letter to authenticate
yourself.

Of course, even better is configuring the network so that you don't need
authentication. If you have an NT domain set up, this is as simple as
setting the access rights for the share to include the logged-in user
that will be accessing the share.

If you don't, you can achieve the same thing by making sure the server
computer has a user with the same name and password as that used on the
client computer used to connect. There might be some security setting
you have to configure to enable this behavior; I don't recall off the
top of my head whether this works by default.

Barring any of that, executing a "net use \\server\share
/user:<username/password:<password>" will authenticate you for the
share, and then you can use the UNC paths without any trouble. You can
do this from a command prompt manually or programmatically.

Pete
Aug 20 '07 #6
Great feedback (as usual). Thanks!

-S
"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Smithers wrote:
>What about authentication?

Don't know. That is, not without using "net use". Maybe .NET provides a
mechanism, but I'm not aware of it.
>IIRC when I wrote version 1 of this utility a few years ago (and similar
apps over the years before), I had to go with mapping a drive letter
because with [net use] I could specify login credentials ("connect as
user"); whereas going with a UNC assumes that the source is authenticated
to the destination (or is otherwise trusted).

You can use "net use" without mapping a drive letter to authenticate
yourself.

Of course, even better is configuring the network so that you don't need
authentication. If you have an NT domain set up, this is as simple as
setting the access rights for the share to include the logged-in user that
will be accessing the share.

If you don't, you can achieve the same thing by making sure the server
computer has a user with the same name and password as that used on the
client computer used to connect. There might be some security setting you
have to configure to enable this behavior; I don't recall off the top of
my head whether this works by default.

Barring any of that, executing a "net use \\server\share /user:<username>
/password:<password>" will authenticate you for the share, and then you
can use the UNC paths without any trouble. You can do this from a command
prompt manually or programmatically.

Pete

Aug 20 '07 #7
Quick followup:
Is it possible to issue a "net use" without putting it in a batch file and
launching that via Process.Start?

The end result I'm after is having the destination server name\share names
listed in App.config. Then at runtime I check to see if I can access each
share prior to attempting to copy files. IF the share is not accessible,
then I'm wanting to issue the net use to attempt to authenticate. Only after
that fails would the logic give up. I don't want to have to go with a batch
file if possible as I implement the net use portion of this.

Thanks!

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Smithers wrote:
>What about authentication?

Don't know. That is, not without using "net use". Maybe .NET provides a
mechanism, but I'm not aware of it.
>IIRC when I wrote version 1 of this utility a few years ago (and similar
apps over the years before), I had to go with mapping a drive letter
because with [net use] I could specify login credentials ("connect as
user"); whereas going with a UNC assumes that the source is authenticated
to the destination (or is otherwise trusted).

You can use "net use" without mapping a drive letter to authenticate
yourself.

Of course, even better is configuring the network so that you don't need
authentication. If you have an NT domain set up, this is as simple as
setting the access rights for the share to include the logged-in user that
will be accessing the share.

If you don't, you can achieve the same thing by making sure the server
computer has a user with the same name and password as that used on the
client computer used to connect. There might be some security setting you
have to configure to enable this behavior; I don't recall off the top of
my head whether this works by default.

Barring any of that, executing a "net use \\server\share /user:<username>
/password:<password>" will authenticate you for the share, and then you
can use the UNC paths without any trouble. You can do this from a command
prompt manually or programmatically.

Pete

Aug 20 '07 #8
On Aug 20, 1:45 pm, "Smithers" <A...@B.comwrote:
What about authentication?
IIRC when I wrote version 1 of this utility a few years ago (and similar
apps over the years before), I had to go with mapping a drive letter because
with [net use] I could specify login credentials ("connect as user");
whereas going with a UNC assumes that the source is authenticated to the
destination (or is otherwise trusted).

-S

"Peter Duniho" <NpOeStPe...@NnOwSlPiAnMk.comwrote in message

news:13*************@corp.supernews.com...
Smithers wrote:
Is there a way to copy files without mapping a drive letter at all?
Yes. Just specify the filename with the UNC server name. So, if you have
\\server\share mapped to d: and would normally copy to the filename
"d:\myfile.dat", instead use the filename "\\server\share\myfile.dat".
Pete
You can impersonate a user using code like this:

http://tinyurl.com/2jfc37

Chris

Aug 20 '07 #9
Smithers needs to delve into Microsoft's PowerShell which was developed to
do tasks exactly the same as those discussed in this news article.
PowerShell uses the .NET Framework to abstract away the complexity and need
to write lots of code in the same manner we learned the framework does for
us with its thousands of methods of classes.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
"Smithers" <A@B.comwrote in message
news:O4**************@TK2MSFTNGP03.phx.gbl...
I'm rewriting a small utility app that, amongst other tasks, copies files
from the local machine to servers on the local network. The existing
implementation executes a batch file that executes the "net use" command
to map a drive to each destination server/share. The program then tests
via "if (File.Exists())" to ensure that the mappings were successful.

I'd like to find a better way to copy the files out to the servers... and
eliminate the batch file and "net use" altogether if possible.

Is there an easier way to map drive letters than via batch file and net
use?

Is there a way to copy files without mapping a drive letter at all?

I'm developing this with .NET 3.5 beta 2, C#, and the app is to run on
Windows Server 2003.

Thanks!

Aug 22 '07 #10

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

Similar topics

0
by: yawnmoth | last post by:
popen / proc_open seem to be broken (as per PHP Bug #30463). As such, does anyone know if there are any alternatives to them? I tried to use fsockopen to load a bunch of instances of a script to...
5
by: Scott F | last post by:
testvar = bob # Trial A: This does not work if testvar == ("fred" or "bob): statements # Trial B: This does work if textvar == "fred" or textvar == "bob": statements
3
by: Dan Christensen | last post by:
I have written a small application in VB6 -- a kind of special purpose text editor. There seem to be many annoying glitches in VB's rich text box control, however. Performance on larger files has...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
2
by: Guadala Harry | last post by:
The current implementation (that works) retrieves data from a SS2K db via stored procedure that returns 40-60 rows and 6 columns (one string and five int columns), and places that result set into a...
1
by: Doug | last post by:
Looking for opinions/suggestions: Suppose I have a "region" of an aspx page I want to hide or show based on whatever runtime conditions. Additionally, the entire region is defined by an HTML...
7
by: Aaron Schnieder | last post by:
Hi, After battling with Crystal Reports for a while I have started to look for alternatives. It seems like there has got to be something out there that does a better job than Crystal Reports...
8
by: werner | last post by:
Hi! I don't want to use eval() in order to parse a user-supplied formula. What alternatives do I have? PHP has no standard functionality for tokenizing or parsing expressions in this regard. ...
1
by: Spencer | last post by:
Our Mainframe DBA insists that the IDTHTOIN parameter be set to 600 so that all idle threads timeout after 10 minutes. This is causing a particular packaged application that expects to hold idle...
3
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I've used an Application_BeginRequest function in my global.asax page to implement some URL rewriting functionality on our website. However, upon moving it to my host (1&1.co.uk), it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.