USE master
GO
-- Make it possible to GRANT EXECUTE ON xp_cmdshell to user
IF NOT EXISTS (SELECT * FROM dbo.sysusers WHERE NAME = N'cnet' AND uid < 16382)
EXEC sp_grantdbaccess N'cnet', N'cnet'
GO
GRANT EXECUTE ON dbo.xp_cmdshell TO cnet
GO
-- This undocumented SP will reconfigure the SQL Agent to allow regular users
-- to run xp_cmdshell through the proxy account, although they would still need explicit GRANT
EXECUTE msdb.dbo.sp_set_sqlagent_properties @sysadmin_only = 0
GO
-- Set a windows user as proxy account for the SQL agent
-- THIS SECTION IS DEFAULT CONFIGURED TO USE A LOCAL ACCOUNT, MAY BE CHANGED TO A DOMAIN
DECLARE @localhost varchar(255)
-- CHANGE THIS TO A DOMAIN INSTEAD
SET @localhost = SUBSTRING(@@SERVERNAME, 0, CHARINDEX('\', @@SERVERNAME))
exec xp_sqlagent_proxy_account 'SET', @localhost, N'windowsuser', N'password'
GO