¡ Por favor active Javascript! / Please turn on Javascript!

Incidencias y resolución de problemas en las diferentes versiones de Windows 7: SP1, Home, Professional, Enterprise...
Avatar de Usuario
Cazador
Colaborador
Mensajes: 1954
Registrado: 16 Abril 2015, 19:16
C. Prof.: Analista de Sistemas
Contactar:

Problema con el servicio Firewall de Windows ID 7024

Mensajepor Cazador » 13 Marzo 2019, 13:54

El siguiente código de Powershell de Microsoft solventa el problema de inicio del Servicio Firewall de Windows:

Crearemos un fichero con el contenido inferior y lo llamaremos Fix_FirewallNotStarted.ps1

Código: Seleccionar todo

#################################################################################
# Fix_FirewallNotStarted.ps1
# Copyright (c) 2010, Microsoft Corporation. All rights reserved.
#
# You may use this code and information and create derivative works of it,
# provided that the following conditions are met:
# 1. This code and information and any derivative works may only be used for
# troubleshooting a) Windows and b) products for Windows, in either case using
# the Windows Troubleshooting Platform
# 2. Any copies of this code and information
# and any derivative works must retain the above copyright notice, this list of
# conditions and the following disclaimer.
# 3. THIS CODE AND INFORMATION IS PROVIDED `AS IS'' WITHOUT WARRANTY OF ANY
# KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. IF THIS
# CODE AND INFORMATION IS USED OR MODIFIED, THE ENTIRE RISK OF USE OR RESULTS IN
# CONNECTION WITH THE USE OF THIS CODE AND INFORMATION REMAINS WITH THE USER.
#################################################################################

trap [exception] {
    Write-Error $_
    continue
}

# Load Utilities
#. .\utils_SetupEnv.ps1
#*=================================================================================
#Function:   find-typeassembly
#Purpose:   Search all loaded assemblies for the named type
#Return:   assembly
#*=================================================================================
function find-typeassembly($typename) # return assembly
{
   foreach ($assembly in [appdomain]::currentdomain.getassemblies())
   {
      foreach ($type in $assembly.gettypes())
      {
         if ($type.fullname -eq $typename)
         {
            return $assembly
         }
      } # $type
   } # $assembly
   return $null
} # find-classassembly

#*=================================================================================
#Function:   cwos-stack
#Purpose:   Wrap current stack trace as a multi line string.
#Param:      optional $format -- default $null is 'long'
#Param:      optional $maxparamlength -- -1 is full, default 0 is interpreted as 50
#Return:   [string]
#*=================================================================================
function cwos-stack([string] $stackformat, [int] $maxparamlength)
{
   if ([string]::isnullorempty($stackformat))
   { $stackformat = 'long' }
   if ($maxparamlength -eq 0)
   { $maxparamlength = 50 }
   if (@(get-command *get-pscallstack).length -eq 0)
   { return '(Stack trace is unavailable)' }   
   $callstack = @( &{
      get-pscallstack
      trap [management.automation.commandnotfoundexception]
      { throw 'Failed obtain call stack' }
   } )
   $trimargs = {
      # debug: [console]::error.writeline("trimargs $($_.command) $($_.arguments)")
      $args = $_.arguments
      if ($maxparamlength -gt 1 -and $_.arguments.length -gt $maxparamlength)
      {
         $x = $_ | select *
         $x.arguments = '[' + $_.arguments.substring(1, $maxparamlength - 2) + '...]'
         return $x
      }
      else
      {
         return $_
      }
   } # $trimargs
   switch ($stackformat)
   {
      'long' {
         $f = { "$($_.location): $($_.command)$($_.arguments)" }
      } # long
   } # switch
   $l = @( $callstack |% $trimargs |% $f )
   return [string]::join("`n", $l)
} # cwos-stack

