[vbs] Hide updates script and help

Discussion in 'Scripting' started by HALIKUS, Jun 13, 2012.

  1. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    526
    371
    30
    #1 HALIKUS, Jun 13, 2012
    Last edited by a moderator: Apr 20, 2017
    I have a vbs script to hide unwanted M$ updates in my firstlogon.cmd. It works as advertised with one caveat, you must have net access. If you have wired LAN, it usually finds the drivers and the net works, but on some older \ newer hardware M$ updates isn't enough to install the driver. Also, if in my autounattended i skip setting the wireless LAN you have no net access on first logon.

    So, as it stands, if you have net access, this script works great for its purposes.
    But, if no net, it complains and gives an error message, thus ruining my silent firstlogon.cmd routine.

    I was wondering if a vb guru could help me with the script as i know next to nothing about vb, and help me add a net access portion at the beginning where the script will exit silently if there is no net access.

    If its easy enough to do, i could also use an OS detection portion so i can use it for both Win7 and Win8 for full control in a multi OS $oem$ folder setup.

    I have it setup to hide the annoying KB971033 WAT update, hide the un-dism-able KB2533552 that i run in a silent autoit exe, and to hide foreign language updates. Its petty, but saves a few clicks.


    Code:
    Function WuaVersion 'get current WUA version
      Dim oAgentInfo, ProductVersion
      On Error Resume Next 
      Err.Clear
      Set oAgentInfo = CreateObject("Microsoft.Update.AgentInfo")
      If ErrNum = 0 Then 
        WuaVersion = oAgentInfo.GetInfo("ProductVersionString") 
      Else 
        Wscript.Echo "Error getting WUA version."
        WuaVersion = 0 'calling code can interpret 0 as an error.
      End If 
      On Error Goto 0
    End Function 
    
    
    if WuaVersion <> "0" then
        Set ServiceManager = CreateObject("Microsoft.Update.ServiceManager")
        ServiceManager.ClientApplicationID = "My App"
    
        'add the Microsoft Update Service, GUID
        Set NewUpdateService = ServiceManager.AddService2("7971f918-a847-4430-9279-4a52d1efe18d",7,"")
    end if
    
    
    'ServerSelection values
    ssDefault = 0
    ssManagedServer   = 1
    ssWindowsUpdate   = 2
    ssOthers          = 3
    
    'InStr values
    intSearchStartChar = 1
    
    
    dim strTitle
    
    
    Set updateSession = CreateObject("Microsoft.Update.Session")
    Set updateSearcher = updateSession.CreateupdateSearcher()
    
    updateSearcher.ServerSelection = ssWindowsUpdate
    Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
    
    
    For I = 0 To searchResult.Updates.Count-1
        Set update = searchResult.Updates.Item(I)
        strTitle = update.Title
        if InStr(intSearchStartChar, strTitle, "KB971033", vbTextCompare) <> "0" then
        update.IsHidden = True
        end if
    Next
    
    For I = 0 To searchResult.Updates.Count-1
        Set update = searchResult.Updates.Item(I)
        strTitle = update.Title
        if InStr(intSearchStartChar, strTitle, "KB2533552", vbTextCompare) <> "0" then
        update.IsHidden = True
        end if
    Next
    
    For I = 0 To searchResult.Updates.Count-1
        Set update = searchResult.Updates.Item(I)
        strTitle = update.Title
        if InStr(intSearchStartChar, strTitle, "KB2483139", vbTextCompare) <> "0" then
        update.IsHidden = True
        end if
    Next
    
    WScript.Quit
    Please and thankyou.
     
  2. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    526
    371
    30
    #2 HALIKUS, Jun 15, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Its not the most elegant solution, but i found if i run the vbs from an autoit script (i have a firstlogon.cmd that also runs a firstlogon.exe) then i can "test the waters" for a net connection.

    Code:
    $connect = _GetNetworkConnect()
    
    If $connect Then
        MsgBox(64, "Connections", $connect, 2)
    
    
    MsgBox(4096, "MSU", "Hide MS updates that are Irritating", 1)
    If FileExists(@WindowsDir & "\Setup\FirstLogon\hideKB.vbs") Then
    ShellExecuteWait(@WindowsDir & "\Setup\FirstLogon\hideKB.vbs")
    MsgBox(4096, "Success", "Hide MS updates complete", 1)
    EndIf
    
    
    
    Else
        MsgBox(48, "Warning", "There is no connection", 2)
    EndIf
    
    Func _GetNetworkConnect()
        Local Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
        Local Const $NETWORK_ALIVE_WAN = 0x2  ;RAS (internet) connection
        Local Const $NETWORK_ALIVE_AOL = 0x4  ;AOL
    
        Local $aRet, $iResult
    
        $aRet = DllCall("sensapi.dll", "int", "IsNetworkAlive", "int*", 0)
    
        If BitAND($aRet[1], $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
        If BitAND($aRet[1], $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
        If BitAND($aRet[1], $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF
    
        Return $iResult
    EndFunc

    You can also add

    Code:
    If @OSVersion <> "WIN_7" Then
    Exit
    EndIf
    after the first msgbox so that it only runs on Win7. Change WIN_7 to WIN_8 if you want it to only run on win8, or duplicate the script with both OS and 2 vbs scripts per OS (if, like me, you use a universal $OEM$ folder for both OS types).