Compare commits

...

4 Commits

5 changed files with 141 additions and 60 deletions

1
Main.Designer.vb generated
View File

@@ -106,7 +106,6 @@ Partial Class TSUserReporter
Me.btnTest.TabIndex = 4 Me.btnTest.TabIndex = 4
Me.btnTest.Text = "Test" Me.btnTest.Text = "Test"
Me.btnTest.UseVisualStyleBackColor = True Me.btnTest.UseVisualStyleBackColor = True
Me.btnTest.Visible = False
' '
'Button1 'Button1
' '

138
Main.vb
View File

@@ -1,5 +1,8 @@
Imports System.Environment Imports System.Environment
Imports System.Globalization
Imports System.IO Imports System.IO
Imports System.Net.NetworkInformation
Imports Microsoft.Win32
Public Class TSUserReporter Public Class TSUserReporter
@@ -9,22 +12,33 @@ Public Class TSUserReporter
Public Printer As New List(Of Drucker) Public Printer As New List(Of Drucker)
Dim Standarddrucker As New Drucker("", "") Dim Standarddrucker As New Drucker("", "")
Dim Bondrucker As New Drucker("", "") Dim Bondrucker As New Drucker("", "")
Dim Niederlassung As New Drucker("", "")
Public Message As String Public Message As String
Dim ThinClient As String Dim ThinClient As String
Dim isTS As Boolean = False Dim isTS As Boolean = False
Dim ID As String = "" Dim ID As String = ""
Dim AutoUpdate As Boolean = True
Private Sub TSUserReporter_Load(sender As Object, e As EventArgs) Handles MyBase.Load Private Sub TSUserReporter_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Visible = False Me.Visible = False
StartTime = Date.Now StartTime = Date.Now
If IstServerErreichbar("sqlcluster.verag.ost.dmn") Then
'MsgBox("Erreichbar")
Else
' MsgBox("Nicht erreichbar")
UpdateTimer.Enabled = False
Exit Sub
End If
Routine() Routine()
SetPrinterRoutine() SetPrinterRoutine()
FillLabel() FillLabel()
ID = StartTime.ToString("dd.MM HH:mm:ss") & cRes.LocalUser.BenutzeranmeldeName ID = StartTime.ToString("yyyy.MM.dd HH:mm:ss ") & cRes.LocalUser.BenutzeranmeldeName
LogLogOn() LogLogOn()
End Sub End Sub
@@ -34,9 +48,12 @@ Public Class TSUserReporter
Sub Routine() Sub Routine()
Try Try
cRes.LocalUser.FillWithLoggedOnUser(True) cRes.LocalUser.FillWithLoggedOnUser(True, "LDAP://DC=VERAG,DC=OST,DC=DMN")
' MsgBox("1")
cRes.LocalTeamviewerID = getregkey() cRes.LocalTeamviewerID = getregkey()
' MsgBox("2")
cRes.LocalDomUser.getDomUserByBenutzerAnmeldename(Environment.UserDomainName, Environment.UserName) cRes.LocalDomUser.getDomUserByBenutzerAnmeldename(Environment.UserDomainName, Environment.UserName)
'MsgBox("3")
isTS = cRes.LocalUser.Hostname Like "TS*" isTS = cRes.LocalUser.Hostname Like "TS*"
'isTS = True 'isTS = True
@@ -49,7 +66,7 @@ Public Class TSUserReporter
CheckAutoLogOffAndIfthenAutoLogOff() CheckAutoLogOffAndIfthenAutoLogOff()
End If End If
Catch ex As Exception Catch ex As Exception
'MsgBox(ex.Message) MsgBox("Routine:" & ex.Message)
End Try End Try
End Sub End Sub
@@ -77,14 +94,23 @@ Public Class TSUserReporter
End Function End Function
Function getregkey() Function getregkey()
Dim Reg As String = Nothing Dim regObj As Object = Nothing
If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\TeamViewer", "ClientIDOfTSUser", Nothing) Is Nothing Then
Reg = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\TeamViewer", "ClientID", Nothing) ' 1. HKCU
Else regObj = Registry.GetValue("HKEY_CURRENT_USER\Software\TeamViewer", "ClientIDOfTSUser", Nothing)
Reg = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\TeamViewer", "ClientIDOfTSUser", Nothing) If regObj IsNot Nothing Then Return regObj.ToString()
End If
' 2. HKLM\WOW6432Node
regObj = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\TeamViewer", "ClientID", Nothing)
If regObj IsNot Nothing Then Return regObj.ToString()
' 3. HKLM (Standard-Pfad, 64-bit)
regObj = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\TeamViewer", "ClientID", Nothing)
If regObj IsNot Nothing Then Return regObj.ToString()
' Falls nichts gefunden
Return Nothing
Return Reg
End Function End Function
Function Report() Function Report()
@@ -110,7 +136,7 @@ Public Class TSUserReporter
'" & cRes.LocalUser.BenutzeranmeldeName & "', '" & cRes.LocalUser.BenutzeranmeldeName & "',
'" & cRes.LocalUser.Name & "', '" & cRes.LocalUser.Name & "',
'" & cRes.LocalTeamviewerID & "', '" & cRes.LocalTeamviewerID & "',
'" & Date.Now & "', '" & Date.Now.ToString("dd.MM.yyyy HH:mm:ss", New CultureInfo("de").NumberFormat) & "',
'" & cRes.LocalUser.Domäne & "', '" & cRes.LocalUser.Domäne & "',
'" & cRes.LocalUser.Company & "', '" & cRes.LocalUser.Company & "',
'" & StartTime.ToString("dd.MM HH:mm") & "', '" & StartTime.ToString("dd.MM HH:mm") & "',
@@ -135,7 +161,8 @@ Public Class TSUserReporter
Label1.Text &= "Letzte Aktualisierung:" & vbCrLf Label1.Text &= "Letzte Aktualisierung:" & vbCrLf
Label1.Text &= lastupdate & vbCrLf Label1.Text &= lastupdate & vbCrLf
Label1.Text &= Standarddrucker.Druckername & vbCrLf Label1.Text &= Standarddrucker.Druckername & vbCrLf
Label1.Text &= Bondrucker.Druckername & vbCrLf & vbCrLf Label1.Text &= Bondrucker.Druckername & vbCrLf
Label1.Text &= "TimasID: " & cRes.LocalUser.TimasID & vbCrLf
Label1.Text &= Message Label1.Text &= Message
End Function End Function
@@ -178,22 +205,32 @@ Public Class TSUserReporter
End Sub End Sub
Private Sub UpdateTimer_Tick(sender As Object, e As EventArgs) Handles UpdateTimer.Tick Private Sub UpdateTimer_Tick(sender As Object, e As EventArgs) Handles UpdateTimer.Tick
Routine() If AutoUpdate = True Then
Routine()
End If
End Sub End Sub
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
'If LoadDefaultPrinter(cRes.LocalUser.Hostname) Then Dim PrinterShortName As String = ""
' SetDefaultPrinter() For Each printer As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
' MsgBox(Drucker) Dim position As Integer = printer.LastIndexOf("\")
'End If If position > 0 Then
printer = printer.Substring(position + 1)
End If
PrinterShortName &= printer & vbCrLf
Next
MsgBox(PrinterShortName)
End Sub End Sub
Function SetUserEnviroment() Function SetUserEnviroment()
Try Try
Environment.SetEnvironmentVariable("PC_SERVER", "pbx3.flashnet.at", EnvironmentVariableTarget.User) Environment.SetEnvironmentVariable("PC_SERVER", Nothing, EnvironmentVariableTarget.User)
Environment.SetEnvironmentVariable("PC_USER", cRes.LocalDomUser.mit_username & "@verag", EnvironmentVariableTarget.User) Environment.SetEnvironmentVariable("PC_USER", Nothing, EnvironmentVariableTarget.User)
Environment.SetEnvironmentVariable("timasID", cRes.LocalUser.TimasID, EnvironmentVariableTarget.User)
' Environment.SetEnvironmentVariable("PC_USER", cRes.LocalDomUser.mit_username & "@verag", EnvironmentVariableTarget.User)
'Environment.SetEnvironmentVariable("PC_PASS", cRes.LocalDomUser.mit_pwd, EnvironmentVariableTarget.User) 'Environment.SetEnvironmentVariable("PC_PASS", cRes.LocalDomUser.mit_pwd, EnvironmentVariableTarget.User)
' Environment.SetEnvironmentVariable("PC_USE_CUSTOM_NOTIFICATIONS_AS_DEFAULT", "ENA", EnvironmentVariableTarget.User) ' Environment.SetEnvironmentVariable("PC_USE_CUSTOM_NOTIFICATIONS_AS_DEFAULT", "ENA", EnvironmentVariableTarget.User)
' MsgBox(Environment.GetEnvironmentVariable("PC_SErVER")) ' MsgBox(Environment.GetEnvironmentVariable("PC_SErVER"))
@@ -206,31 +243,7 @@ Public Class TSUserReporter
Public Function LoadDefaultPrinter(ByVal Hostname As String) Public Function LoadDefaultPrinter(ByVal Hostname As String)
Dim PrintINI As String = "" Dim PrintINI As String = ""
'If isTS Then
' PrintINI = "C:\Users\" & cRes.LocalUser.Username & "\Documents\AVISO_OPTIONS.txt"
' Try
' Dim lines = IO.File.ReadAllLines(PrintINI)
' Dim colCount = lines.First.Split(":"c).Length
' For Each line In lines
' Dim objFields = From field In line.Split(":"c)
' 'Select Case objFields(0).ToString
' ' Case Benutzername
' If String.Compare("PRINTER", objFields(0).ToString, True) = 0 Then
' Drucker = objFields(1).ToString
' '_ConString = objFields(2).ToString
' Return True
' Exit Function
' End If
' ' End Select
' Next
' Return False
' Catch ex As Exception
' ' MsgBox("Fehler beim Lesen TSAnmeldung.ini: " & vbCrLf & ex.Message)
' End Try
' Else
PrintINI = sNetlogon & "\ClientDrucker.ini" PrintINI = sNetlogon & "\ClientDrucker.ini"
Printer.Clear() Printer.Clear()
Try Try
@@ -243,7 +256,15 @@ Public Class TSUserReporter
'Select Case objFields(0).ToString 'Select Case objFields(0).ToString
' Case Benutzername ' Case Benutzername
If String.Compare(Hostname, objFields(0).ToString, True) = 0 Then If String.Compare(Hostname, objFields(0).ToString, True) = 0 Then
Dim p As New Drucker(objFields(1).ToString, objFields(2).ToString) Dim printername As String = objFields(1).ToString
Dim position As Integer = printername.LastIndexOf("\")
If position > 0 Then
printername = printername.Substring(position + 1)
End If
Dim p As New Drucker(printername, objFields(2).ToString)
Printer.Add(p) Printer.Add(p)
'_ConString = objFields(2).ToString '_ConString = objFields(2).ToString
' Return True ' Return True
@@ -272,12 +293,25 @@ Public Class TSUserReporter
End Function End Function
Public Function SetDefaultPrinter() Public Function SetDefaultPrinter()
Dim sp As String = ""
For Each p As Drucker In Printer For Each p As Drucker In Printer
If p.Druckertype = "" Or p.Druckertype = "Standard" Then If p.Druckertype = "" Or p.Druckertype = "Standard" Then
''ip = installed printer
''sp = standard printer
For Each ip As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
If ip.LastIndexOf(p.Druckername, StringComparison.OrdinalIgnoreCase) > 0 Then
sp = ip
End If
Next
Standarddrucker = p Standarddrucker = p
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", p.Druckername) My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", sp)
ElseIf p.Druckertype = "Bon" Then ElseIf p.Druckertype = "Bon" Then
Bondrucker = p Bondrucker = p
ElseIf p.Druckertype = "Niederlassung" Then
Niederlassung = p
End If End If
Next Next
writeoutAVISO_OPTIONS() writeoutAVISO_OPTIONS()
@@ -309,7 +343,8 @@ Public Class TSUserReporter
Text = "" Text = ""
Else Else
Text = "PRINTER:" & Standarddrucker.Druckername & vbCrLf Text = "PRINTER:" & Standarddrucker.Druckername & vbCrLf
Text &= "BON:" & Bondrucker.Druckername Text &= "BON:" & Bondrucker.Druckername & vbCrLf
Text &= "Niederlassung:" & Niederlassung.Druckername
End If End If
Try Try
System.IO.File.WriteAllText(PrintINI, Text) System.IO.File.WriteAllText(PrintINI, Text)
@@ -320,6 +355,17 @@ Public Class TSUserReporter
End Sub End Sub
Function IstServerErreichbar(server As String) As Boolean
Try
Dim ping As New Ping()
Dim reply = ping.Send(server, 1000) ' Timeout 1 Sekunde
Return reply.Status = IPStatus.Success
Catch
Return False
End Try
End Function
End Class End Class
Public Class Drucker Public Class Drucker

