Skip to content
Snippets Groups Projects
Select Git revision
  • 0e357b5715516b2e4388984773af068778c77ee6
  • main default protected
2 results

Fix prompt for password change.cmd

Blame
  • user avatar
    JG authored
    The reasons I've read up on and even though they are so minor in 2022 that I really shouldn't care, I am very obedient to conventions and rules - and I wanna be a cool kid, too.
    0e357b57
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Fix prompt for password change.cmd 1.11 KiB
    @echo off
    REM Ensure Admin rights
    setlocal DisableDelayedExpansion
    set "batchPath=%~0"
    for %%k in (%0) do set batchName=%%~nk
    set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
    setlocal EnableDelayedExpansion
    net file 1>nul 2>nul
    if '%errorlevel%' == '0' (goto gotPrivileges) else (goto getPrivileges)
    
    :getPrivileges
    if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
    REM If you have non-ASCII chars in your path you'll need to set the codepage appropriate to your locale:
    REM chcp 1252
    REM (ANSI-Latin1 - Western European, e.g. German)
    cls
    echo Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
    echo args = "ELEV " >> "%vbsGetPrivileges%"
    echo For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
    echo args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
    echo Next >> "%vbsGetPrivileges%"
    echo UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
    "%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
    exit
    
    :gotPrivileges
    if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
    
    
    REM Functional part
    wmic UserAccount set PasswordExpires=False
    pause
    exit