2017-11-16 32 views
0

Windowsのローカルセキュリティポリシーには複雑さの要件があります。私は上記のパスワードの複雑さをバッチで有効にする方法

::this will change the minimum length of the password 
net accounts /minpwlen:8 
::this will change the maximum age of the password 
net accounts /maxpwage:30 
::this will change the minimum age of the password 
net accounts /minpwage:5 
::this will change the number of passwords stored 
net accounts /uniquepw:5 

は私が何をしたいのほとんどであるが、私は、私は有効方法を見つけ出すことができないなど、長さ、年齢などの他のパスワードのものを可能にバッチファイルで有効にできるようにしたいと思いますバッチの複雑さ。前もって感謝します。あなたがこれを行う方法について他のアイデアがあるならば、私は開いています。

答えて

0

私はかつて同じような状況があったし、私がやったことだった。

setlocal EnableDelayedExpansion 

SecEdit.exe /export /cfg "%temp%\sec-template.cfg" >nul 2>&1 

set names=MaximumPasswordAge MinimumPasswordLength PasswordComplexity PasswordHistorySize 
set values[MaximumPasswordAge]=90 
set values[MinimumPasswordLength]=6 
set values[PasswordComplexity]=1 
set values[PasswordHistorySize]=10 

for /F "delims== tokens=1,*" %%X in ('type "%temp%\sec-template.cfg"') do (
    call :trim "%%X" 
    set cur_name=!result! 
    for %%I in (%names%) do (
     if "!cur_name!" equ "%%I" (
      set value== !values[%%I]!  
     ) 
    ) 

    if not defined value if "%%Y" neq "" (
     call :trim "%%Y" 
     set value== !result!   
    ) 

    echo !cur_name! !value! >> "%temp%\sec-template2.cfg" 
    set value= 
) 

SecEdit.exe /configure /db secedit.sdb /cfg "%temp%\sec-template2.cfg" >nul 2>&1 

del /q "%temp%\sec-template2*.cfg" >nul 2>&1 

if exist "%~dp0secedit.sdb" del "%~dp0secedit.sdb" >nul 2>&1 

goto :eof 

:trim 
set result=%~1 

set "f=!result:~0,1!" & set "l=!result:~-1!" 

if "!f!" neq " " if "!l!" neq " " goto :eof 
if "!f!" equ " " set result=!result:~1! 
if "!l!" equ " " set result=!result:~0,-1! 

call :trim "!result!" 
goto :eof 

はそれがお役に立てば幸いです。

関連する問題