From 0594a02a889f984f5d41416d36bbe567f15ffa76 Mon Sep 17 00:00:00 2001 From: ms Date: Tue, 22 Sep 2020 09:43:50 +0200 Subject: [PATCH] SystemUpTimeReport, ... kleinigkeiten --- TSAnmeldung/Form1.vb | 56 ++++++++++++++------ TSAnmeldung/My Project/Resources.Designer.vb | 2 +- TSAnmeldung/My Project/Resources.resx | 2 +- TSAnmeldung/cBenutzer.vb | 28 +++++++++- TSAnmeldung/cRes.vb | 10 +++- 5 files changed, 76 insertions(+), 22 deletions(-) diff --git a/TSAnmeldung/Form1.vb b/TSAnmeldung/Form1.vb index c07246b..ca22c04 100644 --- a/TSAnmeldung/Form1.vb +++ b/TSAnmeldung/Form1.vb @@ -66,12 +66,13 @@ Public Class Main If Not ds.Tables(0).Rows.Count = 0 Then RemoveSitzung() End If - cSQL.InsertSQL("TbL_ThinClients", "(Benutzeranmeldename, Name, TeamviewerID, LastReport, ClientName) VALUES ( + cSQL.InsertSQL("TbL_ThinClients", "(Benutzeranmeldename, Name, TeamviewerID, LastReport, ClientName, SystemUpTime) VALUES ( '" & cRes.LocalUser.BenutzeranmeldeName & "', '" & cRes.LocalUser.Name & "', '" & cRes.LocalTeamviewerID & "', '" & Date.Now & "', -'" & cRes.LocalUser.Hostname & "')") +'" & cRes.LocalUser.Hostname & "', +'" & cRes.getuptime(True) & "')") End Function Sub RemoveSitzung() @@ -80,20 +81,43 @@ Public Class Main Public Sub WoBinIch() - If Environment.UserDomainName = "VERAGOST" Then - cboxStandort.SelectedItem = "VERAG SUB (rdpintern.verag.ag)" - LDAP = "LDAP://DC=VERAG,DC=OST,DC=DMN" - autoconnect = True - autologoff = True - ElseIf Environment.UserDomainName = "VERAG-SBG" Then - cboxStandort.SelectedItem = "VERAG SBG (terminalsbg.verag.ag)" - LDAP = "LDAP://DC=VERAG-SBG,DC=LOCAL" - autoconnect = True - autologoff = True - Else - autoconnect = False - autologoff = False - End If + 'MsgBox(Environment.UserDomainName) + + Select Case Environment.UserDomainName + Case "VERAGOST" + cboxStandort.SelectedItem = "VERAG SUB (rdpintern.verag.ag)" + LDAP = "LDAP://DC=VERAG,DC=OST,DC=DMN" + autoconnect = True + autologoff = True + Case "VERAG-SBG" + cboxStandort.SelectedItem = "VERAG SBG (terminalsbg.verag.ag)" + LDAP = "LDAP://DC=VERAG-SBG,DC=LOCAL" + autoconnect = True + autologoff = True + Case "IMEX" + cboxStandort.SelectedItem = "VERAG SUB (rdpintern.verag.ag)" + LDAP = "LDAP://DC=IMEX,DC=LOCAL" + autoconnect = True + autologoff = True + Case Else + autoconnect = False + autologoff = False + End Select + + 'If Environment.UserDomainName = "VERAGOST" Then + ' cboxStandort.SelectedItem = "VERAG SUB (rdpintern.verag.ag)" + ' LDAP = "LDAP://DC=VERAG,DC=OST,DC=DMN" + ' autoconnect = True + ' autologoff = True + 'ElseIf Environment.UserDomainName = "VERAG-SBG" Then + ' cboxStandort.SelectedItem = "VERAG SBG (terminalsbg.verag.ag)" + ' LDAP = "LDAP://DC=VERAG-SBG,DC=LOCAL" + ' autoconnect = True + ' autologoff = True + 'Else + ' autoconnect = False + ' autologoff = False + 'End If If sAppPath Like "*\bin\Debug" Or Environment.UserName = "miesenbeck" Or Environment.UserName = "Administrator" Or autologoff = False Then autoconnect = False diff --git a/TSAnmeldung/My Project/Resources.Designer.vb b/TSAnmeldung/My Project/Resources.Designer.vb index 3507901..06965ca 100644 --- a/TSAnmeldung/My Project/Resources.Designer.vb +++ b/TSAnmeldung/My Project/Resources.Designer.vb @@ -71,7 +71,7 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die 1.0.1.2 ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die 1.0.1.7 ähnelt. ''' Public ReadOnly Property ProgVersion() As String Get diff --git a/TSAnmeldung/My Project/Resources.resx b/TSAnmeldung/My Project/Resources.resx index 9bebec7..6851b87 100644 --- a/TSAnmeldung/My Project/Resources.resx +++ b/TSAnmeldung/My Project/Resources.resx @@ -122,7 +122,7 @@ ..\Resources\LogOff20.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - 1.0.1.2 + 1.0.1.7 ..\Resources\Reload20.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/TSAnmeldung/cBenutzer.vb b/TSAnmeldung/cBenutzer.vb index e6d0748..49b7a26 100644 --- a/TSAnmeldung/cBenutzer.vb +++ b/TSAnmeldung/cBenutzer.vb @@ -16,7 +16,7 @@ Public Class cBenutzer Property localdistinguishedName As String = "" Property suchname As String = "" Property Hostname As String = "" - + Property SystemUpTime As String = "" @@ -26,17 +26,41 @@ Public Class cBenutzer userPrincipalName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName Name = System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name Hostname = Environment.MachineName + SystemUpTime = GetSystemUpTimeInfo() + ' MsgBox(SystemUpTime) Catch End Try Domäne = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain.ToString BenutzeranmeldeName = Environment.UserDomainName & "\" & Environment.UserName If dcabfrage = True Then - 'cRes.DebugText = userPrincipalName & LDAPa + 'Class1.DebugText = userPrincipalName & LDAPa FillFromDC(userPrincipalName, "userPrincipalName", LDAPa) End If End Function + Private Shared Function GetSystemUpTimeInfo() As String + Try + Dim time = GetSystemUpTime() + Dim upTime = String.Format("{0:D2}d-{1:D2}h:{2:D2}m", time.Days, time.Hours, time.Minutes) ':{2:D2}s:{3:D3}ms , time.Seconds, time.Milliseconds + Return String.Format("{0}", upTime) + Catch ex As Exception + 'handle the exception your way + Return String.Empty + End Try + End Function + + Private Shared Function GetSystemUpTime() As TimeSpan + Try + Dim uptime = New PerformanceCounter("System", "System Up Time") + uptime.NextValue + Return TimeSpan.FromSeconds(uptime.NextValue) + Catch ex As Exception + 'handle the exception your way + Return New TimeSpan(0, 0, 0, 0) + End Try + End Function + Function FillFromDC(ByVal searchname As String, Optional ByVal searchfilter As String = "distinguishedName", Optional ByVal LDAP As String = "LDAP://DC=VERAG,DC=OST,DC=DMN") Try localdistinguishedName = searchname diff --git a/TSAnmeldung/cRes.vb b/TSAnmeldung/cRes.vb index bbed062..4a6255c 100644 --- a/TSAnmeldung/cRes.vb +++ b/TSAnmeldung/cRes.vb @@ -7,7 +7,8 @@ Public Class cRes Public Shared LocalUser As New cBenutzer Public Shared LocalTeamviewerID As String - Public Shared DBConString As String = "Server=buchhaltung.verag.ost.dmn\SQLEXPRESS;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;" + 'Public Shared DBConString As String = "Server=buchhaltung.verag.ost.dmn\SQLEXPRESS;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;" + Public Shared DBConString As String = "Server=sqlcluster.verag.ost.dmn\verag;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;" Public Shared DBConstringDev As String = "Server=DEVELOPER.verag.ost.dmn\DEVSQL;Initial Catalog=Doku;User ID=sa;Password=BmWr501956;Connection Timeout=5;" Public Shared Function GetUserGroupMembership(ByVal locUsername As String, ByVal LDAP As String) As List(Of String) @@ -95,13 +96,18 @@ Public Class cRes msgsend.Start() End Function - Public Shared Function getuptime() + Public Shared Function getuptime(Optional ByVal Shorty As Boolean = False) Dim pc As PerformanceCounter = New PerformanceCounter("System", "System Up Time") pc.NextValue() ' This returns zero for a reason I don't know ' This call to NextValue gets the correct value Dim ts As TimeSpan = TimeSpan.FromSeconds(pc.NextValue()) + If Shorty = True Then + Dim upTime = String.Format("{0:D2}d-{1:D2}h:{2:D2}m", ts.Days, ts.Hours, ts.Minutes) + Return upTime + Exit Function + End If Return ts.ToString() End Function