View File

@@ -14,9 +14,10 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl> <IsWebBootstrapper>false</IsWebBootstrapper>
<Install>true</Install> <PublishUrl>\\app01\Tools\Test\</PublishUrl>
<InstallFrom>Disk</InstallFrom> <Install>false</Install>
<InstallFrom>Unc</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
@@ -24,14 +25,14 @@
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<DefineDebug>true</DefineDebug> <DefineDebug>true</DefineDebug>
@@ -69,7 +70,10 @@
<SignManifests>true</SignManifests> <SignManifests>true</SignManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ManifestCertificateThumbprint>443CA3745EE904EED98572A89099259301BA06D1</ManifestCertificateThumbprint> <ManifestCertificateThumbprint>1A931924D8078AE56D64EFA22EB781250AB2DEF4</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />

View File

@@ -17,8 +17,9 @@ Public Class cBenutzer
Property suchname As String = "" Property suchname As String = ""
Property Hostname As String = "" Property Hostname As String = ""
Property Company As String = "" Property Company As String = ""
Property Username As String = "" Property Username As String = ""
Property sAMAccountName As String = ""
Property TimasID As String = ""
'test 'test
@@ -26,17 +27,31 @@ Public Class cBenutzer
Function FillWithLoggedOnUser(Optional ByVal dcabfrage As Boolean = False, Optional ByVal LDAPa As String = "") '"LDAP://DC=VERAG,DC=OST,DC=DMN") Function FillWithLoggedOnUser(Optional ByVal dcabfrage As Boolean = False, Optional ByVal LDAPa As String = "") '"LDAP://DC=VERAG,DC=OST,DC=DMN")
Try Try
userPrincipalName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName userPrincipalName = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName
Name = System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name Name = System.DirectoryServices.AccountManagement.UserPrincipal.Current.Name
Hostname = Environment.MachineName Hostname = Environment.MachineName
Catch
Catch ex As Exception
MsgBox("FillWithLoggedOnUser:" & ex.Message)
End Try End Try
Domäne = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain.ToString Domäne = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain.ToString
BenutzeranmeldeName = Environment.UserDomainName & "\" & Environment.UserName BenutzeranmeldeName = Environment.UserDomainName & "\" & Environment.UserName
Username = Environment.UserName Username = Environment.UserName
If dcabfrage = True Then If dcabfrage = True Then
'Class1.DebugText = userPrincipalName & LDAPa Try
FillFromDC(userPrincipalName, "userPrincipalName", LDAPa) 'Class1.DebugText = userPrincipalName & LDAPa
FillFromDC(userPrincipalName, "userPrincipalName", LDAPa)
FillTimasID()
Catch ex As Exception
MsgBox("dcabfrage: " & ex.Message)
End Try
End If End If
End Function End Function
@@ -100,6 +115,7 @@ Public Class cBenutzer
.PropertiesToLoad.Add("msDS-PrincipalName") .PropertiesToLoad.Add("msDS-PrincipalName")
.PropertiesToLoad.Add("userPrincipalName") .PropertiesToLoad.Add("userPrincipalName")
.PropertiesToLoad.Add("company") .PropertiesToLoad.Add("company")
.PropertiesToLoad.Add("sAMAccountName")
End With End With
Dim Result As DirectoryServices.SearchResult = searcher.FindOne Dim Result As DirectoryServices.SearchResult = searcher.FindOne
@@ -115,9 +131,25 @@ Public Class cBenutzer
Me.msDSPrincipalName = blablabla(Result, "msDS-PrincipalName") Me.msDSPrincipalName = blablabla(Result, "msDS-PrincipalName")
Me.userPrincipalName = blablabla(Result, "userPrincipalName") Me.userPrincipalName = blablabla(Result, "userPrincipalName")
Me.Company = blablabla(Result, "company") Me.Company = blablabla(Result, "company")
Me.sAMAccountName = blablabla(Result, "sAMAccountName")
Catch ex As Exception Catch ex As Exception
MsgBox("FillFromDC: " & ex.Message) 'MsgBox("FillFromDC: " & ex.Message)
End Try
End Function
Function FillTimasID()
Try
Dim ds As New DataSet
cSQL.SQL2DS("SELECT mit_timasID FROM ADMIN.dbo.tblMitarbeiter where mit_AliasAD_Username = '" & Me.sAMAccountName & "'", ds)
If ds.Tables.Count > 0 Then
If ds.Tables(0).Rows(0).Item(0) > 0 Then
Me.TimasID = ds.Tables(0).Rows(0).Item(0)
End If
End If
Catch ex As Exception
' MsgBox("FillTimasID: " & ex.Message)
End Try End Try
End Function End Function

View File

@@ -108,7 +108,7 @@ Public Class cDomUser
Next Next
Catch ex As Exception Catch ex As Exception
'MsgBox("getDomUserByBenutzerAnmeldename" & Dom & vbCrLf & ds.Tables(0).Rows.Count & Username & vbCrLf & ex.Message) MsgBox("getDomUserByBenutzerAnmeldename" & Dom & vbCrLf & ds.Tables(0).Rows.Count & Username & vbCrLf & ex.Message)
End Try End Try
' MsgBox("hier") ' MsgBox("hier")