Sledgehammer - Windows 10 Update Control

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

  1. BraneStawm

    BraneStawm MDL Novice

    Apr 14, 2020
    37
    13
    0
    Bingo!!!

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

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,069
    3,449
    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.
     
  3. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,341
    7,060
    210
    @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.
     
  4. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,069
    3,449
    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.
     
  5. BraneStawm

    BraneStawm MDL Novice

    Apr 14, 2020
    37
    13
    0
    Thanks for looking at it so fast, it's good to have things 'in order'
     
  6. Carlos Detweiller

    Carlos Detweiller Emperor of Ice-Cream

    Dec 21, 2012
    6,341
    7,060
    210
    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.
     
  7. thiih_

    thiih_ MDL Novice

    Mar 22, 2008
    27
    20
    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
    }
     
  8. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,447
    1,423
    60
    This is the way to go.
     
  9. zylor

    zylor MDL Junior Member

    Feb 25, 2012
    92
    49
    0
    Awesome job dude! amazing
     
  10. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,069
    3,449
    90
    Put that in code tags. The board has converted some of the code to smiley faces.
     
  11. 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.
     
  12. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,447
    1,423
    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.
     
  13. pf100

    pf100 Duct Tape Coder

    Oct 22, 2010
    2,069
    3,449
    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.
     
  14. thiih_

    thiih_ MDL Novice

    Mar 22, 2008
    27
    20
    0
  15. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,447
    1,423
    60
    @pf100
    Possibly, this is currently the best solution because the script uses nsudo which has different files for amd64 and arm64.
     
  16. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    16,209
    84,855
    340
    Windows 11 arm64 needs one more check just in case (because it support both x64/arm64 interchangeably)
    Code:
    if /i "%PROCESSOR_ARCHITECTURE%"=="amd64" if exist "%SystemRoot%\SysArm32\cmd.exe" set "xBit=arm64"