/build/static/layout/Breadcrumb_cap_w.png

Advice on script I created to download post-install tasks based on computer model

I have post-install tasks specific to computer models. Each one has a script that determines model name and runs only if the system matches the model specified in the script, otherwise the task passes through without doing anything. These have been working great for over a year and continue to have no problems. 

Most of these post-install tasks are hundreds of MB and there are almost 10 of them, amounting to about 5GB of files. I have one master scripted image that uses a core WIM image and then I have all my major post-install tasks set. I don't want a scripted install for every model individually, that would be a pain in the ass. So right now I have the K2000 pulling in all these post-install tasks which takes some time during the "Copy post-install files" task after applying the WIM. As I said, all of this is working fine.

What I want is:
  1. to upload install packages to the K2000 as post-install tasks mostly as a remote server location I can access (central security won't give me a network share, they're cheap jerks), of course residing on the server at "\\K2000ipaddress\peinst\applications". 
  2. Then I have created a single post-install task that is nothing more than a batch script run as a post-install task that finds the model name and then mounts a drive letter to "\\K2000ipaddress\peinst\applications" and searches through all the tasks there and only pulls files in from the "k2000\peinst\applications\*" directory with the install batch file matching the name of the model.
So far, most of the script works.
  • It finds the model name just fine.
  • It mounts the drive letter Z:\ to "\\K2000ipaddress\peinst\applications" just fine
  • It finds the install batch file matching the name of the computer model just fine
The problem is that this post-install download batch script is not setting a variable for the directory of the model specific package that I have stored on the K2000. I've watched the script as it moves line-by-line and it finds the directory without trouble, but I can't get the variable to be set so that I can move on to the actual copying of the files I need and subsequent running of the install batch file (those parts work if I hard code the path of the post-install task directory matching the model name).

*I'm really trying to present this in a way that makes sense, so please feel free to ask questions if it isn't

Any advice would be appreciated. Here is the batch script in it's current state:
::--------------------------------------------------------------------------------------------------------------------
:: ELEVATE TO MAKE THINGS EASIER
::--------------------------------------------------------------------------------------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    cscript "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
::--------------------------------------------------------------------------------------------------------------------
cls

SETLOCAL ENABLEDELAYEDEXPANSION


:: GET COMPUTER MODEL AND ASSIGN AS VARIABLE "Model"
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SET "machine=%%A"

:: CORRECT FOR LATITUDE E7240 AND LATITUDE E7440, WHICH USE ALL THE SAME DRIVERS AND THEREFORE THE SAME PACKAGE/SCRIPT
IF "%machine%"=="Latitude E7270" SET "machine=Latitude E7270-7470"
IF "%machine%"=="Latitude E7470" SET "machine=Latitude E7270-7470"


:: MAP TO K2000
start /wait net use Z: \\K2000-IP-address-here\peinst\Applications /user:K2000-account-inserted-here "password-inserted-here" /PERSISTENT:No

TIMEOUT 5

IF NOT EXIST "Z:\1" ( GOTO FAILURE )

:: SET CURRENT DIRECTORY AS KACE APPLICATIONS DIRECTORY
PUSHD "Z:\"
TIMEOUT 5

:: SEARCH THROUGH K2000 PATH "\\K2000IPaddress\peinst\applications\*" TO FIND APPROPRIATE DRIVER FILES
:: %%~nxa is for name and extension only
:: %%~dpnxA is for folder\file path
for /r "Z:\" %%g in (*.bat) do if "%%~nxa"=="%machine%-Silent-PostInstall.bat" set "p=%%~dpnxA"


