How do I ignore Windows Defender when calling SecurityCenter2? - windows-8

I'm working on a script to detect whether or not there is an antivirus solution running on a Windows machine. When running on Windows 8 I'm getting false positives that antivirus is disabled when running a third-party antivirus solution due to Windows Defender always being around, although disabled.
I can see the productState for the third-party antivirus software as valid and reporting correctly, however my script is only pulling Windows Defender entries.
I need to keep the entries for Windows Defender, however I'm only interested in Windows Defender if there isn't any other antivirus software installed. I ran the following command from a command prompt to retrieve the data, which shows two separate entries.
WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get /Format:List
I would like to only grab the third-party antivirus software if it's installed, otherwise keep the Windows Defender information.
How I'm trying to do this is by calling the instanceGUID and compare it against the Windows Defender GUID, however I'm getting a few false positives. Is there a way for me to parse this data correctly and ideally only look at the third-party information?
I'm including the full script to show exactly what I'm looking at, and I can cut it down if needed:
Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
For Each objAntiVirusProduct In colAVItems
strinstanceGuid = (objAntiVirusProduct.instanceGuid)
strWinDefGUID = "{D68DDC3A-831F-4fae-9E44-DA132C1ACF46}"
If strinstanceGuid <> strWinDefGUID Then
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "393472" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
End If
Else
If Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11" Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
End If
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
End If
Next
Just to reiterate, this is a Windows 8 issue.

I found a solution to my issue. Basically I ended up putting an If statement before my For statement looking at how many entries where in the Security Center WMI for AntiVirus. If there are 0 then it reports back none, If there is 1 installed then it reads the info, and if there are more than 1 it ignores Windows Defender and reads the rest. I'm including full code for future users.
Dim objWMIServiceSC,objAntiVirusProduct,colAVItems,AvStatus
Set objWMIServiceSC = GetObject("winmgmts:\\.\root\SecurityCenter2")
Set colAVItems = objWMIServiceSC.ExecQuery("Select * from AntiVirusProduct")
If colAVItems.count = 0 Then
strdisplayName = "No"
errors("Acceptable AntiVirus software found ") = "NO"
ElseIf colAVItems.count = 1 Then
For Each objAntiVirusProduct In colAVItems
strdisplayName = (objAntiVirusProduct.displayName)
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "266240" _
OR objAntiVirusProduct.ProductState = "331776" _
OR objAntiVirusProduct.ProductState = "397568" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
errors("Antivirus scanning is ") = "DISABLED"
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
errors("AntiVirus Definitions are ") = "OUTDATED"
End If
Next
ElseIf colAVItems.count > 1 Then
For Each objAntiVirusProduct In colAVItems
If (objAntiVirusProduct.displayName) <> "Windows Defender" Then
strdisplayName = (objAntiVirusProduct.displayName)
AvStatus = Hex(objAntiVirusProduct.ProductState)
If (objAntiVirusProduct.ProductState = "393472" _
OR objAntiVirusProduct.ProductState = "266240" _
OR objAntiVirusProduct.ProductState = "331776" _
OR objAntiVirusProduct.ProductState = "397568" _
OR Mid(AvStatus, 2, 2) = "10" Or Mid(AvStatus, 2, 2) = "11" _
OR Mid(AvStatus, 5, 2) = "10" Or Mid(AvStatus, 5, 2) = "11") Then
strproductState = "ENABLED"
Else
strproductState = "DISABLED"
errors("Antivirus scanning is ") = "DISABLED"
End If
If Mid(AvStatus, 4, 2) = "00" Then
strdefinitionState = "CURRENT"
ElseIf Mid(AvStatus, 4, 2) = "10" Then
strdefinitionState = "OUTDATED"
errors("AntiVirus Definitions are ") = "OUTDATED"
End If
End If
Next
End If

Doing all this string stuff looks a little complicated. You could also just do:
int bitmaskUpToDate = 0x000010;
bool upToDate = number & bitmaskUpToDate == bitmaskUpToDate;
int bitmaskEnabled = 0x001000;
bool isEnabled = number & bitmaskEnabled == bitmaskEnabled;
This is just a quick demo for the bitmask stuff. I did not doublecheck if I got the indices correct.

Related

vba listbox to show background color for header

