Check the state of the OS and proceed accordingly.

Page 3 of 7 FirstFirst 12345 ... LastLast
  1. Kyhi's Avatar
    Posts : 3,539
    Windows 3.1 to Windows 10
       #21

    What would be real nice is if you merged your additional options into my existing Image Health options....
    As I provide an option to use Latest ADK Dism Files - which allows Image Health to also run on windows 7
      My Computer

  2. Matthew Wai's Avatar
    Posts : 4,998
    Windows 10 Home 20H2
       #22

    Paul Black said:
    @Matthew Wai, does your code do exactly the same as @Kyhi's code?
    I just found a subtle difference. See the test results below:

    Kyhi said:
    Code:
    set "params=%*"
    setlocal EnableDelayedExpansion
    cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
    %windir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || (
    echo.
    echo ============================================================
    echo ERROR: Run the script as administrator.
    echo ============================================================
    echo.
    echo Press any key to exit...
    pause >nul
    goto :eof
    )
    I put it in a .bat file "E:\$ Testing\Kyhi.bat" and ran it. The output was:
    Code:
    'E:\$' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Windows\system32>
    The code does not work because the file path contains a space.

    Matthew Wai said:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    Echo Hello & pause
    I put it in a .bat file "E:\$ Testing\Matthew.bat" and ran it. The output was:
    Code:
    Hello
    Press any key to continue . . .
    My code works even if the file path contains a space.
      My Computer

  3. Kyhi's Avatar
    Posts : 3,539
    Windows 3.1 to Windows 10
       #23

    our test results vary - as I just tested > "Test$ Admin.cmd" and > "Test Admin.cmd"
    ie with space and a special character - also tested as .bat
      My Computer

  4. Matthew Wai's Avatar
    Posts : 4,998
    Windows 10 Home 20H2
       #24

    The file name "$ Matthew.bat" works.
    The file name "$Matthew.bat" does not work.
    The file name "%Matthew.bat" works.
    The file name "@Matthew.bat" works.

    That is baffling.
      My Computer

  5. FreeBooter's Avatar
    Posts : 3,966
    Windows 10 Pro 64-bit
       #25

    Code:
    :: Clean Up the WinSxS Folder
    
    @Echo off
    
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    
    Cls & Mode CON  LINES=12 COLS=80 & Color 1E & Title Created by FREEBOOTER
    
    
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 8" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 8.1" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (
    Reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 10" >Nul
    If Not Errorlevel 1 (
    Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase
    ) Else (    
    Goto :EOF
    ) ) )  
    
    Ping -n 10 localhost >Nul
      My Computer

  6. Kyhi's Avatar
    Posts : 3,539
    Windows 3.1 to Windows 10
       #26

    seems like a lot of code written - just to run a DISM command
      My Computer

  7. Matthew Wai's Avatar
    Posts : 4,998
    Windows 10 Home 20H2
       #27

    I think FreeBooter's code can be simplified as below:
    Code:
    For /f "tokens=2 delims==" %%# in (
    'wmic path Win32_OperatingSystem get BuildNumber /value') do (set /a WinBuild=%%#)
    If %winbuild% LEQ 7601 (Goto :EOF) else (
    Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase)
    Dism.exe will be run as long as the OS is Windows 8 or above.
      My Computer

  8. Matthew Wai's Avatar
    Posts : 4,998
    Windows 10 Home 20H2
       #28

    Code:
    Set "SFC=%UserProfile%\Desktop\SFC_Errors.txt"
    %UserProfile%\Desktop\ does not work if the desktop has been relocated: Move Location of Desktop Folder in Windows 10

    The following works even if the desktop has been relocated:
    Code:
    For /F "usebackq tokens=3 " %%X in (
    `Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop`) Do (
    Set 👽=%%X)
    For /F "usebackq delims=" %%Y in (`Echo %👽%`) Do (Set ❤️=%%Y)
    Set "SFC=%❤️%\SFC_Errors.txt"
    Credit goes to Try3.
      My Computer

  9. Kyhi's Avatar
    Posts : 3,539
    Windows 3.1 to Windows 10
       #29

    Thank You Matt for sharing that code...
    @Try3 Several members have set me code to adjust "Image Health" to work with relocated Personal folders - Your code is the only one found to work...
    Thank You

    Paul I adjusted *.cmd - to allow "folder relocation" to work with prior PM attachment (new pm sent)
      My Computer

  10. Paul Black's Avatar
    Posts : 12,132
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #30

    Kyhi said:
    Paul I adjusted *.cmd - to allow "folder relocation" to work with prior PM attachment (new pm sent)
    Send me the new updated .cmd code via PM, I can then adjust the code etc accordingly!
      My Computer


 
Page 3 of 7 FirstFirst 12345 ... LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 18:20.
Find Us




Windows 10 Forums