471,350 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

FileIO Netwk Permissions!

Hi All, How do I access a shared Drive which requires username and password
to access?
I need to write a file in a folder within it

TIA
Dec 2 '05 #1
8 1265
Vai2000,

What you want to do is call the LogonUser API function, logging in with
the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All, How do I access a shared Drive which requires username and
password
to access?
I need to write a file in a folder within it

TIA

Dec 2 '05 #2
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uf****************@TK2MSFTNGP14.phx.gbl...
Vai2000,

What you want to do is call the LogonUser API function, logging in with the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user token to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All, How do I access a shared Drive which requires username and
password
to access?
I need to write a file in a folder within it

TIA


Dec 2 '05 #3
LogonUser will still work in that case.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uf****************@TK2MSFTNGP14.phx.gbl...
Vai2000,

What you want to do is call the LogonUser API function, logging in

with
the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user

token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> Hi All, How do I access a shared Drive which requires username and
> password
> to access?
> I need to write a file in a folder within it
>
> TIA
>
>



Dec 2 '05 #4
Thanks Nick,
"The LogonUser function attempts to log a user on to the local computer. The
local computer is the computer from which LogonUser was called. You cannot
use LogonUser to log on to a remote computer."

I want to log the user on the Remote Computer!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
LogonUser will still work in that case.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:uf****************@TK2MSFTNGP14.phx.gbl...
Vai2000,

What you want to do is call the LogonUser API function, logging in

with
the user's credentials that you want to impersonate. Then, you will call the Impersonate method on the WindowsIdentity class, passing the user

token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a code example.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
> Hi All, How do I access a shared Drive which requires username and
> password
> to access?
> I need to write a file in a folder within it
>
> TIA
>
>



Dec 2 '05 #5

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All, How do I access a shared Drive which requires username and
password
to access?
I need to write a file in a folder within it

TIA


Don't do this from code, just map the remote share to the users logon
session by running the "net use passwd /USER:machinename\username" command
from the command line or a logon script.

Willy.


Dec 2 '05 #6
LogonUser is not meant to "logon", it's used to obtain an Access Token that
can be used to impersonate a specific user account.
When you need to access a resource on a remote server, just specify the
remote machine name as domain argument and a vailid user and password as
registered in the remote servers security DB.
Only problem with LogonUser is that you need TCB privileges (part of OS
privilege) when running on W2K.

Willy.

"Vai2000" <no****@microsoft.com> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
Thanks Nick,
"The LogonUser function attempts to log a user on to the local computer.
The
local computer is the computer from which LogonUser was called. You cannot
use LogonUser to log on to a remote computer."

I want to log the user on the Remote Computer!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@tk2msftngp13.phx.gbl...
LogonUser will still work in that case.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Thanks, what if the server is not a part of any Domain its a
> standalone?
>
> TIA
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:uf****************@TK2MSFTNGP14.phx.gbl...
>> Vai2000,
>>
>> What you want to do is call the LogonUser API function, logging in
> with
>> the user's credentials that you want to impersonate. Then, you will call >> the Impersonate method on the WindowsIdentity class, passing the user
> token
>> to be impersonated.
>>
>> You can then make your call, and it will be under that other
>> user's
>> account. Mind you, you need to be careful about these credentials being >> embedded in your app.
>>
>> Check out the documentation for the Impersonate method on the
>> WindowsIdentity class (the overload that takes an IntPtr parameter)
>> for a >> code example.
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Vai2000" <no****@microsoft.com> wrote in message
>> news:%2****************@TK2MSFTNGP14.phx.gbl...
>> > Hi All, How do I access a shared Drive which requires username and
>> > password
>> > to access?
>> > I need to write a file in a folder within it
>> >
>> > TIA
>> >
>> >
>>
>>
>
>



Dec 2 '05 #7
Yes I did net use to map the network drive and provided the credentials,
though my Application fails to access the same, it fails to really now what
Z: Drive is (I used this drive letter to map the remote computer folder)

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All, How do I access a shared Drive which requires username and
password
to access?
I need to write a file in a folder within it

TIA


Don't do this from code, just map the remote share to the users logon
session by running the "net use passwd /USER:machinename\username" command
from the command line or a logon script.

Willy.


Dec 3 '05 #8
What kind of application is it?

Willy.

"Vai2000" <no****@microsoft.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Yes I did net use to map the network drive and provided the credentials,
though my Application fails to access the same, it fails to really now
what Z: Drive is (I used this drive letter to map the remote computer
folder)

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

"Vai2000" <no****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi All, How do I access a shared Drive which requires username and
password
to access?
I need to write a file in a folder within it

TIA


Don't do this from code, just map the remote share to the users logon
session by running the "net use passwd /USER:machinename\username"
command from the command line or a logon script.

Willy.



Dec 3 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by !!! Klutzo !!! | last post: by
reply views Thread by Steven Smith | last post: by
8 posts views Thread by jporter188 | last post: by
reply views Thread by =?Utf-8?B?bWFnZWxsYW4=?= | last post: by
1 post views Thread by =?Utf-8?B?bWFnZWxsYW4=?= | last post: by

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.