I'm trying to search for the latest .msi
file, and install it in the background.
I have tried following the help from this link but it did not help.
This is what I currently have:
@echo off
setlocal
if _%1_==_payload_ goto :payload
:getadmin
echo %~nx0: elevating self
set vbs=%temp%\getadmin.vbs
echo Set UAC = CreateObject^("Shell.Application"^) >> "%vbs%"
echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
:payload
::ENTER YOUR CODE BELOW::
FOR /F "eol=| delims=" %%I IN ('DIR "directory" /A-D /B /S /O-D /TW 2^>nul')
DO (
ECHO %%~I
SET "NewestFile=%%~I"
GOTO FoundFile
)
ECHO No *.msi file found!
GOTO :EOF
:FoundFile
msiexec.exe /I "%NewestFile%" /Q
::END OF YOUR CODE::
echo.
echo...Script Complete....
echo.
I'm guessing the problem is with the :FoundFile
and the execution part or finding the correct file based off of time.
I was thinking maybe I have to use:
forfiles /p "dir" /m *.msi /S /D +%Date%
but I'm not entirely sure.