パスワードのヒント、別アプローチを思いついた。
SIDに含まれるRID部分を16進数にして8桁ゼロパディングしているだけでは
ないかと。
VBScriptで対象ユーザのSIDを得て、その中からRIDを切り出してやればよい、と。
てことで、やっつけ仕事...。
==============================================================
バッチ部分
==============================================================
@echo off
pushd %~dp0
set USER="%1"
set HINT="%2"
if "%USER:"=%" == "" (
goto :usase
)
for /f "usebackq tokens=*" %%i in (`cscript //nologo get_RID.vbs "%USER:"=%"`) do @set RID=%%i
if "%RID%" == "" (
goto :error
) else (
echo HKEY_LOCAL_MACHINE\SAM\SAM [1 17] > SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\%RID% [1 17] >> SAM_REG.ini
regini.exe SAM_REG.ini
reg add HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\%RID% /v UserPasswordHint /t REG_SZ /d "%HINT:"=%" /f > nul
)
echo HKEY_LOCAL_MACHINE\SAM\SAM [17] > SAM_REG.ini
regini.exe SAM_REG.ini
goto :eos
:error
echo,
echo,
echo,
echo "%USER:"=%" ユーザがありません。
echo,
echo,
goto :eos
:usase
echo,
echo Usage : %~nx0 ローカルユーザ名 パスワードヒント
echo,
echo 使用例: %~nx0 PC-User 管理者に確認
echo,
echo,
echo,
:eos
popd
cd /d %HOMEPATH%
exit /b
==============================================================
VBScript部分
ファイル名:get_RID.vbs
==============================================================
'http://www.wmifun.net/sample/win32_useraccount.html
Option Explicit
Dim oClassSet
Dim oClass
Dim oLocator
Dim oService
Dim sMesStr
Dim array
Set oLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocator.ConnectServer
Set oClassSet = oService.ExecQuery("Select * From Win32_UserAccount")
For Each oClass In oClassSet
if oClass.Name = WScript.Arguments(0) then
array = split(oClass.SID, "-")
wscript.echo right("00000000" & hex(array(ubound(array))), 8)
end if
Next
Set oClassSet = Nothing
Set oClass = Nothing
Set oService = Nothing
Set oLocator = Nothing
Set array = Nothing
SIDに含まれるRID部分を16進数にして8桁ゼロパディングしているだけでは
ないかと。
VBScriptで対象ユーザのSIDを得て、その中からRIDを切り出してやればよい、と。
てことで、やっつけ仕事...。
==============================================================
バッチ部分
==============================================================
@echo off
pushd %~dp0
set USER="%1"
set HINT="%2"
if "%USER:"=%" == "" (
goto :usase
)
for /f "usebackq tokens=*" %%i in (`cscript //nologo get_RID.vbs "%USER:"=%"`) do @set RID=%%i
if "%RID%" == "" (
goto :error
) else (
echo HKEY_LOCAL_MACHINE\SAM\SAM [1 17] > SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users [1 17] >> SAM_REG.ini
echo HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\%RID% [1 17] >> SAM_REG.ini
regini.exe SAM_REG.ini
reg add HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\%RID% /v UserPasswordHint /t REG_SZ /d "%HINT:"=%" /f > nul
)
echo HKEY_LOCAL_MACHINE\SAM\SAM [17] > SAM_REG.ini
regini.exe SAM_REG.ini
goto :eos
:error
echo,
echo,
echo,
echo "%USER:"=%" ユーザがありません。
echo,
echo,
goto :eos
:usase
echo,
echo Usage : %~nx0 ローカルユーザ名 パスワードヒント
echo,
echo 使用例: %~nx0 PC-User 管理者に確認
echo,
echo,
echo,
:eos
popd
cd /d %HOMEPATH%
exit /b
==============================================================
VBScript部分
ファイル名:get_RID.vbs
==============================================================
'http://www.wmifun.net/sample/win32_useraccount.html
Option Explicit
Dim oClassSet
Dim oClass
Dim oLocator
Dim oService
Dim sMesStr
Dim array
Set oLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocator.ConnectServer
Set oClassSet = oService.ExecQuery("Select * From Win32_UserAccount")
For Each oClass In oClassSet
if oClass.Name = WScript.Arguments(0) then
array = split(oClass.SID, "-")
wscript.echo right("00000000" & hex(array(ubound(array))), 8)
end if
Next
Set oClassSet = Nothing
Set oClass = Nothing
Set oService = Nothing
Set oLocator = Nothing
Set array = Nothing
コメント
コメントを投稿