#*=================================================================================
#Function:   Import-CS
#Purpose:   Encapsulate loading of C# code.
#         The sourcefiles are ignored when the sourcetext is specified.
#         The classname should be declared by the c# source to indicate that the source was successfully loaded.
#Throw:      If $sourcefile is missing and $sourcetext is blank.
#Throw:      If $classname is not declared by the c# source.
#Throw:      If the class already exists, and -force is requested.  Re-loading a class is not supported.
#Return:   type
#Notice:   The source may declare many types, and NOT necessary to use the returned type reference.
#Notice:   The source files should have any import statements INSIDE the namespace.
#         At runtime, the c# code will fail to compile if import statements are outside
#         namespace in the second and following files.
#*=================================================================================
function import-cs([string] $classname, [string[]] $sourcefile, [string] $sourcetext, [switch] $force, [string[]] $referencedassemblies,[string]$Language = "CSharp",[string]$CodeDomProvider)
{
   $type = $classname -as [type]
   if ($type -ne $null)
   {
      if ($force)
      {
         # Remove the old instance of this class
         throw "Unloading assemblies is not supported in this version"
      }
      else
      {
         # The class has already been loaded
         return $type
      }
   }
   if ($sourcetext -lt ' ')
   {
      foreach ($file in $sourcefile)
      {
         if (test-path $file)
         {
            $sourcetext += "`n" + [string]::join("`n", (get-content $file))
         }
         else
         {
            $title = "Missing c# source $file"
            [string] $message = $myinvocation.positionmessage
            $xml = $myinvocation | convertto-xml
            update-diagreport `
               -xml $xml `
               -id 'embeddedcodemissing' `
               -name $title `
               -description $message `
               -verbosity 'error'
            throw "Source file $file does not exist"
         }
      } # for $file
   }
   &{
      $compilefile = 'compilefile.txt'
      $count = $error.count
      if(![string]::IsNullOrEmpty($CodeDomProvider))
      {
            $out = add-type `
         -typedefinition $sourcetext `
         -referencedassemblies $referencedassemblies -CodeDomProvider $CodeDomProvider `
         -ignorewarnings 2> $compilefile
      }
      else
      {      
            $out = add-type `
         -typedefinition $sourcetext `
         -referencedassemblies $referencedassemblies -Language $language `
         -ignorewarnings  2> $compilefile
      }

      $compileresult = cat $compilefile
      if ($error.count -ne $count)
      {
         $e = $error[0]
         $title = "Error " + $e.FullyQualifiedErrorId
         [string] $position = $e.invocationinfo.positionmessage
         [string] $message = $e.exception
         $message += $position
         $xml = @(cwos-stack) + $e + $sourcefile + $stdout + $stderr + $out | convertto-xml
         update-diagreport `
            -xml $xml `
            -id 'embeddedcodeerror' `
            -name 'Embedded Code Error' `
            -description $position `
            -verbosity 'error'
         throw "Error compiling $sourcefile"
      }
      trap
      {
         #$stdout = cat $outfile
         #$stderr = cat $errfile
         $e = $error[0]
         $title = "Error " + $e.FullyQualifiedErrorId
         [string] $position = $e.invocationinfo.positionmessage
         [string] $message = $e.exception
         $message += $position
         $xml = @(cwos-stack) + $sourcefile + $compileresult + $out + $e | convertto-xml
         update-diagreport `
            -xml $xml `
            -id 'embeddedcodeerror' `
            -name 'Embedded Code Error' `
            -description $position `
            -verbosity 'error'
         throw "Error compiling $sourcefile"
      }
   } # compile
   $type = $classname -as [type]
   if ($type -eq $null)
   {
      $xml = @(cwos-stack) + $sourcefile + $compileresult + $out + $e | convertto-xml
      update-diagreport `
         -xml $xml `
         -id 'embeddedcodeerror' `
         -name 'Embedded Code Error' `
         -description $position `
         -verbosity 'error'
      throw "The type [$classname] was not defined after compiling files [$sourcefile]"
   }
   return $type
} # Import-CS

#*=================================================================================
#Function : log-cwosscriptexception
#Purpose :  Writes the latest script exception to the diagnostic report
#Return  : [bool] $continue -- the script should terminate if $continue is false.
#*=================================================================================
function log-cwosscriptexception()
{
   $e = $error[0]
   $title = "Error " + $e.FullyQualifiedErrorId
   [string] $position = $e.invocationinfo.positionmessage
   [string] $message = $e.exception
   $message += $position
   [bool] $continue = $false
##line 219
   $xml = $e | convertto-xml
   update-diagreport `
      -xml $xml `
      -id 'scripterror' `
      -name 'Script Error' `
      -description $position `
      -verbosity 'error'
   return $continue
   
   trap
   {
      $null = [reflection.assembly]::loadwithpartialname("system.windows.forms")
      $message = "Error while writing error report"
      $message += $error[0].invocationinfo.positionmessage
      $message += $error[0].exception
      [windows.forms.messagebox]::show($message)
   }
} # log-cwosscriptexception

#*=================================================================================
#Function : Set-PSVersionTable
#Purpose :  Check system for current PowerShell Version
#Return  : void
#*=================================================================================
function Set-PSVersionTable

{
     if (!(test-path variable:PSVersionTable))
    {
       $myPSVersionTable = @{}      
      [Version]$CLRVersion = $([System.Reflection.Assembly]::GetExecutingAssembly().ImageRuntimeVersion).TrimStart("v")
      [Version]$BuildVersion = $(Get-WmiObject Win32_OperatingSystem).Version
      [Version]$PSVersion = "1.0"
      [Version]$WSManStackVersion = "0.0"
      [Array]$PSCompatibleVersions = @($PSVersion)
      [Version]$SerializationVersion = "0.0.0.0"
      [Version]$PSRemotingProtocolVersion = "0.0.0.0"

      $myPSVersionTable.Add('CLRVersion', $CLRVersion)      
      $myPSVersionTable.Add('BuildVers$PSion', $BuildVersion)
      $myPSVersionTable.Add('PSVersion', $PSVersion)
      $myPSVersionTable.Add('WSManStackVersion', $WSManStackVersion)
      $myPSVersionTable.Add('PSCompatibleVersions', $PSCompatibleVersions)
      $myPSVersionTable.Add('SerializationVersion', $SerializationVersion)
      $myPSVersionTable.Add('PSRemotingProtocolVersion', $PSRemotingProtocolVersion)
      
      Set-Variable -Name PSVersionTable -Scope Global -Value $myPSVersionTable -Option Constant
    }
}
Set-PSVersionTable

# If Powershell Version is less than 2.0 load compatibility scripts
#if ($PSVersionTable.PSVersion -lt '2.0')
#{
#   . .\utils_PowerShell_1_0.ps1
#}

#*=================================================================================
#Function : Save
#Purpose :  will check the version and accordingly save input xml to a file
#Return  :
#*=================================================================================
function Save()
{
    param($xmldoc,$path)
    trap [Exception] {continue;}
    if($PSVersionTable.PSVersion -lt '2.0')
    {
        if($xmldoc -ne $null)
        {
            $xmldoc | out-file $path -Force
        }
    }
    else
    {
        if($xmldoc -ne $null)
        {
            $xmldoc.save($path)
        }
    }
}
# Place ProductID in Debug Report
function Set-DiagPID([string]$ProductName, [string]$ProductID)
{
   $PIDObject = "" | Select-Object ProductName                  # Return object
   $PIDObject.ProductName = $ProductName
   
   add-member -inputobject $PIDObject -membertype noteproperty -name ProductID -value $ProductID
   
   (convertto-xml -InputObject $PIDObject) | update-diagreport -id OAS_DATAPOINT_ID -name "OAS_DATAPOINT" -description "OAS Data Point for OAS submission" -verbosity debug
}
#*=================================================================================
#End
#*=================================================================================
# ///////////////////////////////////////////////////////////////////
# adding pop messagebox for compatibility with ps1 and ps2
###########
# Pop up window
############
function Pop-Msg {
    param([string]$msg ="message",
    [string]$ttl = "Title",
    [int]$type = 64)
    $popwin = new-object -comobject wscript.shell
    $null = $popwin.popup($msg,0,$ttl,$type)
    remove-variable popwin
}

#. .\utils_SdpExtension.ps1
function Set-RootCauseResolvedMark(
    [string] $RootCauseID
)
{
    if(!$RootCauseID)
    {
        throw "No root cause ID is specified"
    }
    get-date | Out-File ".\$RootCauseID.Resolved"
}

function Test-RootCauseResolvedMark(
    [string] $RootCauseID
)
{
    if(!$RootCauseID)
    {
        throw "No root cause ID is specified"
    }
    return Test-Path ".\$RootCauseID.Resolved" -PathType Leaf
}

function CreateRestorePoint($RestorePointName)
{

    if(!(Test-RootCauseResolvedMark($RestorePointName)))
    {
        $RestoreSetting_Modify = 12;
        $RestoreSetting_Begin  = 103;
        $Restore = [WMIClass]"ROOT\DEFAULT:SystemRestore"
        $Restore.CreateRestorePoint("$RestorePointName", $RestoreSetting_Modify, $RestoreSetting_Begin)
        Set-RootCauseResolvedMark($RestorePointName)
    }

}

#End  Load Utilities

Import-LocalizedData -BindingVariable Strings_RS_FirewallNotStarted -FileName strings
Write-DiagProgress -activity $Strings_RS_FirewallNotStarted.WINDOWSFIREWALL_RC_FirewallNotStarted_RS_PROG


switch([System.Environment]::OSVersion.Version.Major)
{
    5 # Pre-Vista
    {
        $fwServiceName = 'SharedAccess'
    }
    {$_ -gt 5} # Vista+
    {
        $fwServiceName = 'MpsSvc'
    }
}

if(Get-Service $fwServiceName)
{
    Set-Service $fwServiceName -StartupType Automatic
    Start-Service $fwServiceName
}
Redactor de ELSATE.com. Aficionado de la Tecnología, los Videojuegos, la Música Electrónica y el Deporte.





Volver a “Windows 7”

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados