48
Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers)

Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

ScriptologyThings we've figured out how to do with

simple batch scripts (so we don't have to

touch computers)

Page 2: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Who?

• Pat and Lori

Page 3: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Where

• Cornell

• 22,000 students

• 18 labs (include CIW)

• Around 500 computers

Page 4: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

What?

• Scripting

Page 5: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Why?

• Fixes,

• Monthly patching,

• software adds upon request

• Lack of skilled techs

• Steady increase in usage and requests

Page 6: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

How?

• Ghost

• Deep Freeze

• Windows batch

Page 7: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Free utilities that we use

• 7za.exe (7zip command line tool)

• NirCmd.exe (Swiss army knife tool, shortcut, elevate…)

• WUInstall.exe (to launch Windows updates)

• BGInfo (Put info on the desktop image)

Page 8: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Just why? Setx

• setx /m TANNERHOST "en-pq.coecis.cornell.edu"

Page 9: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

The Basics: generally useful commands

• If/then/else

• Goto

• If exist

• PrintUI

• Reg (Add/Delete)

• Start (Start /Wait)

• SC (Stop/Start)

• Exit /b ###

• Msiexec

• Shutdown.exe –r –t #

• Wmic

• Del, rmdir, move, etc…

Page 10: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

The Basics: Thaw/Freeze

• Copy DFC.exe to local client

• "c:\windows\system32\dfc.exe" PasswordHere /thawnextboot

• Power Control Reboot

• Power Control will continue the script

• Script continues with Logon

Page 11: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

The Basics: Logon/Logoff

• REM autologon and reboot or quit if autologon set

• if exist c:\scripts\adauth.txt (GOTO Process) else (GOTO End)

• :Process

• REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon" /v DefaultDomainName /t REG_SZ /d cornell.edu /f

• REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon" /v DefaultUserName /t REG_SZ /d CIT-Labs /f

• REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon" /v CachePrimaryDomain /t REG_SZ /d cornell.edu /f

• REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon" /v DefaultPassword /t REG_SZ /d PasswordHere /f

• REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f

• exit /b 99 (Error trapped at console, causes a power control reboot)

• GOTO End

• :End

Page 12: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

The Basics: Install

• MSIExec

• msiexec /i C:\temp\Mathcad15WixInstaller.msi /passive

• Exe

• REM Install Matlab

start /wait c:\temp\install\setup.exe -inputFile c:\temp\my_installer_input.txt

(this install uses an input file to answer all the questions throughout the install)

• Simple install – c:\temp\setup.exe /q or /s

Page 13: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

The Basics: uninstall

• WMIC sample

• wmic product where name="Autodesk Inventor Content Center Libraries 2015

(Desktop Content)" call uninstall /nointeractive

• MSI sample

• MsiExec.exe /X{5783F2D7-0111-0409-0110-0060B0CE6BBA} /qn

• HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Page 14: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Pick a Printer…(from a list of 87!)

• REM Determine lab and set proper default printer

• REM Grab machine name and number (or N or P for Instructor and Op)

• set name=%computername%

• set name=%name:~4,5%

• set number=%computername:~-1%

• REM Go to the right lab section to process

• Goto %name%

Page 15: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Pick a Printer (2)

• :BLUE-

• if %number%==N GOTO BlueEven (Instructor Station)

• If %number%==P GOTO BlueOdd (Operator Station)

• SET /A OddEven=%number% %% 2

• if %OddEven%==1 GOTO BlueOdd

Page 16: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Pick a Printer (3)

• :BlueEven

• printui.exe /y /n\\net-print-win.cit.cornell.edu\engr-lib3d

• GOTO End

• :BlueOdd

• printui.exe /y /n\\net-print-win.cit.cornell.edu\engr-lib1

• GOTO End

Page 17: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Net-Print to PaperCut

• Thaw/Logon

• Launch Devices and Printers Control Panel

• Delete old software, printers and Drivers

• Install new software, printers and drivers

• Set printers to Duplex

• Set default print queue

