0

Problem to execute following command shell for msg command through Sql Server 2008 r2

EXEC master..xp_cmdshell 'msg Curious.k /server:CuriousK-PC "Hello"'

And Output is : user.name does not exist or is disconnected NULL

But from command prompt its successfully executed and message sent to the require host. c:\>msg Curious.k /server:CuriousK-PC "Hello"

At the same time following command is successfully executed

EXEC sp_configure 'show advanced option' EXEC sp_configure 'xp_cmdshell'

Result of above both query is :

minimum maximum config_value run_value 0 1 1 1

EXEC xp_cmdshell 'del "E:\01. DailyBackup\MainDB.bak"' exec master..xp_cmdshell 'net use t: "\\192.168.0.1\c$" My@Secrete007 /user:MyCoLocal\user.name' EXEC master..xp_cmdshell 'copy t:\a.txt t:\b.txt' EXEC master..xp_cmdshell "net use t: /delete"

All of above is executing perfectly but following command not work through sql server EXEC master..xp_cmdshell 'msg Curious.k /server:CuriousK-PC "Hello"'

curious K
  • 145
  • 5
  • 15
  • It doesn't work because the account SQL Server is running under can't access whatever domain resources are necessary to execute `msg`, while your account can. You can use a [dedicated proxy account for `xp_cmdshell`](https://learn.microsoft.com/sql/relational-databases/system-stored-procedures/sp-xp-cmdshell-proxy-account-transact-sql). Preferably one with the least amount of rights necessary. – Jeroen Mostert Jul 11 '17 at 12:04
  • Also a PowerShell or SQLCMD script executed through SQL Agent would be better than using xp_cmdshell. – David Browne - Microsoft Jul 11 '17 at 12:07
  • SQL server accessing through sa and domain user having administrator rights (full rights). All other cmd's are running prefectly except msg cmd which successfully run through cmd prompt even from normal user. – curious K Jul 11 '17 at 12:10
  • Are you saying SQL Server is running under a domain administrator account? Because that would be bad, unless it's for testing purposes. – Jeroen Mostert Jul 11 '17 at 14:50
  • Also, the problem may simply be that `msg` can't be called from a service (those run in their own isolated sessions). Consider another way to alert users. DBMail would be one option. – Jeroen Mostert Jul 11 '17 at 14:56

0 Answers0