Automated PC Setup script with inbuilt UAC elevation

This script is designed to automate a large portion of a PC build process we have at my current company.

 

:::::::::::::::::::::::::::::::::::::::::

:: Automatically check & get admin rights

:::::::::::::::::::::::::::::::::::::::::

@echo off

CLS

ECHO.

ECHO =============================

ECHO Running Admin shell

ECHO =============================

:checkPrivileges

NET FILE 1>NUL 2>NUL

if ‘%errorlevel%’ == ‘0’ ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges

if ‘%1’==’ELEV’ (shift & goto gotPrivileges)

ECHO.

ECHO **************************************

ECHO Invoking UAC for Privilege Escalation

ECHO **************************************

setlocal DisableDelayedExpansion

set “batchPath=%~0”

setlocal EnableDelayedExpansion

ECHO Set UAC = CreateObject^(“Shell.Application”^) > “%temp%\OEgetPrivileges.vbs”

ECHO UAC.ShellExecute “!batchPath!”, “ELEV”, “”, “runas”, 1 >> “%temp%\OEgetPrivileges.vbs”

“%temp%\OEgetPrivileges.vbs”

exit /B

:gotPrivileges

::::::::::::::::::::::::::::

:START

::::::::::::::::::::::::::::

setlocal & pushd .

REM Run shell as admin (example) – put code here as you like

:START

set input=Y

set install=Z

set back=START

set drive=M:\ICT\Home\AlexLane\Batch Files + Scripts\System Setup\

cls

title Install Options

echo Choose what to Install:

echo ( 1 ) Full Install (All choices will be run)

echo ( 2 ) Ninite

echo ( 3 ) MFG Client

echo ( 4 ) Windows 7 VPN Client

echo ( 5 ) 7zip Reg file

echo ( 6 ) Open Device Manager

echo ( 7 ) Open Users and Groups (local admin)

echo ( 8 ) GPUpdate /force

echo ( 9 ) Open Windows Update

echo ( A ) Wifi-Profiles

echo.

echo ( Q ) Quit

echo.

:: Prompt for Install

Set /P input=

set install=%input:~0,1%

echo.

:: Verify

if /I %install% EQU Q goto END

if %install% EQU 1 goto NINITE

if %install% EQU 2 goto NINITE

if %install% EQU 3 goto MFGCLIENT

if %install% EQU 4 goto W7VPN

if %install% EQU 5 goto 7ZIPREG

if %install% EQU 6 goto DEVMAN

if %install% EQU 7 goto LOCALADMIN

if %install% EQU 8 goto GPUPDATE

if %install% EQU 9 goto WINDOWSUPDATE

if /I %install% EQU A goto WIFIPROFILE

goto ERR0

:Ninite

cls

TITLE Installing Ninite

echo Ninite is installing. . .

“%drive%\full.exe”

if %install% EQU 2 goto START

goto MFGCLIENT

:MFGCLIENT

cls

title Installing MFG Client

echo Installing MFG Client

regedt32.exe /s “%drive%\newput.reg”

mkdir C:\MFG

xcopy “M:\ICT\Home\AlexLane\Batch Files + Scripts\System Setup\putty.exe” “C:\MFG” /c/d/v/y/s/h/i/r/k

xcopy “M:\ICT\Home\AlexLane\Batch Files + Scripts\System Setup\mfg.lnk” “%userprofile%\Desktop\” /c/d/v/y/s/h/i/r/k

if %install% EQU 3 goto START

goto W7VPN

:W7VPN

cls

title Installing Windows 7 VPN Client

echo Installing Windows 7 VPN Client

“%drive%\Windows-7-VPN-standalone.exe”

if %install% EQU 4 goto START

goto 7ZIPREG

:7ZIPREG

cls

title Installing 7zip Registry File

echo Installing 7zip Registry File. . .

Regedit /S “%drive%\7zext.reg”

if %install% EQU 5 goto START

goto DEVMAN

:DEVMAN

cls

title Device Manager

echo Please check for any missing drivers then close device manager to continue

mmc devmgmt.msc

if %install% EQU 6 goto START

goto LOCALADMIN

:LOCALADMIN

cls

title Local Users and Groups

echo Input local admin user then close window

lusrmgr.msc

if %install% EQU 7 goto START

goto GPUPDATE

:GPUPDATE

cls

title Group Policy Update Froce

echo Running GPUpdate /force

gpupdate /force

if %install% EQU 8 goto START

goto WINDOWSUPDATE

:WINDOWSUPDATE

cls

title Windows Update

echo Please make sure all updates are installed

%windir%\system32\wuapp.exe

if %install% EQU 9 goto START

goto WIFIPROFILE

:WIFIPROFILE

cls

title Wifi Profile

echo Installing Wi-fi profile

“%drive%\wifi-Profile.exe”

if /I %install% EQU A goto START

:: goto Next Program if there is another

goto Start

:ERR0

echo ‘%input%’ is an invalid entry.

echo.

pause

cls

goto %back%

:END

exit

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s