From 4eda7c93ab5b5547aeed904325b9f8e3f7021cee Mon Sep 17 00:00:00 2001 From: Jonathan Perry Date: Tue, 5 Dec 2017 12:08:46 -0500 Subject: [PATCH] Added a check for filters before adding them to the XML file --- .../GroupPolicyNetworkLocations.vb | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/GroupPolicyNetworkLocations/GroupPolicyNetworkLocations.vb b/GroupPolicyNetworkLocations/GroupPolicyNetworkLocations.vb index 9e5a4fd..731f2eb 100644 --- a/GroupPolicyNetworkLocations/GroupPolicyNetworkLocations.vb +++ b/GroupPolicyNetworkLocations/GroupPolicyNetworkLocations.vb @@ -350,30 +350,32 @@ Public Class GroupPolicyNetworkLocations ShortcutPropPid1, ShortcutPropTargetType, SharePropAction, ShortcutPropComment, ShortcutPropShortcutKey, ShortcutPropStartIn, ShortcutPropArguments, ShortcutPropIconIndex, shareRow("ShareTarget"), ShortcutPropIconPath, ShortcutPropWindow, ShortcutPropShortcutPath1, shareRow("ShareName"), ShortcutPropShortcutPath3)) ' Group for filters. - ' TODO: Maybe check to see if there are any filters before just throwing them in there... - sbIniFilesXML.AppendLine(" ") - sbFoldersXML.AppendLine(" ") - sbShortcutsXML.AppendLine(" ") - - Dim i As Integer = 1 ' A counter, even though I only need to know which is the first - For Each groupRow In tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))) - Dim strBool As String = "AND" - If i > 1 Then strBool = FilterGroupBool ' The first filter is always AND - ' Create a string, because all of them get the same thing - Dim strFilterGroup As String = String.Format(" ", - strBool, FilterGroupNot, groupRow("GroupName"), groupRow("GroupSID"), FilterGroupUserContext, FilterGroupPrimaryGroup, FilterGroupLocalGroup) - ' Write it to all of them - sbIniFilesXML.AppendLine(strFilterGroup) - sbFoldersXML.AppendLine(strFilterGroup) - sbShortcutsXML.AppendLine(strFilterGroup) - - i += 1 ' Increase the counter - Next - ' Close filter group - sbIniFilesXML.AppendLine(" ") - sbFoldersXML.AppendLine(" ") - sbShortcutsXML.AppendLine(" ") + If tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))).Count() > 0 Then + sbIniFilesXML.AppendLine(" ") + sbFoldersXML.AppendLine(" ") + sbShortcutsXML.AppendLine(" ") + + Dim i As Integer = 1 ' A counter, even though I only need to know which is the first + For Each groupRow In tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))) + Dim strBool As String = "AND" + If i > 1 Then strBool = FilterGroupBool ' The first filter is always AND + ' Create a string, because all of them get the same thing + Dim strFilterGroup As String = String.Format(" ", + strBool, FilterGroupNot, groupRow("GroupName"), groupRow("GroupSID"), FilterGroupUserContext, FilterGroupPrimaryGroup, FilterGroupLocalGroup) + ' Write it to all of them + sbIniFilesXML.AppendLine(strFilterGroup) + sbFoldersXML.AppendLine(strFilterGroup) + sbShortcutsXML.AppendLine(strFilterGroup) + + i += 1 ' Increase the counter + Next + + ' Close filter group + sbIniFilesXML.AppendLine(" ") + sbFoldersXML.AppendLine(" ") + sbShortcutsXML.AppendLine(" ") + End If ' close the groups sbIniFilesXML.AppendLine(" ") @@ -385,17 +387,21 @@ Public Class GroupPolicyNetworkLocations IniClsid, Ini2Name, Ini2Status, ShareImage, shareRow("LastModified"), shareRow("Ini2UID"), ShareUserContext, ShareBypassErrors)) sbIniFilesXML.AppendLine(String.Format(" ", IniPropPath1, shareRow("ShareName"), IniPropPath3, IniPropSection, Ini2PropValue, Ini2PropProperty, SharePropAction)) - sbIniFilesXML.AppendLine(" ") - i = 1 - For Each groupRow In tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))) - Dim strBool As String = "AND" - If i > 1 Then strBool = "OR" - Dim strFilterGroup As String = String.Format(" ", - strBool, groupRow("GroupName"), groupRow("GroupSID")) - sbIniFilesXML.AppendLine(strFilterGroup) - i += 1 - Next - sbIniFilesXML.AppendLine(" ") + + If tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))).Count() > 0 Then + sbIniFilesXML.AppendLine(" ") + Dim i As Integer = 1 ' A counter, even though I only need to know which is the first + For Each groupRow In tableFilterGroups.Select(String.Format("ShareName = '{0}'", shareRow("ShareName"))) + Dim strBool As String = "AND" + If i > 1 Then strBool = "OR" + Dim strFilterGroup As String = String.Format(" ", + strBool, groupRow("GroupName"), groupRow("GroupSID")) + sbIniFilesXML.AppendLine(strFilterGroup) + i += 1 + Next + sbIniFilesXML.AppendLine(" ") + End If + sbIniFilesXML.AppendLine(" ") Next