Startup scripts – add windows features

Quick update for January!

It is easy to control Windows 7 features by turning them on and off by startup scripts. Pop along to your group policy and add the following script to add the Games features back into Windows 7 Enterprise (default is not to install games – how boring!)

REM Install Games
dism /online /enable-feature /featurename:"InboxGames" /norestart /quiet

You can control any features with this simply look up the featurename of the component you want to use.

View your currently installed features with:

dism /online /get-features

You may want to pipe that to something as it can be a long list!

Manage Windows Printers from command line script

Every now and again you come across the issue of printers…..

Most people in larger environment will use Group Policy to manage your printer deployment, certainly in Windows Vista/7 this was made a lot easier with the enhancement of group policy.

This script was included with Windows XP and has appeared in subsequent versions of Windows.

C:\>cscript %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs /?
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
Usage: prnmngr [-adxgtl?][c] [-s server][-p printer][-m driver model]
               [-r port][-u user name][-w password]
 Arguments:
 -a     - add local printer
 -ac    - add printer connection
 -d     - delete printer
 -g     - get the default printer
 -l     - list printers
 -m     - driver model
 -p     - printer name
 -r     - port name
 -s     - server name
 -t     - set the default printer
 -u     - user name
 -w     - password
 -x     - delete all printers
 -xc    - delete all printer connections
 -xo    - delete all local printers
 -?     - display command usage
Examples:
 prnmngr -a -p "printer" -m "driver" -r "lpt1:"
 prnmngr -d -p "printer" -s server
 prnmngr -ac -p "\\server\printer"
 prnmngr -d -p "\\server\printer"
 prnmngr -x -s server
 prnmngr -xo
 prnmngr -l -s server
 prnmngr -g
 prnmngr -t -p "\\server\printer"

A couple of handy commands to get you started

Remove all network connected printers:

cscript %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -xc

If you prefer your approach to be a little more precise, then below is the script I use for removing particular printers and their drivers from machine. Also a very handy way for dealing with 64 bit and 32 bit Windows printers….

rem Remove all Kyocera Drivers
 rem Check Environment
 IF NOT "%ProgramFiles(x86)%"=="" (goto ARP64) else (goto ARP86)
 REM 64 Bit
 :ARP64
 cscript %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Kyocera FS-2020D KX" -v 3 -e "Windows x64"
 cscript %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Kyocera TASKalfa 500ci KX" -v 3 -e "Windows x64"
 goto End
 REM 32 Bit
 :ARP86
 cscript %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Kyocera FS-2020D KX" -v 3 -e "Windows NT x86"
 cscript %windir%\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -d -m "Kyocera TASKalfa 500ci KX" -v 3 -e "Windows NT x86"
 goto End
 :End

Auto-create Outlook signature based on Active Directory

A long time ago I created a useful script to make create a default signature. This evolved over the years and when I was asked if it were possible to standardise all our signatures across each office and company I thought why not make use of Active Directory and gather most details from there.

So the below script looks up the logged on user and then matches it against the company they work for and then adds some extra details that we wanted, apart from that its pretty straight forward.

You need to have Word and Outlook installed to run this script.

I run the script on user logon so it sets up email signatures for the user.

' Auto Add Email Signature based on Active Directory Information
' Created by Iain Gibson 9/02/2007
on error resume next
' Collect Logged on user details and connect to AD
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
' Grab some of the users details from AD
strName = objUser.FullName
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber
strFax = objUser.faxNumber
strEmail = objUser.mail
' Choose which company they work for and ammend extra signature lines
Select Case strCompany
case "COMPANY1"
strPre = "PRE NAME DETAILS "
strExtra = "POST NAME DETAILS"
strWeb = "WEBSITE"
strAddress = "SHORT ADDRESS FORM"
case "COMPANY2"
strPre = "PRE NAME DETAILS "
strExtra = "POST NAME DETAILS"
strWeb = "WEBSITE"
strAddress = "SHORT ADDRESS FORM"
case "COMPANY3"
strPre = "PRE NAME DETAILS "
strExtra = "POST NAME DETAILS"
strWeb = "WEBSITE"
strAddress = "SHORT ADDRESS FORM"end select
' Create MS Word Document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
' Start Text area selection & choose email signature options
Set objSelection = objWord.Selection
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
' Setup Font and type style & Include variables from AD
objSelection.Font.Name = "Palatino Linotype"
objSelection.Font.Size = 12
objSelection.Font.Bold = 1
objSelection.TypeText strName
objSelection.TypeParagraph()
objSelection.Font.Italic = 1
objSelection.Font.Bold = 0
objSelection.Font.Size = 10
objSelection.TypeText strTitle
objSelection.TypeParagraph()
objSelection.TypeText strDepartment
objSelection.TypeParagraph()
objSelection.Font.Bold = 1
objSelection.Font.Italic = 0
objSelection.Font.Size = 12
objSelection.TypeText strPre & strCompany & ", "
objSelection.Font.Bold = 0
objSelection.Font.Size = 10
objSelection.TypeText strExtra
objSelection.TypeParagraph()
objSelection.TypeText strAddress
objSelection.TypeParagraph()
objSelection.TypeText "Email: " & strEmail
objSelection.TypeParagraph()
objSelection.TypeText "Web: " & strWeb
objSelection.TypeParagraph()
objSelection.TypeText "Tel: " & strPhone & "  Fax: " & strFax
objSelection.TypeParagraph()
Set objSelection = objDoc.Range()
' Update Outlook with the new signature and set as default
objSignatureEntries.Add "AD Signature", objSelection
objSignatureObject.NewMessageSignature = "AD Signature"
objSignatureObject.ReplyMessageSignature = "AD Signature"
objDoc.Saved = True
objWord.quit

Mount Virtual Hard Disks

Something I have found useful lately, so I though it best to share.

Mounting and editing the Microsoft Virtual Hard disks can acutally be quite easy. Rather than going into the Disk Management service in Windows you can use scripting to access the virtual disk management layer.

Anyways, the code you need is:

Option Explicit
Dim WMIService
Dim VHDService
Dim VHD
'Specify the VHD to be mounted
VHD = "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\New.vhd"
'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
'Get the MSVM_ImageManagementService
Set VHDService = WMIService.ExecQuery("SELECT * FROM Msvm_ImageManagementService").ItemIndex(0)
'Mount the VHD or use UnMount to unount the VHD
VHDService.Mount(VHD)