From 018cbc5ae0650335b92bcc8137db9fdbfee2ae24 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Wed, 29 Apr 2026 15:47:04 +0200 Subject: [PATCH] Refactor session logout logic into helper method Extracted duplicated session logout code into a new private method, LogoutCurrentSession. This method is now used in both GetWMSessionAsUser and GetWMSession to improve code reuse and maintainability. Exception handling for session logout remains silent to avoid issues with already-terminated sessions. --- ToolCollection/ClassWindream_allgemein.vb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ToolCollection/ClassWindream_allgemein.vb b/ToolCollection/ClassWindream_allgemein.vb index ce8e7d5..e14bf3d 100644 --- a/ToolCollection/ClassWindream_allgemein.vb +++ b/ToolCollection/ClassWindream_allgemein.vb @@ -49,7 +49,20 @@ Public Class ClassWindream_allgemein ' Process.GetCurrentProcess.Kill() End If End Sub + Private Sub LogoutCurrentSession() + If Not IsNothing(CURRENToWMSession) Then + Try + CURRENToWMSession.Logout() + Catch + ' ignorieren – Session war evtl. schon tot + End Try + CURRENToWMSession = Nothing + End If + End Sub + Public Function GetWMSessionAsUser(Domain, ServerName, UserName, Password) + LogoutCurrentSession() + Dim SessionAsUser Dim aConnect, aUserId, aSession On Error Resume Next @@ -143,14 +156,7 @@ Public Class ClassWindream_allgemein End Function Private Function GetWMSession() - If Not IsNothing(CURRENToWMSession) Then - Try - CURRENToWMSession.Logout() - Catch - ' ignorieren – Session war evtl. schon tot - End Try - CURRENToWMSession = Nothing - End If + LogoutCurrentSession() Try Try