Microsoft SQL Server runs by default under the “NT Service\MSSQLSERVER” account. This is a virtual account, with no username nor password (its all managed by windows).
Occasionally you may wish to run a command using this virtual account. As you don’t know the password, one of the easiest ways is to run this via SQL Server directly, by enabling xp_cmdshell. You can then run the command under that user account.
For security, its recommended to disable the xp_cmdshell afterwards (unless you need it).
--Enable xp_cmdshell
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
--Run Command
DECLARE @command NVARCHAR(1000);
SET @command = 'commandtorun.exe';
EXEC xp_cmdshell @command;
--Disable again
EXEC sp_configure 'xp_cmdshell', 0;
RECONFIGURE;
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE;