Showing posts with label bat. Show all posts
Showing posts with label bat. Show all posts

Tuesday, February 15, 2011

Template CMD Script for App Installs

This is obviously bare-bones and will need to be modified to suit specific implementations.  There are dozens of ways to execute a software installation, including setup.exe files, extracting ZIP and other archive files, registering DLLs with REGSVR32, and the ugly-ass, vice-grip + screwdriver + duct tape approach where you manually build folder trees, copy files, register DLLs, add and modify registry keys and make or replace shortcuts.  Oh, the torture.

EDIT: Updated 7/30/2011 to include errorlevel 3010 (reboot pending)


@echo off
rem ****************************************************************
rem  Filename..: setup.cmd
rem  Author....: David M. Stein
rem  Date......: 07/30/2011
rem  Purpose...: install apps in controlled sequence
rem ****************************************************************
rem Additional Notes:
rem
rem ****************************************************************
title Installing Applications
CLS
echo Installing Applications...
SETLOCAL
set APPNAME=MyApplicationSuite2011
set LOG=%TMP%\%APPNAME%_install.log
set MSI=/quiet /norestart
echo %DATE% %TIME% installing... %APPNAME%... >%LOG%
echo %DATE% %TIME% source....... %~dps0 >>%LOG%
echo %DATE% %TIME% target....... %COMPUTERNAME% >>%LOG%
echo %DATE% %TIME% windir....... %WINDIR% >>%LOG%
echo %DATE% %TIME% progfiles.... %PROGRAMFILES% >>%LOG%
echo %DATE% %TIME% temp......... %TMP% >>%LOG%
echo INSTALL LOG: %LOG%
echo ----------------------------------------------- >>%LOG%
echo *** APPLICATION NAME 1 >>%LOG%
echo %DATE% %TIME% info: checking if application is already installed... >>%LOG%
if exist "%ProgramFiles%\FolderName\filename.exe" (
echo %DATE% %TIME% info: ## application is already installed >>%LOG%
) else (
echo %DATE% %TIME% info: ## installing application... >>%LOG%
echo %DATE% %TIME% command = msiexec /i "%~dps0Folder\filename.msi" TRANSFORMS="%~dps0Folder\filename.MST" >>%LOG%
   msiexec /i "%~dps0Folder\filename.msi" TRANSFORMS="%~dps0Folder\filename.MST" %MSI%
   if %errorlevel%==0 (
      echo %DATE% %TIME% info: installation SUCCESSFUL >>%LOG%
   ) else (
      if %errorlevel%==3010 (
         echo %DATE% %TIME% info: installation SUCCESSFUL [reboot pending] >>%LOG%
      ) else (
         echo %DATE% %TIME% file: exit code is %errorlevel% >>%LOG%
         rem Raise error to parent process!!
         exit %errorlevel%
      )

   )
)
rem ------------------------------------------------
rem echo *** APPLICATION NAME 2 >>%LOG%
rem ------------------------------------------------
rem
rem repeat code above with modifications as needed
rem
rem ------------------------------------------------
echo %DATE% %TIME% info: adjusting application folder permissions... >>%LOG%
cacls "%ProgramFiles%\FolderName" /T /E /C /G Users:C
echo ----------------------------------------------- >>%LOG%
echo %DATE% %TIME% info: applying attachmate file association fix... >>%LOG%
REG DEL HKCR\.xxx /f
REG ADD HKCR\.xxx /ve /d "ApplicationClass.ProgName.1" /f
echo ----------------------------------------------- >>%LOG%
echo %DATE% %TIME% info: adjusting registry permissions... >>%LOG%
REGINI.exe %~dps0customregsettings.ini
echo ----------------------------------------------- >>%LOG%
echo %DATE% %TIME% completed! result code: %errorlevel% >>%LOG%
ENDLOCAL
rem Raise error to parent process!!
exit %errorlevel%

Sunday, December 12, 2010

Useful CMD Script Path Expansion Variables


@echo off
rem http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true
echo displaying various path alias values...
echo %~nx0
echo %comspec%
echo %~d0
echo %~dp0
echo %~dps0
echo %~dpp0
echo %~f0
echo --------------------------------
echo %systemdrive%
echo %systemroot%
echo %windir%
echo %programdata%
echo %programfiles%
echo %userprofile%
echo %allusersprofile%
echo %temp%
echo %commonprogramfiles%
echo %commonprogramfiles(x86)%
echo %appdata%
echo %localappdata%
echo %public%

Wednesday, September 8, 2010

Script Tip: Determine the Script File Path

With BAT/CMD scripts you can simply prefix any path references with %~dps0 to get to things in the same location (folder/UNC) where the script itself resides.  So if you run..

start /wait %~dps0setup.exe /silent /norestart

It runs setup.exe from the same folder location. (that is not a typo, there should be NO space between the zero and the rest of the file path)

It's just as easy with KiXtart using the @scriptdir macro, but with VBscript it's not that simple.  But it's not difficult either…

scriptPath = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")

An example of running setup.exe in the same folder with VBscript might be…

filePath = scriptPath & "\setup.exe"
result = objShell.Run(filePath & " /silent /norestart", 7, True)

However, be careful to wrap paths in double-quotes if they contain spaces…

filePath = Chr(34) & scriptPath & "\setup.exe" & Chr(34)
result = objShell.Run(filePath & " /silent /norestart", 7, True)

Sunday, October 25, 2009

Windows 7 Clean Install using Upgrade Media

Just a slightly different spin to the post by Paul Thurrott about performing a clean install of Windows 7 using “upgrade” media without having to install XP or Vista first.  This just wraps the steps inside a .BAT script.  Make sure you read Paul’s article first or you’ll be lost.  Be sure to run this from a CMD console that was launched via “Run as Administrator” or it won’t work…

@echo off
rem the following line between the divider lines should NOT wrap!
rem --------------------------------
REG ADD "HKLM/Software/Microsoft/Windows/CurrentVersion/Setup/OOBE/" /v MediaBootInstall /d 1 /t REG_DWORD /f
rem --------------------------------
echo Registry key value has been set.
pause
slmgr /rearm
echo Activation skip-rearm has been set.
echo Press ENTER to reboot your computer now...
pause
shutdown -r -f -t 2