winforms 문서 관리자를 만들고 있습니다. 사용자가 보호 된 네트워크 드라이브에서 문서를 업로드하고 열 수 있도록하고 싶습니다.사용자 이름 및 암호를 사용하여 파일 열기
특정 사용자 이름과 암호가 응용 프로그램에 설정되므로 응용 프로그램 만 파일에 액세스 할 수 있습니다.
일반적으로 사용자가 파일을 열도록 허용하면 OpenFileDialog 명령을 사용합니다. 사용자 이름과 암호를 어떻게 추가합니까?
감사합니다.
편집이
이 몇 가지 추가 코드를 찾았 원래 작성자에게
Public Class ImpersonateUser
Private Declare Auto Function LogonUser Lib "advapi32.dll" (_
ByVal lpszUsername As String, _
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Int32, _
ByVal dwLogonProvider As Int32, _
ByRef phToken As IntPtr _
) As Int32
Private Declare Auto Function ImpersonateLoggedOnUser Lib "advapi32.dll" (_
ByVal hToken As IntPtr _
) As Int32
Declare Auto Function RevertToSelf Lib "advapi32.dll" (_
) As Int32
Private Function ImpersonateValidUser(_
ByVal Username As String, _
ByVal Domain As String, _
ByVal Password As String _
) As Boolean
Dim LogonType As Int32
Dim LogonProvider As Int32
Dim Tk As IntPtr
LogonType = 2 ' Interactive.
LogonProvider = 0 ' Default Provider.
If LogonUser(Username, Domain, Password, LogonType, LogonProvider, Tk) <> 0 Then
Return (ImpersonateLoggedOnUser(Tk) <> 0)
End If
Return False
End Function
Private Sub UndoImpersonation()
RevertToSelf()
End Sub
Sub test()
If ImpersonateValidUser("accountname", "Domainname", "password") Then
' This code runs unter the privileges of the impersonated user.
Process.Start("C:\foo.exe")
UndoImpersonation()
End If
End Sub
End Class
신용을,이 방법을 사용하여 어떤 장점/단점이있다?
당신은 사용자를 위해 이미 장소에서 사용자 인증 시스템을 가지고 있습니까? 그렇다면 어떤 종류입니까? –
우리 고객의 대부분은 Windows 서버를 사용하므로 Active Directory가됩니다. 나는 모든 제안에 열리다. – Reafidy