DISM does not work properly when run with sudo
Stanzilla opened this issue · 16 comments
Sudo for Windows version
1.0.0
Windows build number
10.0.26100.0
Other Software
Note that it does work if you don't use sudo and just run DISM in an elevated shell.
Steps to reproduce
sudo dism /Online /Cleanup-Image /RestoreHealth
sudo is set to inline mode
Expected Behavior
DISM works
Actual Behavior
❯ sudo dism /Online /Cleanup-Image /RestoreHealth
Deployment Image Servicing and Management tool
Version: 10.0.26100.1
Error: 31
An error occurred while creating the log file.
Ensure that the path to the log file exists and that you have Read/Write permissions on the folder where the log files will be created.
Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?
Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?
Nope just as normal.
Disclaimer: I used a backported version from Canary on my beta branch OS before, then "updated" to 24H2 via downgrading my Insider membership to Release Preview.
Here is the properties of my sudo.exe
(no idea why the signature date is in German, just Windows things)
Well, it's real promising that there's literally no other documentation on why this might happen
🤷
Like, absolute dumb sanity check - does
dismwork from an elevated console window?did you drop that
sudo.exeinto system32? or into some other path/?
Yeah it works from an elevated console window just fine and I did the same google search before filing the issue haha
Here's what that sudo points to, is that the correct version? I'm pretty sure I just dropped it in there yeah.
Huh. I can't seem to repro this locally. That's weird. Were you using sudo to run the command as another user/?
Nope just as normal.
Disclaimer: I used a backported version from Canary on my beta branch OS before, then "updated" to 24H2 via downgrading my Insider membership to Release Preview.
Here is the properties of my sudo.exe
(no idea why the signature date is in German, just Windows things)
About the timestamp, in my case, it uses my local language. Which is English. Do you have other languages installed on your system?
But yeah, I also have one user on my computer, I received the same error code (31). I tested all configuration sudo offers.
Okay we may be onto a lead: on my dev box, sudo cmd, then dism /Online /Cleanup-Image /RestoreHealth from in the CMD that's now running elevated? That works.
as a workaround, running the command like this sudo pwsh {dism /Online /Cleanup-Image /RestoreHealth} works normally... Is this how sudo was designed to be with pwsh?
I'm not an expert at Windows programming, but from what I understand DISM calls CreateFileW to create dism.log. I can't reproduce this, though I have an unorthodox setup where I manually inserted the necessary registry keys to get sudo to work on a non-Insider build of Windows
I'm not sure why it would return error 31. I suspect that if the permissions of a directory are set to something like SYSTEM then sudo could be unable to perform actions inside of that directory, though I created a C file with CreateFileW and it worked fine inside of a directory owned by SYSTEM. could you provide the permissions on C:/Windows/Logs/DISM and anything that might be relevant in Event Viewer?
I was looking around the dism.log after i run sudo and i noticed there are a lot of providers don't support does not support CreateDismImage on C:\ - CGenericImagingManager::CreateDismImage. I'll share the log when I'm free.
Edit: I can finally share the logs from dism. Each logs have specific sudo configuration.
dismForceNewWindow.log
dismInline.log
dismDisableInput.log
Although they don't provide enough details on why dism failed
Okay this is MSFT:51791454 internally
I've also encountered this on 24H2 (release channel). Workaround for me right now is sudo cmd then run dism commands from the new shell











