1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
Aufruf z.B.: txtPDFTKPath.Text = alg.GetSystemFile("pdftk")
'''''' <summary>
'''''' Stellt fest, ob in den Systemverzeichnissen eine Datei vorhanden ist
'''''' und WO sie vorhanden ist.
'''''' Aufruf Beispiel:
'''''' txtPDFTKPath.Text = alg.GetSystemFile("pdftk")
'''''' </summary>
'''''' <param name="FileName">
'''''' Dateiname mit oder ohne Erweiterung "pdftk" ODER "pdftk.exe"
'''''' </param>
'''''' <param name="extension">
'''''' Die Dateiendung z.B.: .exe ODER exe ("." wird automatisch hinzugefügt)
'''''' </param>
'''''' <param name="DefaultFullPath">
'''''' Der Standardwert der zurückgegeben wird, falls NICHTS gefunden wurde.
'''''' </param>
'''''' <returns></returns>
'''''' <remarks></remarks>
Public Function GetSystemFile(ByVal FileName As String, Optional ByVal extension As String = ".exe", Optional ByVal DefaultFullPath As String = "") As String
Dim ext As String = extension
If ext <> "" AndAlso Not ext.StartsWith(".") Then ext = "." & ext
If FileName.EndsWith(ext) Then ext = ""
Dim environmentVariables As IDictionary = Environment.GetEnvironmentVariables()
Dim de As DictionaryEntry
For Each de In environmentVariables
If de.Key = "Path" Then
Dim splt() As String
splt = de.Value.ToString.Split(";")
For i As Integer = 0 To splt.Length - 1
Dim combined As String = splt(i)
If combined <> "" AndAlso Not combined.EndsWith("\") Then combined = combined & "\"
combined = combined & FileName & ext
Try
If IO.File.Exists(combined) Then
Return combined
End If
Catch ex As Exception
MessageBox.Show("Fehler beim auslesen des Verzeichnisses." & vbCrLf & vbCrLf & "Meldung: " & vbCrLf & ex.Message, "Fehler...!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
Next
End If
Next de
Return DefaultFullPath
End Function
|