Page 18: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Launch Control Panel

• REM Open Devices and Printers control panel

• REM Printers create much faster with it open

• start control printers

Page 19: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Delete old Printers and Queues

• REM Remove old Net-Print printers and queues

• REM Set Adobe PDF as default

• printui.exe /y /n "Adobe PDF"

• REM delete old printers

• printui.exe /dl /n "Net-Print Holding Queue" /q

• printui /q /gd /n\\net-print-win.cit.cornell.edu\accel1

• printui /q /dn /n\\net-print-win.cit.cornell.edu\uris4c

Page 20: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Delete Old Printers and Queues (2)

• REM Restart print spooler to free up any drivers that may be in use

• net stop spooler

• net start spooler

• REM Delete old Drivers from the system

• printui.exe /dd /m "Xerox Phaser 4400N NPPS" /q

Page 21: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Delete Old Software

• REM Remove old Net-Print software

• if exist c:\windows\kerberosviewer.exe (goto PROCESS) else (goto END)

• :process

• msiexec /fv c:\temp\kerberosticketviewer.msi /q (Repair: runs from source

and recaches local package)

• msiexec /x c:\temp\kerberosticketviewer.msi /q

• rd /s /q "C:\Program Files\Cornell University\Net-Print\"

• :end

Page 22: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Unzip and install PaperCut Client

• REM unzip PC-Client

• cmd /c c:\7za.exe x "C:\temp\PC-Client.zip" -

o"C:\Temp\“

• REM Install PaperCut Client

• msiexec /i c:\temp\pc-client-admin-deploy.msi /passive

Page 23: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Install Driver

• REM Install the PaperCut Global PostScript Driver

• Printui /ia /m "PaperCut Global postScript" /h "x64" /v

"Type3 - UserMode" /f

c:\temp\PaperCutWHQL\PCGlobal.inf

Page 24: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Install the new Print Queues

• REM install printer(s)

• printui.exe /ga /n\\win.net-print.cornell.edu\campus-bw

• printui.exe /ga /n\\win.net-print.cornell.edu\campus-color

Page 25: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Set the Default Printer

• REM Set Default Printer

• REM Wait for printers to install

• timeout 60 (Reboot for Windows 10 systems)

• printui.exe /y /n\\win.net-print.cornell.edu\campus-bw

Page 26: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Set the Queues to Default to duplex

• REM set queue to duplex

• printui.exe /Sr /n\\win.net-print.cornell.edu\campus-bw

/a "c:\oadiprinter.dat" u f

• printui.exe /Sr /n\\win.net-print.cornell.edu\campus-

color /a "c:\oadiprinter.dat" u f

Page 27: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

OneRing – Monthly Updates process

• Thaw and Logon

• Delete C:\temp (in case it was leftover from previous run)

• Download files (Updates.zip – includes Firefox, chrome, Java, flash, ….)

• Launch Windows Defender defs update and system scan batch file

• runs concurrently with updates

• Unzip Update Files

Page 28: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

OneRing (2)

• Activate Windows and Office with KMS

• Update Adobe Air and Shockwave

• Update Firefox and cleanup desktop

• Launch Firefox

• Update Chome and cleanup desktop

• Launch Chrome (and close it again after 45 seconds)

Page 29: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

OneRing (3)

• Update Adobe acrobat and clean desktop

• Update Flash for IE

• Update Flash for Firefox

• Uninstall old Java

• Install new Java

• Close Firefox (launch a while ago)

Page 30: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

OneRing (4)

• Clean up Java install

• Update Adobe Creative Cloud (with Remote Update manager tool)

• Delete C:\temp folder

• Start Windows updates

• Move Green.cmd to startup folder

• Make sure AV scan has completed, then reboot

Page 31: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Windows Defender

• REM Delete folder if it was left in error

• If exist c:\scripts\AVDone rd /s /q c:\scripts\AVDone

• REM Update to the latest AV definitions

• "c:\Program Files\Microsoft Security Client\MPcmdRun.exe" -SignatureUpdate

