Giving Permissions to BUILTIN\Users in SQL Server

I had a script for granting access to a SQL Server Express database to all users that looked like this:

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'BUILTIN\Users')
BEGIN
	CREATE USER [BUILTIN\Users] FOR LOGIN [BUILTIN\Users]
	EXEC sp_addrolemember N'db_datareader', N'BUILTIN\Users'
	EXEC sp_addrolemember N'db_datawriter', N'BUILTIN\Users'
	GRANT EXECUTE TO [BUILTIN\Users]
END

The problem was that this only worked on English Windows. For example, on a Swedish Windows, this group is called “BUILTIN\Användare”. When looking at the sys.server_principals system view, I noticed that the SID is constant (0x01020000000000052000000021020000) but the name varies, so I could solve this with a dynamic SQL script:

DECLARE @builtinUsers nvarchar(128), @sqlString nvarchar(max)
SET @builtinUsers = (SELECT name FROM sys.server_principals where sid=0x01020000000000052000000021020000)
SET @sqlString = 'IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = ''' + @builtinUsers + ''') CREATE USER [' + @builtinUsers + '] FOR LOGIN [' + @builtinUsers + ']'
EXEC sp_executesql @sqlString
SET @sqlString = 'EXEC sp_addrolemember ''db_datareader'', ''' + @builtinUsers + ''''
EXEC sp_executesql @sqlString
SET @sqlString = 'EXEC sp_addrolemember ''db_datawriter'', ''' + @builtinUsers + ''''
EXEC sp_executesql @sqlString
SET @sqlString = 'GRANT EXECUTE TO [' + @builtinUsers + ']'
EXEC sp_executesql @sqlString
GO