Documentation for CLR-Based Alternatives to xp_cmdshell

Abhishek Modi (amodi) 0 Reputation points
2025-07-08T06:13:40.6066667+00:00

Hi Team,

Since extended stored procedures are deprecated, is there any source code or documentation available for a CLR-based alternative to Microsoft system-defined extended stored procedures such as xp_cmdshell?

Thanks,

Abhishek Modi

SQL Server | SQL Server Transact-SQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 124.3K Reputation points MVP Volunteer Moderator
    2025-07-08T07:59:03.0833333+00:00

    Yes. Here you can find how to write a stored procedure in the CLR: https://learn.microsoft.com/en-us/sql/relational-databases/clr-integration/database-objects/getting-started-with-clr-integration?view=sql-server-ver17&tabs=cs.

    To start a command-line process from .NET, you would use the class System.Diagnostics.Process.

    You will have to piece the things together yourself. Keep in mind that once you are in the CLR, it is quite possible that you can achieve what you want to do through .NET directly, without spawning a subprocess. As one example, see this blog post from Raul Garcia: https://techcommunity.microsoft.com/blog/sqlserver/using-clr-to-replace-xp-cmdshell-for-specific-tasks/384391.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.