Last active
December 20, 2018 13:46
-
-
Save espresso3389/e7f7fa26624b70152494151840254eee to your computer and use it in GitHub Desktop.
Get WSL's rootfs directory and home directory of the default user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem Get the default distribution | |
for /f "tokens=3" %%d in ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss /v DefaultDistribution') do set DIST=%%d | |
rem Get distribution name, rootfs directory, and uid | |
for /f "tokens=3" %%n in ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\%DIST% /v DistributionName') do set DIST_NAME=%%n | |
for /f "tokens=3" %%p in ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\%DIST% /v BasePath') do set ROOTFS=%%p\rootfs | |
for /f "tokens=3" %%u in ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\%DIST% /v DefaultUid') do set /a UID=%%u | |
rem username and home directory from /etc/passwd | |
for /f "tokens=1 delims=:" %%u in ('findstr /R ":x:%UID%:%UID%:,,," %ROOTFS%\etc\passwd') do set USERNAME=%%u | |
for /f "tokens=6 delims=:" %%u in ('findstr /R ":x:%UID%:%UID%:,,," %ROOTFS%\etc\passwd') do set HOMEUNIX=%%u | |
rem Convert Linux path to Windows path | |
set HOME=%ROOTFS%%HOMEUNIX:/=\% | |
echo Dist. : %DIST_NAME% | |
echo Def. User: %USERNAME% | |
echo Home(Lin): %HOMEUNIX% | |
echo Home(Win): %HOME% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment