Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
akruhler authored May 8, 2020
1 parent 4685cac commit c7450fc
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lusrmgr/About.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions lusrmgr/ActiveDirectory.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Public Class ActiveDirectory
Private main As DirectoryEntry
Private mForm As Form1
Private isLoad As Boolean = True
Private cancelToken As New Threading.CancellationTokenSource()
Private cancelToken As Threading.CancellationTokenSource

Public conErr As Boolean
Public displayName As String
Expand Down Expand Up @@ -57,7 +57,7 @@ Public Class ActiveDirectory
End Function

Public Sub Disconnect()
If isLoading() Then
If isLoading() AndAlso cancelToken IsNot Nothing Then
cancelToken.Cancel()
End If

Expand Down Expand Up @@ -104,11 +104,11 @@ Public Class ActiveDirectory
Try
Dim o As Object = main.NativeObject

If GroupList.Count + UserList.Count = 0 Then
Return False
Else
Return True
End If
'If GroupList.Count + UserList.Count = 0 Then
'Return False
'Else
Return True
'End If
Catch ex As Exception
Return False
End Try
Expand All @@ -122,11 +122,15 @@ Public Class ActiveDirectory
Try
RefreshBuiltInSecurityPrincipals()

cancelToken = New Threading.CancellationTokenSource()
Await Task.Run(AddressOf RefreshDS, cancelToken.Token)
Catch ex As Exception
If Not cancelToken.IsCancellationRequested Then
'Set the connection error flag
conErr = True
End If
Finally
cancelToken.Dispose()
End Try
End Sub

Expand Down Expand Up @@ -265,9 +269,6 @@ Public Class ActiveDirectory
End If
End If

'If mForm.QSBar.Visible Then mForm.QuickSearch(Nothing, Nothing)
'If mForm.QSMenu.Visible Then mForm.QuickSearch_Menu(Nothing, Nothing)

If Not mForm.isRootNode() Then
mForm.hiddenItems.Clear()
mForm.QSMenu.Clear()
Expand Down
44 changes: 42 additions & 2 deletions lusrmgr/COMErr.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ILLEGAL_USERNAME = &H8007089A
BLOCKED_BUILTIN = &H8007055B
GROUPADD_KNOWNACCOUNT = &H8007056C
ERROR_INCORRECT_ACCOUNT_TYPE = &H800721C6
End Enum

Enum COMErrResult
Expand All @@ -22,7 +23,7 @@
Sub ShowUnknownErr(HWND As IntPtr, exMsg As String)
TASKDIALOG.TaskDialog(HWND, nullptr,
"Local users and groups",
"An unkown error ocurred",
"An unkown error occurred",
exMsg.Replace(vbNewLine, "") & vbCrLf & "Please report this issue to the developer.",
TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_OK_BUTTON, TD_ERROR_ICON, Nothing)
End Sub
Expand All @@ -45,7 +46,7 @@
tdc.nDefaultButton = TASKDIALOG_RESULT.IDCANCEL

tdc.pszWindowTitle = "Local users and groups"
tdc.pszMainInstruction = "An unkown error ocurred"
tdc.pszMainInstruction = "An unkown error occurred"
tdc.pszContent = exMsg.Replace(vbNewLine, "") & vbCrLf & vbCrLf & "Error code: 0x" & Hex(errCode) & vbCrLf & "Please report this issue to the developer."

TaskDialogIndirect(tdc, result, 0, 0)
Expand Down Expand Up @@ -152,6 +153,45 @@
Case ErrorCodes.GROUPADD_KNOWNACCOUNT
TASKDIALOG.TaskDialog(HWND, nullptr, "Local users and groups", "Operation cannot be performed on built-in accounts", "System-defined groups cannot be members of predefined security principals.", TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_OK_BUTTON, TASKDIALOG_ICONS.TD_ERROR_ICON, 0)
Return False
Case ErrorCodes.ERROR_INCORRECT_ACCOUNT_TYPE

Dim result As Integer

Dim tdc As New TASKDIALOGCONFIG
tdc.cbSize = sizeof(tdc)

Dim buttons As TASKDIALOG_BUTTON() = {New TASKDIALOG_BUTTON(IDOK, "OK"), New TASKDIALOG_BUTTON(100, "Copy error code")}
tdc.cButtons = buttons.Length
tdc.pButtons = arrPtr(buttons, TASKDIALOG_BUTTON.SIZE * tdc.cButtons)

