Admin check

Pour vérifier rapidement si le compte à les droit d'administrateur.

@echo on & @echo off
cls

REM
REM Script d'installation silencieuse
REM
REM O.Brizard @2021
REM

REM Parametre d'installation silencieuse
set silentParams=/silent /loadinf="foxitSilent.inf"
set uninstallCmd=

REM compte de montage
set login=monLogin
set pwd=monPwd

REM R‚pertoire source du logiciel
set fullPath="%~dp0"
set fullPath=%fullPath:~-0,-2%"

if NOT %1=="" set fullPath=%1
if NOT %1=="" set fullPath=%fullPath:~-0,-1%"

set srcFolder=%fullPath%

REM Source local
if NOT "%srcFolder:~1,2%"=="\\" goto next

REM On monte le serveur
if exist g:\ net use /delete g: /y>nul 2>&1
echo | set /p =Montage du partage r‚seau:
net use g: %srcFolder% /persistent:no
if errorlevel 2 (
    net use g: %srcFolder% /user:%login% %pwd% /persistent:no
)
if not exist g: exit 1

:next
REM Recupere le nom du repertoire source du logiciel
set fullPathTmp=%fullPath:&=^&%
set fullPathTmp=%fullPathTmp:\=,%
for %%a in (%fullPathTmp:"=%) do set pFolder=%%a
set nomRepertoireLogiciel=%pFolder%

REM SI BESOIN D'ETRE SUPER Administrateur
REM *************************************
    :init
    setlocal DisableDelayedExpansion
    set "batchPath=%~nx0"
    for %%k in (%0) do set batchName=%%~nk
    set "vbsGetPrivileges=%TMP%\OEgetPriv_%batchName%.vbs"
    setlocal EnableDelayedExpansion

    :checkPrivileges
    net session 1>NUL 2>NUL
    if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

    :getPrivileges
    if '%1'=='ELEV' (shift /1 & goto gotPrivileges)

    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 /B

    :gotPrivileges
    if exist "%vbsGetPrivileges%" del /Q "%vbsGetPrivileges%"
    setlocal
    if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

REM *********** Fin admin **************************

::::::::::::::::::::::::::::
:: START
::::::::::::::::::::::::::::
TITLE Installation de %nomRepertoireLogiciel%
echo Installation de %nomRepertoireLogiciel% patientez...
echo.

pushd G:\

REM On determine le nom du setup
set _setup=
for /F "tokens=*" %%A in ('dir /b *^| findstr /i /r "\.msi$ \.exe$"') DO set _setup=%%A && set ext=%%~xA
if "%_setup%"=="" goto end

REM Si besoin d'ajout de certificat
REM certutil.exe -addstore TrustedPublisher monCertificat.cer

REM Désintallation avant si besoin
if NOT "%uninstallCmd%"=="" cmd.exe /c %uninstallCmd%
timeout /T 3> nul

REM Execution de l'installation
echo D‚but de l'installation.
if "%_setup:~-1%"==" " set _setup=%_setup:~-0,-1%
if "%ext%"==".msi" msiexec.exe /i "%_setup%" %silentParams% && set exitCode=%errorlevel%
if "%ext%"==".exe" "%_setup%" %silentParams% && set exitCode=%errorlevel%

REM ::::: Post installation :::::
REM :::::::::::::::::::::::::::::
::regedit.exe /s titi.reg
::reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v ADS_LICENSE_FILE /t REG_SZ /d 32000@mon-srv.toto.fr /f>nul 2>&1

:end
popd
echo | set /p=Fin d'installation:
net use /delete g: /Y
echo.
if "%_setup%"=="" exit 1

REM Controle du succes d'installation si besoin
::if not exist "C:\Program Files (x86)\Microchip\MPLABX\v5.40\mplab_platform\bin\mplab_ide64.exe" set exitCode=1

exit %exitCode%
Dernière modification : le 2022/01/25