[VB.NET] WindowsSecurityCenter by fudmario

Iniciado por fudmario, Diciembre 22, 2016, 02:19:20 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.




Implementacion de Windows Security Center (WSC) en No tienes permitido ver los links. Registrarse o Entrar a mi cuenta, cualquier error o sugerencia enviarlo por MP o Skype...



Ejemplo de Uso:
Código: vbnet

        Dim avsStatus As WindowsSecurityCenter.WscSecurityProviderHealth = WindowsSecurityCenter.GetStatusOfSecurityProvider(WindowsSecurityCenter.WscSecurityProvider.WscSecurityProviderAntivirus)
        Select Case avsStatus
            Case WindowsSecurityCenter.WscSecurityProviderHealth.WscSecurityProviderHealthGood
                MessageBox.Show("El estado del proveedor de seguridad es bueno y no necesita atención del usuario.")
            Case WindowsSecurityCenter.WscSecurityProviderHealth.WscSecurityProviderHealthPoor
                MessageBox.Show("El estado del proveedor de seguridad es deficiente y el equipo puede estar en riesgo.")
            Case WindowsSecurityCenter.WscSecurityProviderHealth.WscSecurityProviderHealthSnooze
                MessageBox.Show("El proveedor de seguridad está en estado suspendido. Snooze indica que WSC no está protegiendo activamente la computadora.")
        End Select
        Dim uacStatus As WindowsSecurityCenter.WscSecurityProviderHealth = WindowsSecurityCenter.GetStatusOfSecurityProvider(WindowsSecurityCenter.WscSecurityProvider.WscSecurityProviderUserAccountControl)
        If uacStatus = WindowsSecurityCenter.WscSecurityProviderHealth.WscSecurityProviderHealthPoor Then
            MessageBox.Show("El UAC se encuentra desactivado....")
        End If




Código: vbnet

' ***********************************************************************
' Assembly         : WinControl
' Author           : fudmario
' Created          : 12-21-2016
'
' Last Modified By : fudmario
' Last Modified On : 12-21-2016
' ***********************************************************************
' <copyright file="WindowsSecurityCenter.vb" company="DeveloperTeam">
'     Copyright ©  2016
' </copyright>
' <summary></summary>
' ***********************************************************************
Imports System.Runtime.InteropServices
Public NotInheritable Class WindowsSecurityCenter
    <DebuggerNonUserCode>
    Private Sub New()
    End Sub
    ''' <summary>
    ''' Defines all the services that are monitored by Windows Security Center (WSC).
    ''' </summary>
    ''' <remarks>
    ''' <see href="https://msdn.microsoft.com/en-us/library/bb432509(v=vs.85).aspx"/>
    ''' </remarks>
    <Flags>
    Public Enum WscSecurityProvider As Integer
        ''' <summary>
        ''' The aggregation of all firewalls for this computer.
        ''' </summary>
        WscSecurityProviderFirewall = 1
        ''' <summary>
        ''' The automatic update settings for this computer.
        ''' </summary>
        WscSecurityProviderAutoupdateSettings = 2
        ''' <summary>
        ''' The aggregation of all antivirus products for this computer.
        ''' </summary>
        WscSecurityProviderAntivirus = 4
        ''' <summary>
        ''' The aggregation of all anti-spyware products for this computer.
        ''' </summary>
        WscSecurityProviderAntispyware = 8
        ''' <summary>
        ''' The settings that restrict the access of web sites in each of the Internet zones for this computer.
        ''' </summary>
        WscSecurityProviderInternetSettings = 16
        ''' <summary>
        ''' The User Account Control (UAC) settings for this computer.
        ''' </summary>
        WscSecurityProviderUserAccountControl = 32
        ''' <summary>
        ''' The running state of the WSC service on this computer.
        ''' </summary>
        WscSecurityProviderService = 64
        ''' <summary>
        ''' None of the items that WSC monitors.
        ''' </summary>
        WscSecurityProviderNone = 0
        ''' <summary>
        ''' All of the items that the WSC monitors.
        ''' </summary>
        WscSecurityProviderAll =
            WscSecurityProviderFirewall Or WscSecurityProviderAutoupdateSettings Or WscSecurityProviderAntivirus Or
            WscSecurityProviderAntispyware Or WscSecurityProviderInternetSettings Or
            WscSecurityProviderUserAccountControl Or
            WscSecurityProviderService Or WscSecurityProviderNone
    End Enum

    ''' <summary>
    ''' Defines the possible states for any service monitored by Windows Security Center (WSC).
    ''' </summary>
    ''' <remarks>
    ''' <see href="https://msdn.microsoft.com/en-us/library/bb432510(v=vs.85).aspx"/>
    ''' </remarks>
    <Flags>
    Public Enum WscSecurityProviderHealth As Integer
        ''' <summary>
        ''' The status of the security provider category is good and does not need user attention.
        ''' </summary>
        WscSecurityProviderHealthGood
        ''' <summary>
        ''' The status of the security provider category is not monitored by WSC.
        ''' </summary>
        WscSecurityProviderHealthNotmonitored
        ''' <summary>
        ''' The status of the security provider category is poor and the computer may be at risk.
        ''' </summary>
        WscSecurityProviderHealthPoor
        ''' <summary>
        ''' The security provider category is in snooze state. Snooze indicates that WSC is not actively protecting the computer.
        ''' </summary>
        WscSecurityProviderHealthSnooze
        ''' <summary>
        ''' The status of the security provider category is unknown
        ''' </summary>
        WscSecurityProviderHealthUnknown
    End Enum

    ''' <summary>
    ''' Gets the aggregate health state of the security provider categories represented by the specified <see cref="WscSecurityProvider"/> enumeration values.
    ''' </summary>
    ''' <param name="providers ">One or more of the values in the <see cref="WscSecurityProvider"/> enumeration. To specify more than one value, combine the individual values by performing a bitwise OR operation.</param>
    ''' <param name="pHealth ">A pointer to a variable that takes the value of one of the members of the <see cref="WscSecurityProviderHealth"/> enumeration. If more than one provider is specified in the Providers parameter, the value of this parameter is the health of the least healthy of the specified provider categories.</param>
    ''' <returns>Returns S_OK if the function succeeds, otherwise returns an error code. If the WSC service is not running, the return value is always S_FALSE and the pHealth out parameter is always set to WSC_SECURITY_PROVIDER_HEALTH_POOR.</returns>
    ''' <remarks>
    ''' <see href="https://msdn.microsoft.com/en-us/library/bb432506(v=vs.85).aspx"/>
    ''' </remarks>
    <DllImport("wscapi.dll")>
    Private Shared Function WscGetSecurityProviderHealth(<[In]> providers As WscSecurityProvider,
                                                         <Out> ByRef pHealth As WscSecurityProviderHealth) _
        As Integer
    End Function

    ''' <summary>
    ''' Gets the status of security provider.
    ''' </summary>
    ''' <param name="provider">provider.</param>
    ''' <returns>The possible states for service monitored by Windows Security Center (WSC).</returns>
    Public Shared Function GetStatusOfSecurityProvider(provider As WscSecurityProvider) As WscSecurityProviderHealth
        Dim outValue As WscSecurityProviderHealth = WscSecurityProviderHealth.WscSecurityProviderHealthUnknown
        Dim ret As Integer = WscGetSecurityProviderHealth(provider, outValue)
        Return If(ret <> &H0, WscSecurityProviderHealth.WscSecurityProviderHealthUnknown, outValue)
    End Function
End Class