cjinsocal581
Programmer
Here is code that I am trying to get working.
____________________________________________________
_________________________________________________________
So, with the code on the above mentioned question, I need to make the following work.
I need to connect to a HIDDEN share and impersonating authentication on a server. List the files withing that share and have access to them.
PLEASE do not suggest unhiding the share. This IS NOT an option due to basic security requirements, I need to somehow get this solution to work.
Better yet, if you can get it to "prompt" for user name and password, that would be awesome.
Any ideas?
____________________________________________________
Code:
Option Explicit On
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Principal
Imports System.Threading
Public Class Form1
Inherits System.Windows.Forms.Form
Private strPath As String = "\\10.1.1.106\cjdev$"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rolesArray As String() = {"managers", "executives"}
Try
'Set the principal to a new generic principal.
Thread.CurrentPrincipal = _
New GenericPrincipal(New GenericIdentity( _
"administrator", "password"), rolesArray)
Catch secureException As SecurityException
Debug.WriteLine("{0}: Permission to set Principal " & _
"is denied.", secureException.GetType().Name)
End Try
Dim threadPrincipal As IPrincipal = Thread.CurrentPrincipal
Console.WriteLine( _
"Name: {0}" & vbCrLf & "IsAuthenticated:" & _
" {1}" & vbCrLf & "AuthenticationType: {2}", _
threadPrincipal.Identity.Name, _
threadPrincipal.Identity.IsAuthenticated, _
threadPrincipal.Identity.AuthenticationType)
Debug.WriteLine(System.Threading.Thread.CurrentPrincipal)
Dim strFile As String, SelectedItem As ListViewItem
Dim thisFile As FileInfo
Dim thisDir As New DirectoryInfo(strPath)
For Each thisFile In thisDir.GetFiles("*.wav")
SelectedItem = ListView1.Items.Add(thisFile.Name, 0)
SelectedItem.SubItems.Add(Now())
Next
End Sub
So, with the code on the above mentioned question, I need to make the following work.
I need to connect to a HIDDEN share and impersonating authentication on a server. List the files withing that share and have access to them.
PLEASE do not suggest unhiding the share. This IS NOT an option due to basic security requirements, I need to somehow get this solution to work.
Better yet, if you can get it to "prompt" for user name and password, that would be awesome.
Any ideas?