FileIO Netwk Permissions!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

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
 
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.
 
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

Nicholas Paldino said:
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]
- (e-mail address removed)

Vai2000 said:
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
 
LogonUser will still work in that case.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vai2000 said:
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

in
message news:uf%[email protected]...
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]
- (e-mail address removed)

Vai2000 said:
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
 
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 said:
LogonUser will still work in that case.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vai2000 said:
Thanks, what if the server is not a part of any Domain its a standalone?

TIA

in
message news:uf%[email protected]...
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]
- (e-mail address removed)

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
 
Vai2000 said:
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.
 
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 said:
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!


in
message news:%[email protected]...
LogonUser will still work in that case.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vai2000 said:
Thanks, what if the server is not a part of any Domain its a
standalone?

TIA

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message 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]
- (e-mail address removed)

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
 
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)
 
What kind of application is it?

Willy.

Vai2000 said:
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)
 
Back
Top