Home All Groups Group Topic Archive Search About

Accessing a Share Using Windows Credentials

Author
17 Mar 2006 5:12 PM
Carl
Using VB .NET how can I enable my program to access a share on another
machine and pass the user name and password.  I have a computer and share,
say "\\computer\share" so I can copy files from it but to access it I have to
log on with a UserName and Password.  I do not want the user to have to enter
the user name or password, so how can I pass this in code?

Thanks,
-Carl

Author
17 Mar 2006 5:31 PM
Chris
Carl wrote:
> Using VB .NET how can I enable my program to access a share on another
> machine and pass the user name and password.  I have a computer and share,
> say "\\computer\share" so I can copy files from it but to access it I have to
> log on with a UserName and Password.  I do not want the user to have to enter
> the user name or password, so how can I pass this in code?
>
> Thanks,
> -Carl
>
>


Is the username/password on the remote computer the same as the user
running the VB program?  If it is, it should pass the credentials
automatically.  If it is not, adding the user to the remote computer
using the same password should fix it.  Otherwise you will have to
impersonate a user in the vb.net program.

Chris
Author
17 Mar 2006 6:05 PM
Carl
The username/password are not the same as the user running my program so I do
need to use impersonation.  How do I do that and then access a file on that
other computer using the impersonated windows account?  Is there some sample
code that does this I could look at?

Thanks,
-Carl

Show quoteHide quote
"Chris" wrote:

> Carl wrote:
> > Using VB .NET how can I enable my program to access a share on another
> > machine and pass the user name and password.  I have a computer and share,
> > say "\\computer\share" so I can copy files from it but to access it I have to
> > log on with a UserName and Password.  I do not want the user to have to enter
> > the user name or password, so how can I pass this in code?
> >
> > Thanks,
> > -Carl
> >
> >
>
>
> Is the username/password on the remote computer the same as the user
> running the VB program?  If it is, it should pass the credentials
> automatically.  If it is not, adding the user to the remote computer
> using the same password should fix it.  Otherwise you will have to
> impersonate a user in the vb.net program.
>
> Chris
>
Author
17 Mar 2006 6:19 PM
Chris
Carl wrote:
Show quoteHide quote
> The username/password are not the same as the user running my program so I do
> need to use impersonation.  How do I do that and then access a file on that
> other computer using the impersonated windows account?  Is there some sample
> code that does this I could look at?
>
> Thanks,
> -Carl
>
> "Chris" wrote:
>
>
>>Carl wrote:
>>
>>>Using VB .NET how can I enable my program to access a share on another
>>>machine and pass the user name and password.  I have a computer and share,
>>>say "\\computer\share" so I can copy files from it but to access it I have to
>>>log on with a UserName and Password.  I do not want the user to have to enter
>>>the user name or password, so how can I pass this in code?
>>>
>>>Thanks,
>>>-Carl
>>>
>>>
>>
>>
>>Is the username/password on the remote computer the same as the user
>>running the VB program?  If it is, it should pass the credentials
>>automatically.  If it is not, adding the user to the remote computer
>>using the same password should fix it.  Otherwise you will have to
>>impersonate a user in the vb.net program.
>>
>>Chris
>>

Once the impersonation is done you should be able to access shares just
like you wanted to.

Do a web search for impersonation, I haven't had to do it in a long time
so I don't have any code for you.  There are lots of examples around,
most will deal with ASP.NET, but the process is identical.

This article looks promising, they've made a wrapper for doing the
impersonation.

http://weblogs.asp.net/ralfw/archive/2003/11/24/39479.aspx

Chris