473,326 Members | 2,588 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,326 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 12275
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 been granted the desired access to a file on another...
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 and query their XML file. Their file may be...
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 solve my problem. I've got two server inside the...
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 the path" but if I copy the file to my C dirve,...
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 hidden field programatically? Thanks in advance....
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 controller (e.g. server1). Does anyone know how...
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 file at a UNC location in a shared file. Currently...
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 to rely on IIS. Assuming you've got decent LAN...
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 A), I can access the image file via network path...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.