diff --git a/lusrmgr/About.Designer.vb b/lusrmgr/About.Designer.vb index e46ca21..b3977e9 100644 --- a/lusrmgr/About.Designer.vb +++ b/lusrmgr/About.Designer.vb @@ -87,7 +87,7 @@ Partial Class About Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(452, 39) Me.Label4.TabIndex = 8 - Me.Label4.Text = "Version 1.5 (x86)" + Me.Label4.Text = "Version 1.5.1 (x86)" Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'Label5 diff --git a/lusrmgr/ActiveDirectory.vb b/lusrmgr/ActiveDirectory.vb index 8d3ad11..81e56b2 100644 --- a/lusrmgr/ActiveDirectory.vb +++ b/lusrmgr/ActiveDirectory.vb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/lusrmgr/COMErr.vb b/lusrmgr/COMErr.vb index cf3e195..5fadb57 100644 --- a/lusrmgr/COMErr.vb +++ b/lusrmgr/COMErr.vb @@ -11,6 +11,7 @@ ILLEGAL_USERNAME = &H8007089A BLOCKED_BUILTIN = &H8007055B GROUPADD_KNOWNACCOUNT = &H8007056C + ERROR_INCORRECT_ACCOUNT_TYPE = &H800721C6 End Enum Enum COMErrResult @@ -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 @@ -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) @@ -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 diff --git a/lusrmgr/Connect.vb b/lusrmgr/Connect.vb index bba5ded..7158871 100644 --- a/lusrmgr/Connect.vb +++ b/lusrmgr/Connect.vb @@ -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 @@ -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 diff --git a/lusrmgr/Form1.vb b/lusrmgr/Form1.vb index 230b7b8..302a4e9 100644 --- a/lusrmgr/Form1.vb +++ b/lusrmgr/Form1.vb @@ -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)" @@ -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() @@ -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 @@ -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") @@ -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") @@ -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 @@ -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() @@ -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 & @@ -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 diff --git a/lusrmgr/My Project/AssemblyInfo.vb b/lusrmgr/My Project/AssemblyInfo.vb index 5e48758..5f6dc06 100644 --- a/lusrmgr/My Project/AssemblyInfo.vb +++ b/lusrmgr/My Project/AssemblyInfo.vb @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - - + + diff --git a/lusrmgr/bin/Release/lusrmgr.exe b/lusrmgr/bin/Release/lusrmgr.exe index d9467c0..0a7cd5f 100644 Binary files a/lusrmgr/bin/Release/lusrmgr.exe and b/lusrmgr/bin/Release/lusrmgr.exe differ diff --git a/lusrmgr/lusrmgr.vbproj b/lusrmgr/lusrmgr.vbproj index 4e85180..a8ea88e 100644 --- a/lusrmgr/lusrmgr.vbproj +++ b/lusrmgr/lusrmgr.vbproj @@ -320,6 +320,7 @@ Auth.vb + Designer ChangePw.vb diff --git a/lusrmgr/obj/Debug/lusrmgr.exe b/lusrmgr/obj/Debug/lusrmgr.exe index d3ee9b5..d942c0e 100644 Binary files a/lusrmgr/obj/Debug/lusrmgr.exe and b/lusrmgr/obj/Debug/lusrmgr.exe differ diff --git a/lusrmgr/obj/Release/DesignTimeResolveAssemblyReferences.cache b/lusrmgr/obj/Release/DesignTimeResolveAssemblyReferences.cache index a2501e8..b301c28 100644 Binary files a/lusrmgr/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/lusrmgr/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/lusrmgr/obj/Release/Interop.ActiveDs.dll b/lusrmgr/obj/Release/Interop.ActiveDs.dll index 40b735b..c5874d0 100644 Binary files a/lusrmgr/obj/Release/Interop.ActiveDs.dll and b/lusrmgr/obj/Release/Interop.ActiveDs.dll differ diff --git a/lusrmgr/obj/Release/lusrmgr.exe b/lusrmgr/obj/Release/lusrmgr.exe index d9467c0..0a7cd5f 100644 Binary files a/lusrmgr/obj/Release/lusrmgr.exe and b/lusrmgr/obj/Release/lusrmgr.exe differ diff --git a/lusrmgr/obj/Release/lusrmgr.vbproj.GenerateResource.Cache b/lusrmgr/obj/Release/lusrmgr.vbproj.GenerateResource.Cache index 6543761..dcaa29c 100644 Binary files a/lusrmgr/obj/Release/lusrmgr.vbproj.GenerateResource.Cache and b/lusrmgr/obj/Release/lusrmgr.vbproj.GenerateResource.Cache differ