tdc.hwndParent = HWND
tdc.pszMainIcon = TASKDIALOG_ICONS.TD_ERROR_ICON
tdc.dwFlags = TASKDIALOG_FLAGS.TDF_ALLOW_DIALOG_CANCELLATION

tdc.pszWindowTitle = "Cannot make changes to account"
tdc.pszMainInstruction = "System is not authoritative for the account"

tdc.pszContent = "The system is not authoritative for the specified account and therefore cannot complete the operation. Please retry the operation using the provider associated with this account. If this is an online provider please use the provider's online site." &
vbCrLf & vbCrLf & "Error code: 0x" & Hex(errCode)

tdc.pszCollapsedControlText = "Why does this occurr?"
tdc.pszExpandedControlText = "Why does this occurr?"
tdc.pszExpandedInformation = "This issue can occurr whilst trying to make changes to a Microsoft account linked to your computer, not to a local account." &
" To make changes to Microsoft accounts, use the Windows settings or visit your account page online."

TaskDialogIndirect(tdc, result, 0, 0)

For i As Integer = 0 To buttons.Length - 1
buttons(i).freem()
Next
free(tdc.pButtons)

If result = 100 Then
Clipboard.SetText("0x" & Hex(errCode))
End If

Return False

Case Else
ShowUnknownCOMErr(errCode, HWND, exMsg)
Return COMErrResult.UNKOWN_ERR
Expand Down
44 changes: 21 additions & 23 deletions lusrmgr/Connect.vb
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
Imports System.Threading
Public Class Connect
Private Delegate Sub dTextBox(text As String)
Private thread As Thread
Public Class Connect
Private currentAsyncResult As IAsyncResult

Private Sub searchForHostName(addr As String)
On Error Resume Next
Private Async Sub queueHostEntry(result As IAsyncResult)
'This prevents multiple searches at a time by stopping all current searches
currentAsyncResult = result

Dim t As String = Net.Dns.GetHostEntry(addr).HostName
While Not result.IsCompleted
If currentAsyncResult IsNot result Then 'Determine whether scan is no longer required, since a new input has been given
Return
End If

If TextBox2.InvokeRequired Then
TextBox2.Invoke(New dTextBox(Sub(text As String)
TextBox2.Text = text
End Sub), t)
Else
TextBox2.Text = t
End If
Await Task.Delay(100)
End While

Try
TextBox2.Text = Net.Dns.EndGetHostEntry(result).HostName
Catch ex As Exception
End Try

currentAsyncResult = Nothing
End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If thread IsNot Nothing Then
thread.Abort()
End If

TextBox2.Clear()

If TextBox1.TextLength = 0 Then
Button1.Enabled = False
currentAsyncResult = Nothing 'Cancel current DNS lookup
Else
Button1.Enabled = True

thread = New Thread(Sub()
searchForHostName(TextBox1.Text)
End Sub)
thread.Start()
queueHostEntry(Net.Dns.BeginGetHostEntry(TextBox1.Text, Nothing, Nothing))
End If
End Sub

Expand Down Expand Up @@ -60,7 +58,7 @@ Public Class Connect
End Sub

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
thread.Abort()
currentAsyncResult = Nothing 'Cancel current DNS lookup
End Sub

Private Sub Label2_HelpRequested(sender As Object, hlpevent As HelpEventArgs) Handles TextBox2.HelpRequested, Label2.HelpRequested
Expand Down
29 changes: 20 additions & 9 deletions lusrmgr/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ Public Class Form1
End Sub

Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim ComputerName As String = My.Computer.Name
If ComputerName = Nothing Then ComputerName = "Local Computer"
tw.Nodes(0).Text = ComputerName & " (this computer)"
Expand All @@ -158,7 +157,7 @@ Public Class Form1

While localAD.isLoading()

Await Task.Delay(600)
Await Task.Delay(100)

If c.isBackground AndAlso tw.Nodes(0).Tag = cTag.Connected Then
If Not c.isClosing Then c.Close()
Expand All @@ -171,10 +170,12 @@ Public Class Form1
End If

