Saturday, November 06, 2010

Saturday, October 30, 2010

Optimising Battery

Hi

Whilst preparing my media for a long haul flight I have coming up recently, I wanted to make sure I got every last drop of energy out of my laptop battery before it ran out.

What I wanted to do was have a script which closed all applications which are not required to run. All I want is to be able to watch VLC, but I have a number of programs which are running in the background on startup e.g. Dropbox. Obviously this is no use to me on a plane so why leave it running and have it wasting CPU resource?

I first of all found this useful article at Lifehacker for quitting all applications


The second thing I wanted this script to do was to change the power management profile to my super battery saving mode. Windows 7 gives you loads of options to tweak this how you see fit.

I used the powercfg command to set the profile. More details on this can be found here


Lastly I wanted to pin this in the taskbar. In Windows 7 you cannot pin batch files to the taskbar. There are lots of ways around this, I used the following


So my script is as follows (replace username with actual username and GUID of power management profile which is relevant to you)

#battery optimiser
powercfg -s df011ed9-9131-49b9-8090-46963cfb65ce
C:\Windows\System32\taskkill.exe /F /FI "USERNAME eq username" /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne dwm.exe"

The shortcut I created just had explorer.exe preceed it to make sure it could pin to the taskbar

C:\Windows\explorer.exe "C:\Users\username\My Dropbox\Personal\Battery Optimiser.bat"

Some really useful information here and you can tweak it quite a lot to suit you.

Cheers!

Sam

Friday, October 29, 2010

Monday, October 04, 2010

Create XenDesktop 4 administrator through MFCOM

Hello there

XenApp 6 removes MFCOM and replaces it with a full set of powershell SDKs which make scripting tasks far easier to complete.

I was asked to create a script to add a Citrix Administrator for a XenDesktop 4. This was actually easier than I had initially thought. The complexity with this task revolves around the granularity that Citrix administrators have with XenApp. Fortunately there are only a couple of options to configure for XenDesktop.

The below powershell script adds the user administrator from the domain SAMO2 to be a full administrator. To change this to a Delegated administrator change AdminType to 2.

$mfFarm = New-object -com "MetaframeCOM.MetaFrameFarm"
$mfFarm.Initialize(1)
$newadmin=$mfFarm.addadmin()
$newadmin.AccountName = "Administrator"
$newadmin.AccountType = 2
$newadmin.AAName = "SAMO2"
$newadmin.AAType = 3
$newadmin.Enable = 1
$newadmin.AdminType = 3
$newadmin = $newadmin
$newadmin.savedata()

Cheers

Sam


Thursday, September 02, 2010

Nike+ is awesome

I have been looking to start exercising again recently as I have seen my weight slightly creep up and more importantly my general fitness has been pretty poor. I had to walk up the stairs at a Tube station in London due to the escalators being broken and I was out of breathe at the top.

This was the straw that broke the camels back. For my birthday I asked my girlfriend for Nike+. It is a system which has a sensor in your shoe and this connects to either a iPod nano, iPhone, iPod touch or Nike wrist band. This collects data on distance run, time, calories burnt etc.

I wasn't quite sure what to expect when I got this for iPod Nano but I was pleasantly surprised. I hooked up the sensor (hidden beneath the left trainer of my Nike+s) to test it and it looked great. You can get feedback on how far you have run, and current pace. Brilliant!

The best bit about this though is the community feel at the Nike+ site. When you sync your iPod it will send your results to Nike+ if you choose and this tracks your runs in a brilliant way. You can set challenges or goals which is a great motivator.

The best bit for me was the group challenges (of which there are hundreds). I joined the premiership challenge for Tottenham (Come on you Spurs) and each run you complete upon iPod syncage (if that is a word) it will update the challenge table for your team. I find this a great motivation to help your team become the best. Also if you decide not to run one evening you feel that you are letting others down which is a nice reverse psychology method to make you continue running rather than bailing out.

You can also get a heart monitor from Polar which connects in as well.

I highly recommend it, more details can be found here


my own profile is here

http://my.nike.com/shammyowens

Sam!

Friday, August 27, 2010

List Add/Remove Programs on Remote Computer

Quite a handy little script for listing programs showing as installed on a remote location without having to check the registry. Modify the computer name in the script. To output the file to a text file, run from dos with a >c:\output.txt command.

__________

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("COMPUTERNAMEHERE")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "InstallDate: " & objItem.InstallDate
WScript.Echo "ProdID: " & objItem.ProdID
WScript.Echo "Publisher: " & objItem.Publisher
WScript.Echo "Version: " & objItem.Version
WScript.Echo
Next
Next

________

Thursday, August 26, 2010

Running a process on a remote machine SILENTLY

Below is the contents of a script to run a process on a remote workstation.

It will only run the program silently in the background. As you can't interact this is obviously only recommended to be run on processes which don't require any interaction.

The process will run as the user you run the VBS script as, on the workstation specified in the script.

________

strComputer = "remotecomputername"
strCommand = "notepad.exe"


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")


errReturn = objProcess.Create(strCommand, null, null, intProcessID)

If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

__________

GP Templates for disabling removable devices

Below is a template for additional group policies for enabling/disabling removable devices and detailed in http://support.microsoft.com/kb/555324

Details of how to import the template into a Group Policy are in http://support.microsoft.com/kb/323639 under How to Load the Administrative Template.

You may need to select View and untick Show Policies Only for the options to appear under the custom template folder.

__________________

CLASS MACHINE
CATEGORY !!category
CATEGORY !!categoryname
POLICY !!policynameusb
KEYNAME "SYSTEM\CurrentControlSet\Services\USBSTOR"
EXPLAIN !!explaintextusb
PART !!labeltextusb DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynamecd
KEYNAME "SYSTEM\CurrentControlSet\Services\Cdrom"
EXPLAIN !!explaintextcd
PART !!labeltextcd DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 1 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynameflpy
KEYNAME "SYSTEM\CurrentControlSet\Services\Flpydisk"
EXPLAIN !!explaintextflpy
PART !!labeltextflpy DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynamels120
KEYNAME "SYSTEM\CurrentControlSet\Services\Sfloppy"
EXPLAIN !!explaintextls120
PART !!labeltextls120 DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
END CATEGORY
END CATEGORY

[strings]
category="Custom Policy Settings"
categoryname="Restrict Drives"
policynameusb="Disable USB"
policynamecd="Disable CD-ROM"
policynameflpy="Disable Floppy"
policynamels120="Disable High Capacity Floppy"
explaintextusb="Disables the computers USB ports by disabling the usbstor.sys driver"
explaintextcd="Disables the computers CD-ROM Drive by disabling the cdrom.sys driver"
explaintextflpy="Disables the computers Floppy Drive by disabling the flpydisk.sys driver"
explaintextls120="Disables the computers High Capacity Floppy Drive by disabling the sfloppy.sys driver"
labeltextusb="Disable USB Ports"
labeltextcd="Disable CD-ROM Drive"
labeltextflpy="Disable Floppy Drive"
labeltextls120="Disable High Capacity Floppy Drive"
Enabled="Enabled"
Disabled="Disabled"

_______

Thursday, January 28, 2010

Forcing the regional settings via Group Policy using custom templates

Forcing the settings via Group Policy using custom templates
---------------------
You may want to read up on Group Policy if you're not familiar with it first.
Download and a regional setting .adm file (settings below) into C:\WINDOWS\INF on the domain controller. From Active Directory Users and Computers create a new container and place the users to wish to be affected into that container. Create a new group policy, attach it to the container and edit the settings. Note: This is a user configured policy and not a computer policy and will affect all users that are listed in the container that you attach it too.
Click on Administrative Templates underneath User Configuration and select Add/Remove Templates. Browse for the File->Open, and select C:\WINDOWS\INF\RegionalSettings.adm. Close the Add/Remove Templates window. From the group policy window select View->Filtering and untick Only show configured policy settings and Only show policy settings that can be fully managed, select OK. Under User Configuration->Administrative Templates->Control Panel->International Settings you should see 4 policies to set regional settings. Enable UK International Settings.
RegionalSettings.adm contents....
CLASS USER
; created by chriske911 on behalf of..

