Skip to content

Instantly share code, notes, and snippets.

@amar-r
Created May 9, 2017 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amar-r/0fa53e4a36347b4e4cd22c70e1160a28 to your computer and use it in GitHub Desktop.
Save amar-r/0fa53e4a36347b4e4cd22c70e1160a28 to your computer and use it in GitHub Desktop.
Imports System.Threading
Imports Microsoft.Win32
Imports System.IO
Imports System.DirectoryServices
Public Class frmMain
Private infoThread As Thread
Public list As New List(Of String)
Private Sub initialize()
CheckForIllegalCrossThreadCalls = False
infoThread = New Thread(Sub() AppCheck())
infoThread.IsBackground = True
infoThread.Start()
End Sub
Private Sub AppCheck()
'---Populate labels
txtName.Text = Environment.MachineName
'---Get AD information
Dim ADinfo As String() = getComputerPath.Split(New Char() {","c})
txtOU.Text = ADinfo(1).Replace("OU=", "")
'---Create variable to read Registry key values
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall", True)
'---Create dictionary to store info https://www.dotnetperls.com/dictionary-vbnet
Dim dictionary As New Dictionary(Of String, Boolean) From {
{"Adobe Reader", False},
{"Adobe Flash", False},
{"Adobe Shockwave", False},
{"Citrix Receiver", False},
{"FINRA VPN", False},
{"MBAM Client", False},
{"McAfee Agent", False},
{"McAfee DLP", False},
{"McAfee HIPS", False},
{"McAfee VSE", False},
{"Microsoft Office", False},
{"Microsoft Silverlight", False},
{"Microsoft XML", False},
{"Oracle Java", False},
{"WebEx Meeting Center", False},
{"WebEx Network Recording Player", False},
{"WebEx Recorder and Player", False},
{"WinZip", False}
}
'---Application Install verification
For Each uninstallName As String In regKey.GetSubKeyNames
Dim uninstallKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" & uninstallName, True)
Dim strDisplayName As String = uninstallKey.GetValue("DisplayName")
Dim strInstallLocation As String = uninstallKey.GetValue("InstallLocation")
Try
If (Not strDisplayName Is Nothing) Then
If (strDisplayName.Contains("Reader")) Then
dictionary("Adobe Reader") = True
ElseIf (strDisplayName.Contains("Adobe Flash")) Then
dictionary("Adobe Flash") = True
ElseIf (strDisplayName.Contains("Adobe Shockwave")) Then
dictionary("Adobe Shockwave") = True
ElseIf (strDisplayName.Contains("Citrix Receiver")) Then
dictionary("Citrix Receiver") = True
ElseIf (strDisplayName.Contains("BIG-IP Edge Client")) Then
dictionary("FINRA VPN") = True
ElseIf (strDisplayName.Contains("MSXML")) Then
dictionary("Microsoft XML") = True
ElseIf (strDisplayName.Contains("Java")) Then
dictionary("Oracle Java") = True
ElseIf (strDisplayName.Contains("Cisco WebEx Meeting Center")) Then
dictionary("WebEx Meeting Center") = True
ElseIf (strDisplayName.Contains("Network Recording Player")) Then
dictionary("WebEx Network Recording Player") = True
ElseIf (strDisplayName.Contains("WebEx Recorder and Player")) Then
dictionary("WebEx Recorder and Player") = True
End If
End If
Catch ex As Exception
End Try
Next
Dim BitLocker As String = "C:\Program Files\microsoft\MDOP MBAM\mbamclientUI.exe"
If File.Exists(BitLocker) Then
dictionary("MBAM Client") = True
End If
Dim strWinZip As String = "C:\Program Files\WinZip\WINZIP64.EXE"
If File.Exists(strWinZip) Then
dictionary("WinZip") = True
End If
Dim Silverlight As String = "C:\Program Files\Microsoft Silverlight\sllauncher.exe"
If File.Exists(Silverlight) Then
dictionary("Microsoft Silverlight") = True
End If
'---Check different Office versions
Dim Office2016 As String = "C:\Program Files\Microsoft Office\Office16\OUTLOOK.EXE"
Dim Office2013 As String = "C:\Program Files (x86)\Microsoft Office\Office15\OUTLOOK.EXE"
Dim Office2010 As String = "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
If File.Exists(Office2016) OrElse File.Exists(Office2010) OrElse File.Exists(Office2013) Then
dictionary("Microsoft Office") = True
End If
'---Check McAfee Suite
Dim Agent As String = "C:\Program Files\McAfee\Agent\cmdagent.exe"
Dim Agent2 As String = "C:\Program Files (x86)\McAfee\Common Framework\cmdagent.exe"
Dim DLP As String = "C:\Program Files\McAfee\DLP\Agent\fcag.exe"
Dim HIPS As String = "C:\Program Files\McAfee\Host Intrusion Prevention\FireSvc.exe"
Dim VSE As String = "C:\Program Files (x86)\McAfee\VirusScan Enterprise\shstat.exe"
If File.Exists(Agent) OrElse File.Exists(Agent2) Then
dictionary("McAfee Agent") = True
End If
If File.Exists(DLP) Then
dictionary("McAfee DLP") = True
End If
If File.Exists(HIPS) Then
dictionary("McAfee HIPS") = True
End If
If File.Exists(VSE) Then
dictionary("McAfee VSE") = True
End If
'---Check McAfee EP10 DO IF WINDOWS 10 THEN CHECK THESE FILES
'Dim EPPlatform As String = "C:\Program Files\McAfee\Endpoint Security\Endpoint Security Platform\mfeesp.exe"
'Dim EPFirewall As String = "C:\Program Files\McAfee\Endpoint Security\Firewall\mfefw.exe"
'Dim EPThreatPrevention As String = "C:\Program Files\McAfee\Endpoint Security\Threat Prevention\mfetp.exe"
'If File.Exists(EPPlatform) Then
' dictionary.Add("McAfee Endpoint Platform", True)
'Else
' dictionary.Add("McAfee Endpoint Platform", False)
'End If
'If File.Exists(EPFirewall) Then
' dictionary.Add("McAfee Firewall", True)
'Else
' dictionary.Add("McAfee Firewall", False)
'End If
'---Check info based on computer model or OS
Dim compinfo As New WMI()
With compinfo
Dim DisplayLink As String = "C:\Program Files\DisplayLink Core Software\DisplayLinkUI.exe"
Dim Model As String = .Model
Dim Version As String = .Version
If Version.Contains("ThinkPad") Then
If File.Exists(DisplayLink) Then
dictionary.Add("DisplayLink", True)
Else
dictionary.Add("DisplayLink", False)
End If
End If
End With
'---Add missing applications to list https://www.dotnetperls.com/dictionary-vbnet
Dim pair As KeyValuePair(Of String, Boolean)
For Each pair In dictionary
If pair.Value = False Then
lstMissing.Items.Add(pair.Key)
Else
lstInstalled.Items.Add(pair.Key)
End If
Next
'---Set acknowledgement buttons
Dim Manual As String = "manually"
If lstMissing.Items.Count > 0 Then
rbSuccess.Visible = False
rbManual.Text = "I have acknowledged there are " & lstMissing.Items.Count & " missing program(s) and I will manually install them."
rbImage.Text = "I have acknowledged there are " & lstMissing.Items.Count & " missing program(s) and I will re-image the machine."
Else
rbImage.Visible = False
rbManual.Visible = False
rbSuccess.ForeColor = Color.Green
rbSuccess.Text = "I have acknowledged the successfull installation of the OSD Task Sequence."
End If
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
initialize()
LogError("AppVerification", "AppVerification ran at " & Now().ToString & ".", EventLogEntryType.Warning)
gbBorder.Location = New Point((ClientSize.Width - gbBorder.Width) / 2, (ClientSize.Height - gbBorder.Height) / 2)
End Sub
Private Sub LogError(ByVal Source As String, ByVal Message As String, ByVal EntryType As EventLogEntryType)
Dim el As New EventLog("Application")
el.Source = Source
Try
el.WriteEntry(Message, EntryType, 1713)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'---Get AD info
Private Function getComputerPath() As String
Dim OUName As String = "Not Found"
Try
Dim objectFound As Boolean = False
Dim searcher As DirectorySearcher = New DirectorySearcher()
searcher.SearchRoot = New DirectoryEntry("LDAP://DC=,DC=,DC=,DC=")
searcher.Filter = "(&(objectClass=computer)(name=" & My.Computer.Name & "))"
searcher.SearchScope = SearchScope.Subtree
searcher.PropertiesToLoad.Add("cn")
For Each result As SearchResult In searcher.FindAll()
If result Is Nothing Then
OUName = "Object not found in AD"
Else
Dim computerObject = result.GetDirectoryEntry()
OUName = "LDAP://" & computerObject.Properties("distinguishedName").Value
objectFound = True
End If
Next
Catch ex As Exception
OUName = "Error: " & ex.Message
End Try
Return OUName
End Function
'---Okay button click action
Private Sub btnOkay_Click(sender As Object, e As EventArgs) Handles btnOkay.Click
Close()
Dim user As String = Environment.UserName
If rbManual.Checked Then
LogError("AppChecker", user & " acknowledged OSD error at " & Now().ToString & " and will manually install software." & vbCrLf & String.Join(vbCrLf, list), EventLogEntryType.Warning)
ElseIf rbImage.Checked Then
LogError("AppChecker", user & " acknowledged OSD error at " & Now().ToString & " and will re-image machine." & vbCrLf & String.Join(vbCrLf, list), EventLogEntryType.Warning)
Else
LogError("AppChecker", user & " acknowledged OSD completion at " & Now().ToString & ".", EventLogEntryType.Warning)
End If
End Sub
'---Radio button check action
Private Sub rbSuccess_CheckedChanged(sender As Object, e As EventArgs) Handles rbSuccess.CheckedChanged
btnOkay.Enabled = True
End Sub
Private Sub rbManual_CheckedChanged(sender As Object, e As EventArgs) Handles rbManual.CheckedChanged
btnOkay.Enabled = True
End Sub
Private Sub rbImage_CheckedChanged(sender As Object, e As EventArgs) Handles rbImage.CheckedChanged
btnOkay.Enabled = True
End Sub
'---Hide Close button
Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim myCp As CreateParams = MyBase.CreateParams
myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
Return myCp
End Get
End Property
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment