Sledgehammer - Windows 10 Update Control

Discussion in 'MDL Projects and Applications' started by pf100, Nov 28, 2016.

  1. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    Change the last line of LockFiles.cmd from this:
    Code:
    exit
    to this:
    Code:
    exit /b %errorlevel%
    and run the LockFiles task again to see if that fixes it.
     
  2. BraneStawm

    BraneStawm MDL Novice

    Apr 14, 2020
    23
    5
    0
  3. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    Try
    Code:
    exit /b 0
     
  4. BraneStawm

    BraneStawm MDL Novice

    Apr 14, 2020
    23
    5
    0
    Bingo!!!

    I take it that forces a successful exit?
     
  5. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    It should have been there all along. It would be difficult to check for any error in any operation of any command in LockFiles.cmd, only that LockFiles.cmd ran to the end and finished. Exit /b 0 forces an exit code of 0 (success) after the file runs all the way to the end, so really all that matters is that the file runs all commands to the end and then reports that it finished since it has to work if it runs, which is what this command does. I have no idea why this was an issue for you (it's not for me), but if it's happening with you it's probably an issue for many others too. So I'll make this correction in the next version of Sledgehammer which I'm trying really hard to get out within the next 7 days. I'll update the script with it. Thanks for the report and the help.
     
  6. Carlos Detweiller

    Carlos Detweiller MDL Spinning Tortoise

    Dec 21, 2012
    4,932
    5,110
    150
    @pf100 If you take the WMIC-less script from my post, use the Powershell variant. The other one, strangely, fails for me although it should work as well.
     
  7. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    That's basically how this whole script has been over the years. I thought a particular bit of code would work but it didn't and the thing that did work wasn't what I expected and half of it turned out to be trial and error. :) I was planning to DM you tomorrow to see where you are on this, so thanks for the work you've done.
     
  8. BraneStawm

    BraneStawm MDL Novice

    Apr 14, 2020
    23
    5
    0
    Thanks for looking at it so fast, it's good to have things 'in order'
     
  9. Carlos Detweiller

    Carlos Detweiller MDL Spinning Tortoise

    Dec 21, 2012
    4,932
    5,110
    150
    I have only replaced and tested the code snippets a few others provided. As said, the Powershell one (edited 2.7.3-rc1) works fine in the dev builds. It should work for Windows 10 and the Servers, as well. Older OS are not applicable.

    - It's an unconditional, hard edit. WMIC won't be used even if available.
    - Powershell is a little bit slower, but the script doesn't depend on it too much.
    - Only the main script has been patched.
    - @rpo has still posted a few possible improvements.
     
  10. thiih_

    thiih_ MDL Novice

    Mar 22, 2008
    27
    19
    0
    I converted this script (sledgehammer) into a fully Powershell script for my own use and works flawlessly, I just updated using PS1 + Update Manager.

    #-------------------------------------------------------#
    # Starts Windows Update Service and Open Updater App #
    #-------------------------------------------------------#
    Start-Process -FilePath $wub -ArgumentList "/e"
    while ((Get-Service wuauserv).status -eq 'STOPPED')
    {
    [System.Windows.Forms.Application]::DoEvents()
    Sleep -m 1
    }
    Add-Content -Path "$CurrentDir\usingupdatescript.control" -Value "Just a Control"

    # Use WUMGR
    Start-Process -FilePath $wumgr -ArgumentList "-update -online 7971f918-a847-4430-9279-4a52d1efe18d -provisioned"
    while ((Get-Process | Where-Object {$_.MainWindowTitle -like "*Update Manager*Xanatos*"}) -eq $null)
    {
    [System.Windows.Forms.Application]::DoEvents()
    Sleep -m 1
    }

    #---------------------------------#
    # Closes Load Screen after load #
    #---------------------------------#
    $LoadScreen.Close();

    #-----------------------------------------------------------#
    # Waits Updates and Keep Windows Update Service Running #
    #-----------------------------------------------------------#
    while ((Get-Process -Name *wumgr*) -or (Get-Process -Name *wumt*))
    {
    if ((Get-Service -Name wuauserv).Status -ne 'Running')
    {
    Start-Process -FilePath $wub -ArgumentList "/e"
    }
    Sleep 5
    }
     
  11. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,258
    1,168
    60
    This is the way to go.
     
  12. zylor

    zylor MDL Junior Member

    Feb 25, 2012
    91
    43
    0
    Awesome job dude! amazing
     
  13. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    Put that in code tags. The board has converted some of the code to smiley faces.
     
  14. (\_/)^(\_/)

    (\_/)^(\_/) MDL Member

    May 31, 2020
    1,587
    1,333
    60
    Thank you i also thought to write the same but is waiting for you to write this on your MDL thread. Very Nice objective Thread to control WU.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,258
    1,168
    60
    Three years ago i converted the script into PowerShell. The structure was changed and i used a extensive number of functions. One problem with PowerShell is that it offers no goto statement, you have to deal wirh embedded if blocks and while blocks. But this makes the script cleaner.
     
  16. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,059
    3,346
    90
    And I had to not use the entire script being powershell because I wouldn't be able to maintain it, and I'm sure my powershell illiteracy has caused you and others frustration at times. What I wish I had known from the beginning is that I don't have to be a great coder, I just have to have an idea that works and create a working sample and somebody else will help. Ideally the script would be beautifully written by a professional coder. But I have to be able to fully test it and if it's all powershell I can't fully tweak and test it in case of issues such as the task completion error code issue I fixed the other day with "exit /b 0". Not to downplay any of your other contributions, but when you fixed the failed tasks caused by foreign language characters in the path with vbscript that was really a thing of beauty and I would probably have never figured that out in a million years, and I tried really hard to figure it out, so I have to go outside of my comfort zone sometimes. I consulted renowned Batch Script God Rob van der Woude and got nowhere because I don't think what you did with vbscript is actually possible with batch script and would have required ugly hacky workarounds otherwise. The code I've used of yours in the script that is not batch script probably will never have to be maintained or altered but I understand it well enough to be able to work with it. Also, some info not specific to you while I'm typing, but I promised I'd try to get an update out within 7 days about 10 days ago but since then I sprained my shoulder really bad and then had to build my daughter a pc and all of that set me back about 2 weeks. In the next day or two I will threaten everyone I know with death if they don't leave me the hell alone so I can get this update out the door.
     
  17. thiih_

    thiih_ MDL Novice

    Mar 22, 2008
    27
    19
    0
    #1940 thiih_, Dec 1, 2021
    Last edited: Dec 1, 2021