Select Case loadingL.Tag
Case Is < 3
Case Is < 24
loadingL.Tag += 1
loadingL.Text &= "."
Case 3
If loadingL.Tag = 6 OrElse loadingL.Tag = 12 OrElse loadingL.Tag = 18 Then
loadingL.Text &= "."
End If
Case 24
loadingL.Tag = 0
loadingL.Text = loadingL.Text.Remove(loadingL.Text.Length - 3)
End Select
Expand Down Expand Up @@ -787,6 +788,8 @@ Public Class Form1
Dim addr As String = Connect.TextBox1.Text
c = New Connecting(Me)


'/////// DNS lookup ///////////////////////////////////
Try
c.SetText("Resolving host name")

Expand Down Expand Up @@ -814,19 +817,25 @@ Public Class Form1

Return
End Try
'//////////////////////////////////////////////////


'/////// Set display name /////////////////////////
Dim dspName As String = addr
If Connect.TextBox2.TextLength > 0 Then
dspName = Connect.TextBox2.Text
End If
'//////////////////////////////////////////////////

Connect.TextBox1.Text = ""
Connect.TextBox1.Select()

Dim newAD As ActiveDirectory

'/////// Authentication //////////////////////////
If Connect.promptAuth.Checked = False Then
c.SetText(addr, True)
'Create AD object, connect
newAD = New ActiveDirectory(addr, Me, dspName)
Else
c.SetText("Waiting for authentication")
Expand All @@ -845,15 +854,17 @@ Public Class Form1

c.SetText(addr, True)

'Create AD object, connect with credentials
newAD = New ActiveDirectory(addr, cred.Username, cred.Password, Me, dspName)

cred.Username = ""
cred.Password = ""
End If
'//////////////////////////////////////////////////

While newAD.isLoading()

If newAD.conErr Then 'An error ocurred
If newAD.conErr Then 'An error occurred
c.Close()

Dim result As Integer
Expand All @@ -871,7 +882,7 @@ Public Class Form1
Return
End If

Await Task.Delay(600)
Await Task.Delay(100)

If c.Cancel Then 'The user cancelled the process
c.Close()
Expand All @@ -882,7 +893,7 @@ Public Class Form1

c.Close()

If Not newAD.testConnection Then
If Not newAD.testConnection() Then
Dim result As Integer

TASKDIALOG.TaskDialog(Handle, nullptr, "Connection error", "Could not connect to computer", "There was an error whilst connecting to " & addr & "." & vbCrLf &
Expand Down Expand Up @@ -921,7 +932,7 @@ Public Class Form1
End If
Dim result As Integer

TASKDIALOG.TaskDialog(Handle, nullptr, "Unkown error", "Could not connect to computer", "An unkown error ocurred whilst connecting to the computer." & vbCrLf &
TASKDIALOG.TaskDialog(Handle, nullptr, "Unkown error", "Could not connect to computer", "An unkown error occurred whilst connecting to the computer." & vbCrLf &
ex.Message.Replace(vbNewLine, ""), TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_RETRY_BUTTON Or TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CLOSE_BUTTON, TD_ERROR_ICON, result)

If result = IDRETRY Then
Expand Down
4 changes: 2 additions & 2 deletions lusrmgr/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.5.0.0")>
<Assembly: AssemblyFileVersion("1.5.0.0")>
<Assembly: AssemblyVersion("1.5.1.0")>
<Assembly: AssemblyFileVersion("1.5.1.0")>
Binary file modified lusrmgr/bin/Release/lusrmgr.exe
Binary file not shown.
1 change: 1 addition & 0 deletions lusrmgr/lusrmgr.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Auth.resx">
<DependentUpon>Auth.vb</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="ChangePw.resx">
<DependentUpon>ChangePw.vb</DependentUpon>
Expand Down
Binary file modified lusrmgr/obj/Debug/lusrmgr.exe
Binary file not shown.
Binary file modified lusrmgr/obj/Release/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file modified lusrmgr/obj/Release/Interop.ActiveDs.dll
Binary file not shown.
Binary file modified lusrmgr/obj/Release/lusrmgr.exe
Binary file not shown.
Binary file modified lusrmgr/obj/Release/lusrmgr.vbproj.GenerateResource.Cache
Binary file not shown.

0 comments on commit c7450fc

Please sign in to comment.