Sledgehammer - Windows 10 Update Control

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

  1. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    Could use a bit of help here. At first this might not sound like it's related to my use of Sledgehammer, but it is.

    1. I have been tinkering around with the power settings on my laptop. Specifically those that determine what happens when you close the lid, push the power and/or sleep buttons, etc. Decided to have my laptop hibernate when I close the lid (in the past I would just power off).
    2. Using a tutorial on TenForums I am able to create desktop shortcuts to tasks I created in Task Scheduler/Task Scheduler Library. Those shortcuts work perfectly.
    3. Seeing how I am now using hibernate on my laptop, it may be in that hibernate state during one of the scheduled WDU run times. Coming out of the hibernate state, the task time has passed and WDU will not run again for another six hours or so, at which time the laptop may very well be in hibernate once again.

    So, my idea was to create a desktop shortcut to the WDU task so I could run it manually without having to open up Task Scheduler. But, I can not for the life of me figure out how to create that shortcut that runs a task which is located at Task Scheduler Library/Microsoft/Sledgehammer.

    It's either that or ask pf100 to change the tasks so they run if a scheduled run time is missed :)
     
  2. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    To change the WDU task so it runs if a scheduled run time is missed just replace line 65 of vdu.vbs in the bin subfolder by :
    Code:
    "    <StartWhenAvailable>true</StartWhenAvailable>" &_
    If you want to run the wdu task manually without having to open up Task Scheduler, execute a copy of wdu.cmd where you comment the second line.
     
  3. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    Copied the wdu.cmd to the desktop and changed as per above and double clicked to execute:

    ::Allow only WDU task to run this file::
    rem whoami /user /nh | find /i "S-1-5-18" || exit
    cd /d "%~dp0"
    ::Wait 5 minutes to prevent resource hogging after reboot with missed update::
    rem timeout /t 300>nul
    ::If WUMT or WuMgr are running, cancel Defender update and exit. If not, continue::
    tasklist | findstr /i "wumt_x86.exe wumt_x64.exe wumgr.exe" && exit 1
    ::If Windows Defender is running, update it. If not, cancel Defender update and exit::
    sc query | find /i "windefend" || exit 1
    ::Enable Windows Update service and update Defender, then disable Update Service::
    wub.exe /e
    timeout /t 10
    "%ProgramFiles%\Windows Defender\MpCmdRun.exe" -SignatureUpdate
    wub.exe /d /p
    exit /b %errorlevel%

    WDU did not run and this was the Task Scheduler error:
     

    Attached Files:

  4. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    @Homer712 If you want to execute Wdu.cmd from the desktop, you have to change the third line of the script to :
    cd /d "pass to your sledgemammer folder\bin (for example cd /d c:\sledgehammer\bin)
    because wub.exe is located in the bin subfolder.
    This will run a cmd script and not a task scheduler task.
     
  5. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    @rpo Initially opted to go the .cmd route as I didn't know that you could edit a .vbs file in Notepad (I use Notepad++). Just did that now and I'm sure it will be the better solution as well. Thanks for the assist!
     
  6. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    @Homer712 : don't forget to run the script again to recreate the tasks (modifying only the .vbs files is not enough).
     
  7. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    @rpo Ran the script right after modifying the vbs file and checked the (re)created WDU task to ensure that the settings had in fact changed to run if missed, and they were. This completely addresses concerns over missed definition updates. Thanks!
     
  8. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    You'r welcome.
     
  9. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    @rpo I'm sure you knew it would work, but I'm a "Trust but Verify" type of guy. Let the laptop hibernate until 6:10 PM (just past the task time) and woke it up. Let it run for a couple of minutes to settle everything back down, then took a look at the Task Scheduler and the WDU task did in fact run successfully past it task time. Thanks again!
     

    Attached Files:

  10. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    If you want to start the scheduled task WDU without opening the task scheduler menu :
    1. Create a shortcut and enter schtasks.exe /run /tn Microsoft\Sledgehammer\wdu for the target
    2. Set WDU as the name for the shortcut and terminate
    3. Right click on the created shortcut and select Properties
    4. On the shortcut tab hit Advanced
    5. Check the Run As Administrator box and hit OK
    6. Hit OK once more to close the Properties window
    You can now start the WDU task by clicking on the shortcut
     
  11. Homer712

    Homer712 MDL Junior Member

    Oct 22, 2018
    82
    19
    0
    @rpo Perfect solution, thank you! The only other thing I did was set the shortcut to run minimized.
     
  12. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    Created a VBS script to generate a shortcut to execute the WDU task. The shortcut is copyied to the desktop. Paste the script, copy it in your favorite text editor, save it as a ANSI file with the vbs extension in a write enabled folder and double click on the saved file.
    Code:
    Option Explicit ' Force explicit variable declaration.
    Dim oShell         : Set oShell = CreateObject("WScript.Shell")
    Dim oFS         : Set oFS = CreateObject("Scripting.FileSystemObject")
    Dim oShortcut    : Set oShortcut = oShell.CreateShortcut(lnk_Path)
    Const lnk_Path = "WDU.lnk" ' shortcut name and path (script directory)   
    oShortcut.TargetPath = "schtasks.exe"
    oShortcut.Arguments = "/run /tn Microsoft\Sledgehammer\WDU" ' schtasks parameters
    oShortcut.WindowStyle = 7 ' minimized window
    oShortcut.Description = "Shortcut for WDU task"
    oShortcut.IconLocation =  "%SystemRoot%\System32\SHELL32.dll,46"
    oShortcut.Save
    Dim oF, oTs, s   
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Set oF=oFS.GetFile(lnk_Path) ' get a File object corresponding to the shortcut
    Set oTs=oF.OpenAsTextStream(ForReading, TristateUseDefault)
    s=oTs.Read(oF.Size) : oTs.Close ' get content of WDU.lnk as a string
    Set oTs=oF.OpenAsTextStream(ForWriting, TristateUseDefault)
    oTs.Write Mid(s,1,21) & Chr(Int(Asc(Mid(s,22,1))) Or &H20) & Mid(s,23) : oTs.Close ' rewrite with admin flag set
    oFS.CopyFile lnk_Path, oShell.SpecialFolders("Desktop") & "\", True ' copy shortcut to desktop
     
  13. Whistler4

    Whistler4 MDL Member

    Jul 30, 2015
    147
    116
    10
    Another reason the Sledgehammer folder exists between uninstall and install is because other files have been added to the folder or its subfolders. For example, if you have selected offline update and downloaded wsusscn2.cab, that file will not be deleted by the uninstall process. (Most Windows uninstall processes will not completely delete the application program folders if they contain modified or additional files alien to the program.) Once you realize this behavior, you can just accept installing into the existing folder without the need to delete it first.
     
  14. Whistler4

    Whistler4 MDL Member

    Jul 30, 2015
    147
    116
    10
    @pf100, I've got a question about the second screen warning (third bullet), "If WuMgr or WUMT is offering updates, you need to hide or install them before closing WuMgr or WUMT."

    Is this an abundance of caution or have there been cases when unselected updates have actually launched after closing WuMgr or WUMT?

    The reason I ask is that, numerous times, I have gotten to the stage of viewing what updates are available to decide whether or not to install them, then closed the update tool without checking/selecting any updates, but I haven't had them be installed unintentionally. What would trigger an unintentional update if the Windows Update Service is disabled right after WUMT or WuMgr is closed?
     
  15. pf100

    pf100 MDL Expert

    Oct 22, 2010
    1,832
    2,757
    60
    @Whistler4 It's just to cover my a** if by some chance an update somehow made it through by cancelling the script. Nobody can say I didn't say to hide or update, even if it may be useless. I like to be overly cautious.
     
  16. Whistler4

    Whistler4 MDL Member

    Jul 30, 2015
    147
    116
    10
    Got it, and I agree. Things happen.
     
  17. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,112
    911
    60
    @pf100
    At line 398 of sledgehammer.cmd 2.7.2 there is an extraenous reference to %3. Create_tasks is called with 2 parameters (but there is no incidence on the processing).
     
  18. Carlos Detweiller

    Carlos Detweiller MDL Spinning Tortoise

    Dec 21, 2012
    3,744
    3,496
    120
    #1579 Carlos Detweiller, Jun 27, 2020
    Last edited: Jun 27, 2020
    Sledgehammer includes WuMgr 1.1 and uses only that included version. And, as Sledgehammer disabled Windows Update Service, the standalone version is of very limited use.
     
  19. pf100

    pf100 MDL Expert

    Oct 22, 2010
    1,832
    2,757
    60
    No. If Wumgr is updated I'll make a new release of the script that includes it.
    If you mean can the latest version of the script block the 2004 update, then yes.
    There has only been two versions of WuMgr that were considered "finished" and ready for prime time use, 0.9 and 1.1, so it doesn't need to be updated very often.

    When this script started taking off I asked a couple of people who make projects if I should make it check for updates of itself, and the answer I got was "no".