Sprache: VB
Diese Funktion prüft, ob ein Automatisches Anmelden aktiviert ist.
Die Funktion kann leicht abgewandelt werden, um die entsprechenden Werte in der Registry zu setzen.
Dies würde ich jedoch nicht empfehlen 😉
Imports Microsoft.Win32.Registry
Imports Microsoft.Win32.RegistryKey
Function AutoLogonEnabled() As Boolean
Dim Autologon As Boolean
Dim AutoAdminLogon As String
Dim AutoLogOnPassword As String
Dim AutoLogOnUser As String
Try
AutoLogOnUser = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "DefaultUserName", "")
Catch ex As Exception
End Try
Try
AutoLogOnPassword = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "DefaultPassword", "")
Catch ex As Exception
MessageBox.Show("Autologon will fail: No password set", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Try
AutoAdminLogon = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "AutoAdminLogon", "")
If AutoAdminLogon = 1 Then
Autologon = True
Else
Autologon = False
End If
Catch ex As Exception
End Try
Return Autologon
End Function
Imports Microsoft.Win32.Registry
Imports Microsoft.Win32.RegistryKey
Function AutoLogonEnabled() As Boolean
Dim Autologon As Boolean
Dim AutoAdminLogon As String
Dim AutoLogOnPassword As String
Dim AutoLogOnUser As String
Try
AutoLogOnUser = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "DefaultUserName", "")
Catch ex As Exception
End Try
Try
AutoLogOnPassword = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "DefaultPassword", "")
Catch ex As Exception
MessageBox.Show("Autologon will fail: No password set", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Try
AutoAdminLogon = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon", "AutoAdminLogon", "")
If AutoAdminLogon = 1 Then
Autologon = True
Else
Autologon = False
End If
Catch ex As Exception
End Try
Return Autologon
End Function
Alte URL:
/snippet/autologon/396
Gutes snippet, aber klitzekleiner Rechtschreibfehler im Registry-Key
der sollte [code]“HKEY_LOCAL_MACHINE…“[/code] heißen.
Danke für den Hinweis,
hab´ den Code entsprechend korrigiert.
Es war leider noch ein Fehle im Reg. Schlüssel.
Es muss selbstverständlich
HKEY_LOCAL_MACHINESoftwareMicrosoftWindows ….. heissen.
Im ursprünglichen Schlüssel war versehentlich
HKEY_LOCAL_MACHINESoftwareCMicrosoftWindows … eingetragen.
Das Snippet ist entsprechend korrigiert
Bei mir werden leider keine Werte zurück geliefert (.Net 4).
Nach …
Dim sMeinName As String = CStr(My.Computer.Registry.GetValue(„HKEY_LOCAL_MACHINESoftwareMicrosoftWindows NTCurrentVersionWinlogon“, „DefaultUserName“, CStr(„xxx“))) … hat sMeinName die Länge 0.