CATEGORY "Control Panel"
CATEGORY "International Settings"
KEYNAME "Control Panel"
POLICY "USA International Settings"
KEYNAME "Control Panel\International"
EXPLAIN !!USA_regopt
VALUENAME "sCountry"
VALUEON "USA"
ACTIONLISTON
KEYNAME "Control Panel\International"
VALUENAME "iCountry"
VALUE "1"
VALUENAME "iCurrDigits"
VALUE "2"
VALUENAME "iCurrency"
VALUE "2"
VALUENAME "iDate"
VALUE "0"
VALUENAME "iDigits"
VALUE "2"
VALUENAME "iLZero"
VALUE "0"
VALUENAME "iMeasure"
VALUE "0"
VALUENAME "iNegCurr"
VALUE "12"
VALUENAME "iTime"
VALUE "1"
VALUENAME "iTLZero"
VALUE "1"
VALUENAME "Locale"
VALUE "00000409"
VALUENAME "s1159"
VALUE ""
VALUENAME "s2359"
VALUE ""
VALUENAME "sCurrency"
VALUE "$"
VALUENAME "sDate"
VALUE "/"
VALUENAME "sDecimal"
VALUE "."
VALUENAME "sLanguage"
VALUE "ENU"
VALUENAME "sList"
VALUE ","
VALUENAME "sLongDate"
VALUE "dddd, MMMM dd, yyyy"
VALUENAME "sShortDate"
VALUE "M/d/yyyy"
VALUENAME "sThousand"

Sybase - Restoring Master Dump Process

Restoring a master dump file into a blank Sybase set-up.

Install Sybase.
Stop services.

Rename your current D:\Sybase\Data\master.dat to .old.

Change to D:\Sybase\ASE-12_5\bin in CMD

Create an empty master db by typing sqlsrvr -d d:\Sybase\Data\master.dat -z 2k -b 40960 this will create a master device which is 80MB in size.

Then make a copy RUN_SQLBOX.bat and called it something like MasterRecover.bat. Run it. This will leave a batch file version of the Sybase service running. Don't close it.

Load up another CMD window and connect using isql. The SA password will be blank at this point.

You need to set the master DB to use more of the master device in order to load the dump. Type

alter database master
on default "60M"
go

You then need to change the Sybase backup server name. Type:

update sysservers
set srvnetname = "SQLBOX_BS" (or whatever the backup servname should be)
where srvname ="SYB_BACKUP"
go

Start the Sybase backup service in services.msc. You can then load your database by typing

load database master from "D:\locationoffile.dat"
go

The master recover CMD window will now have closed and you then start the normal Sybase server service and connect using advantage or SQL Central Server etc... Note the sa password will be whatever it was in the database you have restored

Adding Windows 2008 DC's to Existing Domain

Adding Windows 2008 Domain Controllers

----------------------------------------------------------------
· You will need the Windows 2008 CD.

· In order to Add 2008 DC’s, the domain functional level needs to be at least Windows 2000 native.

· Check the forest/domain level. If you’re domain is not the root domain in the forest, you may not have sufficient rights to update the forest schema.

· You will need to create or use an existing user account which is a member of the following security groups.

Enterprise Admins

Schema Admins

Domain Admins for the domain that contains the schema master.

· Log onto the Schema Master DC as a user with the rights specified above. To check the Schema Master role you’ll need to load a DLL by running regsvr32 schmmgmt.dll from command prompt to enable the Schema snap-in. You can then go to Start-Run->Type MMC; select File-Add/Remove Snap In and select Active Directory Schema. One loaded, right click on Active Directory Schema and select Operations Master. The current Schema Master will be displayed.

· Go to command prompt and run... D:\sources\adprep\adprep /forestprep

Assuming D:\ is the CD drive.

If you have more than 1 domain controller, you should wait at least 15 minutes for the changes to replicate to other domain controllers

· From the Infrastructure Master DC, go to command prompt and run...D:\sources\adprep\adprep /domainprep /gpprep

Assuming D:\ is the CD drive.
Again if you have more than 1 domain controller, you should wait at least 15 minutes for the changes to replicate to other domain controllers.
To identify the domain Infrastructure Master, go to Active Directory Users and Computers, right-click the domain, click Operations Masters, and then click Infrastructure.

· Join the Windows 2008 server as a member server.

· Go to Start-Run-Type DCPROMO and run through the wizard.

-----------------

Transferring DC (FSMO) Roles

· Schema Master via Active Directory Schema

· Domain Naming Master via Active Directory Domains and Trusts

· RIS Master via Active Directory Users and Computers

· PDC Emulator via Active Directory Users and Computers

· Infrastructure Master via Active Directory Users and Computers