• REM Launch Security Essentials quick scan

• "c:\Program Files\Microsoft Security Client\MPcmdRun.exe" -scan -1

• REM Create a folder to flag scan completion

• MD C:\scripts\AVDone

• exit

Page 32: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Update Firefox

• REM Update Firefox and clean up

• if exist c:\temp\firefoxsetup.exe start /wait

c:\temp\firefoxsetup.exe -ms

• del /q /f "C:\Users\Public\Desktop\Mozilla

Firefox.lnk"

Page 33: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Uninstall old Java

• REM Uninstall old Java installations

• if exist c:\temp\jdkupdate.exe wmic product where

"name like '%%Java 8%%'" call uninstall /nointeractive

• if exist c:\temp\jdkupdate.exe wmic product where

"name like '%%Java SE%%'" call uninstall /nointeractive

Page 34: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Install new Java

• REM Install new Java version

• if exist c:\temp\jdkupdate.exe start /wait

c:\temp\jdkupdate.exe

INSTALLCFG=C:\temp\javaconfig.txt

Page 35: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Close Firefox

• REM Kill Firefox for visibility

• cmd /c taskkill /im firefox.exe

Page 36: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Update Adobe Creative Cloud

• REM Update Adobe CC

• c:\temp\RemoteUpdateManager.exe

Page 37: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Launch Windows Updates

• REM Start Windows Updates

• "C:\scripts\wuinstall.exe" /install /criteria "IsHidden=0

and IsInstalled=0"

Page 38: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Move Green.cmd to startup folder

• REM Move Green.cmd to startup folder to notify of

Windows Updates success

• copy /y c:\scripts\green.cmd

"c:\ProgramData\microsoft\Windows\Start

Menu\Programs\Startup\"

Page 39: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Green.cmd

• cmd /k "color 27&echo

off&cls&echo.&echo.&echo.&echo.&echo Windows

Updates have completed successfully - ready to freeze!"

Page 40: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Make sure AV scan has completed

• REM Check to make sure AV scan is complete

• if exist c:\scripts\AVDone (goto Done) else (goto Wait)

• :Enter

• if exist c:\scripts\AVDone (goto Done) else (goto Wait)

• :Wait

• Timeout 15

• Goto Enter

• :Done

• RD /s /q c:\scripts\AVDone

Page 41: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

After OneRing – Check Freeze/Thaw status

• REM run DFC.exe to get status

• c:\windows\system32\dfc.exe get /isfrozen

• if errorlevel 1 (exit /b 1) else (exit /b 2)

Page 42: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Cautionary note about Deep Freeze and

reboots

• Ghost Power control reboot

• Good for continuing a task

• Windows Shutdown –r –t 0 reboot

• Good for rebooting to a frozen state

• Power control to frozen state results in a boot loop.

Page 43: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Check to see if software is installed

• REM Check for MathCAD 15

• If exist "C:\Program Files (x86)\mathcad\MathCAD

15\" (exit /b 15) else (exit /b 20)

Page 44: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Registry adds

• Rem Add Registry key (Accept new IE add-ins)

• REG ADD

"HKLM\SOFTWARE\Microsoft\Windows\CurrentVer

sion\Policies\Ext" /v NoFirsttimeprompt /t

REG_Dword /d 1

Page 45: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

NirCmd fun

• REM Put up a screen

• start c:\nircmd.exe infobox "Updates in Progress! Do

not use this machine for any purpose." "Warning!"

Page 46: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

A Note on Start

• Works

• Start c:\nircmd.exe

• Fails

• Start “c:\nircmd.exe”

• Start “” “c:\nircmd.exe”

Page 47: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

OK, I’ll stop now….

• Questions?

• Comments?

• Better ways?

Page 48: Scriptology - Wright State University · Scriptology Things we've figured out how to do with simple batch scripts (so we don't have to touch computers) Who? ... •Reg (Add/Delete)

Thank You!

• Pat Washburn

[email protected]

• Very Useful site:

• http://www.robvanderwoude.com/