New
#41
The "getadmin.vbs" created by your CMD code is:
The above does not work at my end, while the following does:Code:Set UAC = CreateObject("Shell.Application") : UAC.ShellExecute "cmd.exe", "/k cd ""E:\A folder\"" && E:\A folder\ImageHealth.cmd ", "", "runas", 1
Code:Set UAC = CreateObject("Shell.Application") : UAC.ShellExecute "E:\A folder\Get admin.cmd",cmd,"","runas",1
@Kyhi,
In your ImageHealth.cmd, option 3 cannot proceed if no ISO has been mounted beforehand. I just found that ISO can be mounted via a CMD command: Mount or Unmount ISO and IMG file in Windows 10
Would you consider adding it into your script?
Before running Disk Cleanup, my WinSxS was 5.26 GB.
After running Disk Cleanup, it remains 5.26 GB.
I'm trying to use the code Matthew posted earlier but having now success. The batch file is fairly simple.
When I run it from a standard Command Prompt I get this:Code:@Echo on Rem Tuneup.bat Rem Written by Ztruker @ tenforums.com based on a post by Zbook at tenforums.com. Rem Must be run from a Elevated Command Prompt or Powershell Rem The first 4 commands will take quite a while to run. Rem If not admin NET SESSION wil fail and call Powershell to run batch as Admin (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B) echo. >&2 echo The following commands will be run in sequence. echo The first 4 will take quite awhile to run, be patient. echo. >&2 echo sfc /scannow echo dism /online /cleanup-image /scanhealth echo dism /online /cleanup-image /restorehealth echo sfc /scannow echo chkdsk /scan echo wmic recoveros get autoreboot echo wmic recoveros set autoreboot = false echo wmic recoveros get autoreboot echo wmic recoveros get DebugInfoType echo wmic recoveros set DebugInfoType = 7 echo wmic recoveros get DebugInfoType echo bcdedit --% /enum {badmemory} @echo on rem sfc /scannow rem dism /online /cleanup-image /scanhealth rem dism /online /cleanup-image /restorehealth rem sfc /scannow rem chkdsk /scan wmic recoveros get autoreboot wmic recoveros set autoreboot = false wmic recoveros get autoreboot wmic recoveros get DebugInfoType wmic recoveros set DebugInfoType = 7 wmic recoveros get DebugInfoType Rem for Powershell bcdedit --% /enum {badmemory} Rem for Command Prompt bcdedit /enum {badmemory}
D:\Batch Files>Tuneup-mod.bat
D:\Batch Files>Rem Tuneup.bat
D:\Batch Files>Rem Written by Ztruker @ tenforums.com based on a post by Zbook at tenforums.com.
D:\Batch Files>Rem Must be run from a Elevated Command Prompt or Powershell
D:\Batch Files>Rem The first 4 commands will take quite a while to run.
D:\Batch Files>Rem If not admin NET SESSION wil fail and call Powershell to run batch as Admin
D:\Batch Files>(Net session 1>nul 2>&1 ) || (PowerShell start """Tuneup-mod.bat""" -verb RunAs & Exit /B )
start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ start "Tuneup-mod.bat" -verb RunAs
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
How could it not exist, it's currently running?
I've also tried invoking it using the full path like so:
from C:\Users\ztruk> I ran d:\batchfiles\tuneup-mod.bat
It's a moot point now as I have a useable solution but I really would like to understand why it doesn't work.
I really appreciate your help Matthew.
I'll try what you've suggested above just to see what it shows.
Rich,
If you open an admin prompt and change to the d:\batchfiles folder, does your [elevated] admin account have permission to list the folder contents and to run the d:\batchfiles\tuneup-mod.bat file?
I cannot say that permissions are affecting this problem but it seems worth checking.
Denis
Also try the following on standard Command Prompt:
(Powershell "Start-Process ""d:\batchfiles\tuneup-mod.bat""")