:: TAKE FOLDER PATH FOUND FROM SEARCH AND EXTRACT THE FOLDER PATH (WHICH CONTAINS A "\")
FOR %%i IN ("%p%") DO (
SET "filepath=%%~pi"
)

:: REMOVE THE "\" FROM THE FOLDER PATH BECAUSE IT SCREWS UP THE XCOPY COMMAND TO PULL THE FILES IN
IF "%filepath:~-1%"=="\" SET "filepath=%filepath:~0,-1%"

:: ONLY PROCEED TO COPYING DRIVER FILES TO COMPUTER IF PATH VARIABLE HAS SOME VALUE, NOT BLANK RESULT
if defined p (
echo "%filepath%"&& goto COPYDrivers
) else (
GOTO FAILURE
)

:: BEGIN COPYING NEEDED DRIVER FILES FROM THE "K2000\peinst\applications\*" LOCATION TO THE LOCAL COMPUTER AT "C:\HARDWAREDrivers"
:COPYDrivers
TIMEOUT 3
xcopy "%filepath%" "C:\HARDWAREDrivers" /c /e /s /i /h /k /y
TIMEOUT 5

:: RELEASE CURRENT DIRECTORY OF "\\10.20.50.19\PEINST\APPLICATIONS"
popd
timeout 5
:: ONE MORE TIME TO MAKE SURE CURRENT DIRECTORY IS BACK TO ORIGINATING DIRECTORY OF SCRIPT
popd
TIMEOUT 5

cd /D "C:\HARDWAREDrivers"
TIMEOUT 3


:: CALL LOCAL DRIVER INSTALL SCRIPT FOR THE DRIVER IN "C:\HARDWAREDrivers"
if exist "C:\HARDWAREDrivers\%machine%-Silent-PostInstall.bat" (
CALL "C:\HARDWAREDrivers\%machine%-Silent-PostInstall.bat"
)

TIMEOUT 5

GOTO FINISH


:: IF FILEPATH OF DRIVERS CAN'T BE FOUND, HOLD ERROR NOTICE ON SCREEN
:FAILURE
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO ******************************************************************
ECHO ******************************************************************
ECHO ******************************************************************
ECHO ***                                                            ***
ECHO ***            *** UH OH!! I NEED AN ADULT!!!***               ***
ECHO ***                                                            ***
ECHO *** DRIVER FILES NOT FOUND ON K2000 SERVER, SOMETHING IS WRONG ***
ECHO ***                                                            ***
ECHO ******************************************************************
ECHO ******************************************************************
ECHO ******************************************************************
ECHO.
ECHO.
ECHO.
PAUSE
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.


:FINISH
popd
net use Z: /delete
TIMEOUT 5
endlocal

There are other applications for this and that's why I really want to get this working. I highlighted and bolded the part that is failing. %p% is just getting set to nothing, so nothing after that is working. Again, if I hard code the path to %p% myself, then everything works great. It's just the stupid variable for setting the folder path.

An example of the other applications I will get this working with, once this script is working for this application:
  • some of our machines have Office 365 and some are using Office 2016 Standalone (because Office365 shared licensing is awful and doesn't work at all with non-AD users from outside agencies coming into our lab). Office Standalone is nearly 1GB and the updates for office are nearly another 1GB, which I do not want to download as post-install tasks unless necessary (I also don't want an scripted install for just installing one version of Office instead of another). So I already have a preinstall task that asks my techs if certain things should be installed and if so, then I want a version of this script here set up to pull in the files for the proper version of Office from the post-install directory of the K2000 and install, for instance, Office 2016 standalone with it's updates. (Office 365 is set up to with a script to download the latest version from Microsoft and install it, without having to upload the whole install of 1.3GB into the K2000, but Standalone Office can't do that).
Whew, that was a lot of information!
Thank you very much for any help at all.


0 Comments   [ + ] Show comments

Answers (3)

Posted by: chucksteel 7 years ago
Red Belt
0
My solution was to rewrite the tasks.xml file to install directly from the network share instead of copying locally first. You can get the relevant tasks.xml file for your image from the \\kace2000\peinst\scripts folder. Place that modified tasks.xml in c:\kace\engine along with the files from \\kace2000\peinst\hta (it is easiest to grab the c:\kace folder from a machine that is installing post install tasks).

Once these files are in place, launch the kaceengine.exe and it will cycle through the tasks in the tasks.xml file.

I actually wrote a c# application that handles all of this for you, but the code isn't ready for public release, yet.
Posted by: supergreens 7 years ago
Senior White Belt
0
Thanks chucksteel, I'll look into that.
Posted by: SMal.tmcc 7 years ago
Red Belt
0
try using setx vs set

FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SETX machine "%%A"
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