I want to show different background color to row 1 in listback. I am using below code to color but it is changing entire background for all listbox rows. Please help if there is anyway to color first row of listbox.
UserForm4.ListBox15.BackColor = RGB(0, 0, 255)
If lv_item = 0 Then
UserForm4.ListBox15.AddItem "Sr no" 'Additem creates a new row
UserForm4.ListBox15.List(lv_item, 1) = "Volumn Processed"
UserForm4.ListBox15.List(lv_item, 2) = "Volumn Target"
UserForm4.ListBox15.List(lv_item, 3) = "Approached"
UserForm4.ListBox15.List(lv_item, 4) = "Confidence Level"
End If
lv_item = 1
With rs
rs.MoveFirst
While Not rs.EOF
UserForm4.ListBox15.AddItem rs.Fields("Sr no").Value 'Additem creates a new row
UserForm4.ListBox15.List(lv_item, 1) = rs.Fields("Volumn Processed").Value
UserForm4.ListBox15.List(lv_item, 2) = rs.Fields("Volumn Target").Value
UserForm4.ListBox15.List(lv_item, 3) = rs.Fields("Approached").Value
UserForm4.ListBox15.List(lv_item, 4) = rs.Fields("Confidence Level").Value
UserForm4.ListBox15.List(lv_item, 6) = rs.Fields("Unique ID").Value

VBA Excel : Adding a second set of commands if Textbox is changed

