Follow up to: SQL Server 2008 R2: Problems after computer name change
You could resort to Powershell for that.

I have tested this on a server with multiple instances and this should work:

foreach ($instance in (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances)
{
    if ($instance -eq  "MSSQLSERVER")
    {
    $serverinstance = "."
    }
    else
    {
    $serverinstance = ".\" + $instance  
    }

    Invoke-Sqlcmd -Query "select @@version;" -ServerInstance $serverinstance
}


I replaced your query with something safer on my environment though.

You could use -InputFile to source an sql file