:: Batch pour activer/désactiver le partage protégé par mot de passe sous Windows (7, 8, 8.1, 10). :: Créer par Tlem le 27/12/2017 :: @Echo Off CLS :: Relance le batch pour obtenir les droits admin (copie le batch dans Temp). Net.exe session 1>NUL 2>NUL || ( Copy "%~dpnx0" "%temp%">Nul Powershell start-process """%temp%\%~nx0""" -verb RunAs & Exit /b 1 ) Set UserAccount=Invit‚ Echo R‚cup‚ration du SID du compte Invit‚ ... Echo. FOR /F "tokens=1,2 delims==" %%s IN ('wmic path win32_useraccount where name^='%UserAccount%' get sid /value ^| find /i "SID"') DO SET SID=%%t If "%SID%"=="" ( Color 0C Echo Impossible de r‚cup‚rer le SID du compte %UserAccount% Echo Ce batch ne peux pas continuer. Echo. Echo Appuyez sur une touche pour quitter Pause>Nul Goto :Exit ) :Selection Cls Echo Quelle op‚ration d‚sirez vous effectuer ? Echo. Echo 1 : D‚sactiver le partage prot‚g‚ par mot de passe Echo. Echo 2 : Activer le partage prot‚g‚ par mot de passe Echo. Echo 3 : Quitter Echo. Echo. Set /p Choix="Veuillez taper 1, 2 ou 3 (Choix 1 par d‚faut) : Cls IF '%Choix%' == '' GOTO :Off IF '%Choix%' == '1' GOTO :Off IF '%Choix%' == '2' GOTO :On IF '%Choix%' == '3' GOTO :Exit Goto :Selection :Off Echo. Echo Activation du compte "Invit‚" net user %UserAccount% /active:yes If Errorlevel 1 Goto :Error Color 0A net user %UserAccount% "">Nul If Errorlevel 1 Goto :Error Echo. Echo Ajout de la cl‚ de registre pour d‚sactiver le partage prot‚g‚ par mot de passe Call :AdminWriteKey 0x00000041 Goto :Reboot :On Echo. Echo D‚sactivation du compte "Invit‚" net user %UserAccount% /active:no If Errorlevel 1 Goto :Error Color 0A Echo. Echo Ajout de la cl‚ de registre pour activer le partage prot‚g‚ par mot de passe Call :AdminWriteKey 0x000000C1 Goto :Reboot :Reboot Echo. Echo. Echo. Echo ***************************** Echo ***** ATTENTION ***** Echo ***************************** Echo. Echo Votre ordinateur doit red‚marrer pour prendre en compte les modifications. Echo Appuyez sur une touche pour valider le red‚marrage ou fermez cette Echo fenetre pour red‚marrer votre ordinateur plus tard. Pause>Nul Shutdown -r -t 0 Goto :Exit :AdminWriteKey Echo HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\%SID%\ActSysAc [1 17]>"%temp%\GetRightOnRegKey.txt" Echo HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\%SID%\ActSysAc>>"%temp%\GetRightOnRegKey.txt" Echo @ = DELETE>>"%temp%\GetRightOnRegKey.txt" Echo @ = REG_NONE 0x04 %1>>"%temp%\GetRightOnRegKey.txt" "%Windir%\System32\Regini.exe" "%temp%\GetRightOnRegKey.txt" If %Errorlevel% == 1 Goto :Error Goto :EOF :Error Color 0C Echo La commande ne s'est pas deroul‚e correctement. Echo Merci de lire le message d'erreur et de corriger. Echo. Echo Fin du script !!! Echo. Echo. Echo Appuyez sur une touche pour quitter Pause>NUL Goto :Exit :Exit Del /F /Q "%temp%\GetRightOnRegKey.txt" Del /F /Q "%temp%\%~nx0" If Exist "%temp%\%~nx0" Goto :Exit Exit :EOF