472,328 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Read file on remote server in hidden share

Hi,

I am trying to get the contents of a file in a hidden share on a remote
server, something like '\\server.domain.com\c$\program
files\application\document.xml'. When I try any of the standard
streamreader, textreader or file classes I get an access denied error
message (which I expect). If I go Start | Run and type this in, I get
prompted for network credentials. After supplying the correct credentials I
can access the file both through explorer and through the VB.NET application
(as expected) as my workstation is caching the credentials for me. I want
to be able to do this programmatically.

First I tried the networkcredential object, creating an xmlResolver and
using this on an xmlDocument to load the file. This didn't work as I
understand it's only for HTTP requests and the path is obviously UNC. I
then tried the LogonUser API which according to MSDN cannot authenticate for
remote access. LOGON32_LOGON_INTERACTIVE always returned an unknown
username or password error although LOGON32_LOGON_NETWORK returned ok but
doesn't return the right type of token. The sample on MSDN for
WindowsIdentity.Impersonate will not work on Windows 2000 which is no good
to me :(

I also tried using WMI to copy the file to the local computer but had
problems getting the Copy method of CIM_DataFile to work. I would rather
leave the file on the remote server than drag it across a possibly slow WAN
link. My next attempt was to use WNetUseConnection to map a network drive
dynamically but this has problems under XP and 2003 and looked like a really
messy solution.

If anyone can provide some code to accomplish this I would be eternally
grateful!

Thanks

Glen
Nov 20 '05 #1
2 12172
If you want to read the file while using different credentials, try this:
System.Threading.Thread.CurrentPrincipal = CType(New
System.Net.NetworkCredential("user","pw"),
System.Security.Principal.IPrincipal)

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Glen Conway" <gl*********@flarepath.com> wrote in message
news:e1*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to get the contents of a file in a hidden share on a remote
server, something like '\\server.domain.com\c$\program
files\application\document.xml'. When I try any of the standard
streamreader, textreader or file classes I get an access denied error
message (which I expect). If I go Start | Run and type this in, I get
prompted for network credentials. After supplying the correct credentials I can access the file both through explorer and through the VB.NET application (as expected) as my workstation is caching the credentials for me. I want
to be able to do this programmatically.

First I tried the networkcredential object, creating an xmlResolver and
using this on an xmlDocument to load the file. This didn't work as I
understand it's only for HTTP requests and the path is obviously UNC. I
then tried the LogonUser API which according to MSDN cannot authenticate for remote access. LOGON32_LOGON_INTERACTIVE always returned an unknown
username or password error although LOGON32_LOGON_NETWORK returned ok but
doesn't return the right type of token. The sample on MSDN for
WindowsIdentity.Impersonate will not work on Windows 2000 which is no good
to me :(

I also tried using WMI to copy the file to the local computer but had
problems getting the Copy method of CIM_DataFile to work. I would rather
leave the file on the remote server than drag it across a possibly slow WAN link. My next attempt was to use WNetUseConnection to map a network drive
dynamically but this has problems under XP and 2003 and looked like a really messy solution.

If anyone can provide some code to accomplish this I would be eternally
grateful!

Thanks

Glen

Nov 20 '05 #2
Thanks Jan but I get a "Specified cast is not valid" exception. The method
that needs to access the file runs under the thread pool so I put the code
into the class the thread pool calls although I don't think that has
anything to do with the exception.

Cheers

Glen

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
If you want to read the file while using different credentials, try this:
System.Threading.Thread.CurrentPrincipal = CType(New
System.Net.NetworkCredential("user","pw"),
System.Security.Principal.IPrincipal)

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Glen Conway" <gl*********@flarepath.com> wrote in message
news:e1*************@TK2MSFTNGP11.phx.gbl...
Hi,

I am trying to get the contents of a file in a hidden share on a remote
server, something like '\\server.domain.com\c$\program
files\application\document.xml'. When I try any of the standard
streamreader, textreader or file classes I get an access denied error
message (which I expect). If I go Start | Run and type this in, I get
prompted for network credentials. After supplying the correct credentials
I
can access the file both through explorer and through the VB.NET

application
(as expected) as my workstation is caching the credentials for me. I

want to be able to do this programmatically.

First I tried the networkcredential object, creating an xmlResolver and
using this on an xmlDocument to load the file. This didn't work as I
understand it's only for HTTP requests and the path is obviously UNC. I
then tried the LogonUser API which according to MSDN cannot authenticate

for
remote access. LOGON32_LOGON_INTERACTIVE always returned an unknown
username or password error although LOGON32_LOGON_NETWORK returned ok but doesn't return the right type of token. The sample on MSDN for
WindowsIdentity.Impersonate will not work on Windows 2000 which is no good to me :(

I also tried using WMI to copy the file to the local computer but had
problems getting the Copy method of CIM_DataFile to work. I would rather leave the file on the remote server than drag it across a possibly slow

WAN
link. My next attempt was to use WNetUseConnection to map a network drive dynamically but this has problems under XP and 2003 and looked like a

really
messy solution.

If anyone can provide some code to accomplish this I would be eternally
grateful!

Thanks

Glen


Nov 20 '05 #3

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

Similar topics

4
by: Rene' Nielsen | last post by:
Context: Running Windows 2003 Server on an intranet. A web is configured with an anonymous access account that is a domain account that has...
7
by: Dan V. | last post by:
Situation: I have to connect with my Windows 2000 server using VS.NET 2003 and C# and connect to a remote Linux server at another company's office...
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still...
8
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of...
4
by: Kevin Vogler | last post by:
I need to read the value of a hidden field on a remote HTML page and then use that value in a form submit on my local page. How can I read the...
2
by: freenews.netfront.net | last post by:
Hi, I am writing an asp.net / Active Directory application using vb.net in it's code-behind pages. The app is running on the W2k3 (r1) domain...
1
by: Duffman | last post by:
Hi, I have what seems to be a common problem, but the solutions I've found don't seem to work. I would like to use a web service to create a...
1
by: Mark | last post by:
The new file based web server that comes with Visual Studio 2005 allows you to develop and debug an ASP.NET on a remote computer rather than having...
3
by: Amie | last post by:
Hi, My .NET application has a script that checks whether an image file on a remote server exists using File.Exists. >From my localhost (Server...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.