Logon on to the network computer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Can someone help me in my C# program:
I am just trying to deal with files stored on the shared network server- to create, read and write operations.
If the user is authenticated from Windows Explorer with username, password there are no problems after to use "System.IO.File.Open(..)", but otherwise i have to authenticate the user programatically.

What is the best way to do Autentication on the network or Logon if I know the username and password on the network server?
 
Ivaylo,

In order to do this, you will have to call the LogonUser API function,
and get a handle to the logon session. Once you have that, you can pass the
token to the static Impersonate method on the WindowsIdentity class to get a
WindowsImpersonationContext class (which you would use in a using statement
to insure that the identity is rolled back).

You can check the documentation for the WindowsImpersonationContext to
see how to declare LogonUser and make the call to Impersonate (or check the
documentation for Impersonate as well).

Hope this helps.


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

Ivaylo said:
Hello,
Can someone help me in my C# program:
I am just trying to deal with files stored on the shared network server-
to create, read and write operations.
If the user is authenticated from Windows Explorer with username, password
there are no problems after to use "System.IO.File.Open(..)", but otherwise
i have to authenticate the user programatically.
What is the best way to do Autentication on the network or Logon if I know
the username and password on the network server?
 
Back
Top