By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Read file on remote server in hidden share

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.