I am busy building a Shift rotation schedule using VBA and Excel
at the moment I am sitting with a problem
In my Userform I have 434 textboxes that give the shift allocation per agent
as seen below:
Now in order to get these colours to change I have a code in every Textbox (Named A1,A2.....A31 then B1, B2,,,,,,B31 etc.)
the code goes as follows:
Private Sub A1_Change()
If A1.Text = "A" Then
A1.BackColor = &H602000
ElseIf A1.Text = "B" Then
A1.BackColor = &HC07000
ElseIf A1.Text = "C" Then
A1.BackColor = &HEED7BD
ElseIf A1.Text = "D" Then
A1.BackColor = &HF0B000
ElseIf A1.Text = "W" Then
A1.BackColor = &HFF&
ElseIf A1.Text = "M" Then
A1.BackColor = &H808080
ElseIf A1.Text = "S" Then
A1.BackColor = &HA6A6A6
ElseIf A1.Text = "P" Then
A1.BackColor = &H7D7DFF
ElseIf A1.Text = "L" Then
A1.BackColor = &HD9D9D9
End If
End Sub
I am trying now to allow the user to edit the shifts manually, Once this is done, they would be able to click on a set button that will copy the data from the Specific Agents row onto the worksheet based on the month selected for example:
Private Sub CommandButton2_Click()
If Sheets(3).Range("B5").Text = "2018-01-01" Then
Worksheets("LAYOUT").Activate
Sheets("LAYOUT").Range(B4).Text = A1.Value
Sheets("LAYOUT").Range(C4).Text = A2.Value
Sheets("LAYOUT").Range(D4).Text = A3.Value
Sheets("LAYOUT").Range(E4).Text = A4.Value
Sheets("LAYOUT").Range(F4).Text = A5.Value
.
.
.
.
Sheets("LAYOUT").Range(AD4).Text = A29.Value
Sheets("LAYOUT").Range(AE4).Text = A30.Value
Sheets("LAYOUT").Range(AF4).Text = A31.Value
ElseIf Sheets(3).Range("B5").Text = "2018-02-01" Then
Worksheets(1).Activate
Sheets("LAYOUT").Range(AG4).Text = A1.Value
.
.
.
.
.
Sheets("LAYOUT").Range(BJ4).Text = A30.Value
Sheets("LAYOUT").Range(BK4).Text = A31.Value
ElseIf Sheets(3).Range("B5").Text = "2018-03-01" Then
Worksheets(1).Activate
Sheets("LAYOUT").Range(BI4).Text = A1.Value
Sheets("LAYOUT").Range(BJ4).Text = A2.Value
ect
Now when I make a change and click on the CommandButton2
it does nothing... Where am I going wrong?
Wow, that's... um... really something. You get an 'A' for for Determination, but a "C-" for Study Skills. (I mean that in the kindest way possible!) :)
There are a lot of ways to create a dynamic multicolored form like this (with no sensitive code available to the users) and you pretty much picked the hardest and most complicated way. Unfortunately, complicating simple tasks tends to make them more likely to break in the future for a small reason, and then it can take forever to figure out the problem, if you're baby doesn't crash altogether, losing all your data.
I don't think I've ever seen a Too Many Variables error before! (Even Excel wants you to simplify.) Sorry if this doesn't qualify as an answer, but I think you're best best it to start over with your formatting in a proper way.
omg, "5208 lines of code left") IF you know exactly how many lines of code you have left, you are being way too repetitive! The whole point of Excel, or VBA, or coding in general, is make the computer do the work!
If you're concerned about learning new Excel features, don't be. You obviously have some skill & organization to have made it as far as you did on that! There are some basic things you should teach yourself in Excel...
Some things to learn, ASAP (you will be glad you did!)
Select..Case statements (instead of ElseIf ElseIf ElseIf)
With..End With statements (instead of A1.BackColor A1.BackColor A1.BackColor)
VLookup (store reusable values in tables)
Match / Index
Protecting Worksheets in Excel
CONDITIONAL FORMATTING! (Automatically change a cell's color etc based on a value or a formula.)
Arrays! Both for storage (like color names and cell trigger values) and for control.
VBA Events! (Make stuff happen automatically when other stuff happens) --from the website of Chip Pearson (the king of Excel)
Making a static web page of an Excel Page
Some of Excel's amazing built-in features
Microsoft Excel formulas and features that you need to know
ExcelGuru Forums
and even: Rotating Shift Schedule Templates for Excel (that are ready to use, free, you can adapt as you need, built by professionals)
Good luck... Those are some nice color choices!
The best way to solve this issue is to start creating modules for each "action" that you want to do, for example to insure the colors in the textboxes make one Module and call it "Colour_Text" as an example is would look something like this
Public Sub Colour_Text1()
If PA1.Text = "S1" Then
PA1.BackColor = RGB(0, 32, 96)
PA1.ForeColor = RGB(255, 255, 255)
PA1.Font.Bold = True
ElseIf PA1.Text = "S2" Then
PA1.BackColor = RGB(0, 112, 192)
PA1.ForeColor = RGB(255, 255, 255)
PA1.Font.Bold = True
ElseIf PA1.Text = "S3" Then
PA1.BackColor = RGB(189, 215, 238)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "S4" Then
PA1.BackColor = RGB(0, 176, 240)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "W" Then
PA1.BackColor = RGB(60, 60, 60)
PA1.ForeColor = RGB(255, 255, 255)
PA1.Font.Bold = True
ElseIf PA1.Text = "P" Then
PA1.BackColor = RGB(166, 166, 166)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "A" Then
PA1.BackColor = RGB(255, 0, 0)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "S" Then
PA1.BackColor = RGB(169, 208, 142)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "L" Then
PA1.BackColor = RGB(0, 176, 80)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "F" Then
PA1.BackColor = RGB(112, 48, 160)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "N" Then
PA1.BackColor = RGB(255, 125, 125)
PA1.ForeColor = RGB(0, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "UL" Then
PA1.BackColor = RGB(0, 176, 80)
PA1.ForeColor = RGB(169, 208, 142)
PA1.Font.Bold = True
ElseIf PA1.Text = "US" Then
PA1.BackColor = RGB(169, 208, 142)
PA1.ForeColor = RGB(255, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "UN" Then
PA1.BackColor = RGB(255, 125, 125)
PA1.ForeColor = RGB(255, 0, 0)
PA1.Font.Bold = True
ElseIf PA1.Text = "H" Then
PA1.BackColor = RGB(255, 192, 0)
PA1.ForeColor = RGB(255, 0, 0)
PA1.Font.Bold = True
End If
End Sub
You then do the same for all the other text boxes, you can then call the module when you change the Text box like this:
Private Sub PA1_Change()
Call Module1.Colour_Text1
End Sub
This way you are only calling small changes thus freeing up your Memory :)

VBA USER FORM error 6 work around

I currently have a bunch of Combo boxes that has a option for Yes, No or N/A
Then I Have a Command button that that runs a calculation then moves to the next page
Private Sub CommandButton2_Click()
Dim a As Long, b As Long
a = IIf(Cbx1_1.Value = "Yes", 1, 0) + IIf(Cbx1_2.Value = "Yes", 1, 0) +_
IIf(Cbx1_3.Value = "Yes", 1, 0) + IIf(Cbx1_4.Value = "Yes", 1, 0)
b = 4 - IIf(Cbx1_1.Value = "N/A", 1, 0) - IIf(Cbx1_2.Value = "N/A", 1, 0)_
- IIf(Cbx1_3.Value = "N/A", 1, 0) - IIf(Cbx1_4.Value = "N/A", 1, 0)
OUTBX1.Text = Format(a / b, "00.00%")
MultiPage1.Value = 1
End Sub
Now the Only Problem that I am experiencing now is that if all the boxes are check as "N/A" then I get the 0/0 problem (Error 6 : Overflow)
I know that with Excel I would have used an ERRORIF formula to solve this. Is there a way that I can tell VBA that if:
=ERRORIF (b=0) then MultiPage1.Value = 1 else
OUTBX1.Text = Format(a / b, "00.00%")
Thank you to everyone for you help the final answer to this is coded as following:
Private Sub CommandButton2_Click()
Dim a As Long, b As Long
a = IIf(Cbx1_1.Value = "Yes", 1, 0) + IIf(Cbx1_2.Value = "Yes", 1, 0) + IIf(Cbx1_3.Value = "Yes", 1, 0) + IIf(Cbx1_4.Value = "Yes", 1, 0)
b = 4 - IIf(Cbx1_1.Value = "N/A", 1, 0) - IIf(Cbx1_2.Value = "N/A", 1, 0) - IIf(Cbx1_3.Value = "N/A", 1, 0) - IIf(Cbx1_4.Value = "N/A", 1, 0)
If b = 0 Then
MultiPage1.Value = 1
Else
OUTBX1.Text = Format(a / b, "00.00%")
MultiPage1.Value = 1
End If
End Sub

Visual Basic - System.IndexOutOfRangeException

So my part of the code that gives me problems is this one. It says:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in WindowsApplication1.exe
Additional information: Index was outside the bounds of the array
for Label1.Text = question(i - 1,0) and I really don't understand.
I am at the start and I am really trying to learn things for programming.
Public Class Test1
Dim question(2, 5) As String
Dim i As Integer = 2
Private Sub Test1_Load()
question(1, 0) = "2+2="
question(1, 1) = "1"
question(1, 2) = "2"
question(1, 3) = "3"
question(1, 4) = "4"
question(2, 0) = "How old are you?"
question(2, 1) = "12"
question(2, 2) = "13"
question(2, 3) = "17"
question(2, 4) = "18"
Label1.Text = question(i - 1, 0)
nr1.Text = question(i - 1, 1)
nr2.Text = question(i - 1, 2)
nr3.Text = question(i - 1, 3)
nr4.Text = question(i - 1, 4)
End Sub
Your code didn't give me any errors on dotnetfiddle.net. So "question" is a 2D array indexed from 0-2 and 0-5. Here's what it kinda looks like:
0 1 2 3 4 5
0 s s s s s s
1 s s s s s s
2 s s s s s s
Where each 's' represents a string. So if you're accessing question(0, 0), then it would be the 's' in the top left. If you're accessing question(0, 1), then it would be the 's' to the right of that one. If you try to access something outside of the bounds of your array, you will get an error, for example, if you try to access question(3, 0).
So to fix your error, you need to figure out what the value of i is. Try putting
MessageBox.Show(i)
right before the line that's giving you the error.

EDI file without any third party tool

i am getting EDI file as shown below,i need to process it ,and i need to maintain primary key ,foreign key also.
TH*4.2*857463*01**20091015*1045*P**~~IS*7564*ACME
PHARMACY~PHA*1234567890~PAT*MA*06*987544****SMITH*JOHN****1234 MAIN
ST**SOMEWHERE*MA*54356**19500101*M*01*01*INDIA**BURGER~
Here the column delimeter is * ,also if no value is provided they also put *.
i need to store fields from
TH*4.2*857463*01**20091015*1045*P**~~
into 1 table,by seperating fields.
So it would be
th01 th02 th03 th04 th05 th06 th07 th08 th09 th10
TH 4.2 857163 01 *(no value) 20091015 1045 p * (novalue) ~~
IS*7564*ACME PHARMACY into another table,and so on.
i cannot use third party tool as i cannot have xml files
Any help?
ok.
here is my vb.net code
Public Enum Segments
TH
PHA
PAT
IS1
End Enum
Dim arrLine As String()
Dim segmentcode As String
Dim counter As Integer
Dim linenumber As Integer = 1
Dim segmenetsequence As Hashtable = New Hashtable()
Dim setid As Guid = Guid.NewGuid()
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
arrLine = Row.LineText.Split("*"c)
segmentcode = SegmentValue(arrLine, 0)
Row.LineNumber = linenumber
Row.Setid = setid
counter = arrLine.Length
linenumber += 1
Select Case (segmentcode.ToUpper())
Case Segments.TH.ToString.ToUpper()
Row.TH01 = SegmentValue(arrLine, 1)
Row.TH02 = SegmentValue(arrLine, 2)
Row.TH03 = Convert.ToInt32(SegmentValue(arrLine, 3))
Row.TH04 = SegmentValue(arrLine, 4)
Row.TH05 = Convert.ToDateTime(SegmentValue(arrLine, 5))
Row.TH06 = SegmentValue(arrLine, 6)
Row.TH07 = SegmentValue(arrLine, 7)
Row.TH08 = Convert.ToInt32(SegmentValue(arrLine, 8))
Row.TH09 = SegmentValue(arrLine, 9)
Case Segments.IS1.ToString.ToUpper()
Row.IS01 = SegmentValue(arrLine, 1)
Row.IS02 = SegmentValue(arrLine, 2)
Row.IS03 = SegmentValue(arrLine, 3)
Case Segments.PHA.ToString.ToUpper()
Row.PHA01 = SegmentValue(arrLine, 1)
Row.PHA02 = SegmentValue(arrLine, 2)
Row.PHA03 = SegmentValue(arrLine, 3)
Row.PHA04 = SegmentValue(arrLine, 4)
Row.PHA05 = SegmentValue(arrLine, 5)
Row.PHA06 = SegmentValue(arrLine, 6)
Row.PHA07 = SegmentValue(arrLine, 7)
Row.PHA08 = SegmentValue(arrLine, 8)
Row.PHA09 = SegmentValue(arrLine, 9)
Row.PHA10 = SegmentValue(arrLine, 10)
Row.PHA11 = SegmentValue(arrLine, 11)
Row.PHA12 = SegmentValue(arrLine, 12)
Case Segments.PAT.ToString.ToUpper()
Row.PAT01 = SegmentValue(arrLine, 1)
Row.PAT02 = SegmentValue(arrLine, 2)
Row.PAT03 = SegmentValue(arrLine, 3)
Row.PAT04 = SegmentValue(arrLine, 4)
Row.PAT05 = Convert.ToInt32(SegmentValue(arrLine, 5))
Row.PAT06 = SegmentValue(arrLine, 6)
Row.PAT07 = SegmentValue(arrLine, 7)
Row.PAT08 = SegmentValue(arrLine, 8)
Row.PAT09 = SegmentValue(arrLine, 9)
Row.PAT10 = SegmentValue(arrLine, 10)
Row.PAT11 = SegmentValue(arrLine, 11)
Row.PAT12 = SegmentValue(arrLine, 12)
Row.PAT13 = SegmentValue(arrLine, 13)
Row.PAT14 = SegmentValue(arrLine, 14)
Row.PAT15 = SegmentValue(arrLine, 15)
Row.PAT16 = SegmentValue(arrLine, 16)
Row.PAT17 = SegmentValue(arrLine, 17)
Row.PAT18 = Convert.ToDateTime(SegmentValue(arrLine, 18))
Row.PAT19 = SegmentValue(arrLine, 19)
Row.PAT20 = Convert.ToInt32(SegmentValue(arrLine, 20))
Row.PAT21 = Convert.ToInt32(SegmentValue(arrLine, 21))
Row.PAT22 = SegmentValue(arrLine, 22)
Row.PAT23 = SegmentValue(arrLine, 23)
Row.PAT24 = SegmentValue(arrLine, 24)
End Select
End Sub
Public Function SegmentValue(ByRef LineArray As String(), ByVal Counter As Integer) As String
Throw New NotImplementedException
If LineArray.Length > Counter Then
Return LineArray(Counter).ToString().Trim()
End If
Return String.Empty
End Function
End Class
Speaking in broad terms, I would look at using a Script Component as a source. It would have an output collection per "thing" the file could contain. In your example, you'd have Output 0 with sufficient columns to describe the th rows above. You'd then have an Output 1 collection that describes the IS data set. You'll also need to factor in any keys, possibly surrogate keys generated within the source component to keep track of your data.
Once you've defined the all the columns in the collections, then it's a simple matter of writing the parsing logic in C#/VB.NET. Once parsed, you simply assign values into those collections.
Output0Buffer.AddRow();
// use this to assign a value
Output0Buffer.MyColumn = parsedValue;
// Use this for handling a null value
Output0Buffer.MyColumn_IsNull = true;
Now you can run the package and parsed data flows down the stream.
It sounds like you have foreign keys to be satisfied and surrogate values to be generated. If that is the case, I'd write most, if not all this data into a variety of staging tables and then proceed with validation and backfilling of data through repeated queries via Execute SQL Tasks chained to the Data Flow Task.
Need more detail? Edit your question and provide some yourself. We're all happy to give advice and direction but we are not in your cube and do not understand your needs.