We can spawn a Windows command shell and passes in a string for execution. Any output is returned as rows of text. (msdn) ex:
1
2xp_cmdshell 'dir C:\'
Set configuration
1
2-- --------------------------------
3-- Set Configuration
4-- --------------------------------
5--
6
7-- To allow advanced options to be changed.
8EXEC sp_configure 'show advanced options', 1;
9GO
10-- To update the currently configured value for advanced options.
11RECONFIGURE
12GO
13-- To enable the feature.
14EXEC sp_configure 'xp_cmdshell', 1
15GO
16-- To update the currently configured value for this feature.
17RECONFIGURE
18--
but, we can do more…
1
2-- --------------------------------
3-- Get server access by SQL Server
4-- --------------------------------
5-- User : MyNewUser
6-- password : MyP@ss1Word!
7
8xp_cmdshell 'NET USER UserTest MyP@ss1Word! /ADD'
9xp_cmdshell 'NET localgroup "Administrators" MyNewUser /ADD'
10-- --------------------------------
1
2-- --------------------------------
3-- Delete user
4xp_cmdshell 'NET USER MyNewUser /DELETE
5-- --------------------------------
1
2-- --------------------------------
3-- Get list of logical by SQL Server
4-- --------------------------------
5
6xp_cmdshell 'wmic logicaldisk get name'
7
8-- with details
9xp_cmdshell 'wmic logicaldisk get name,caption,description,drivetype,providername,volumename,size, freespace'
source : https://social.technet.microsoft.com/forums/windowsserver/en-US/a2f8e48e-38fc-4bc6-9e0e-e7cedea83d66/hard-disk-information-from-command-prompt source : https://ardamis.com/2012/08/21/getting-a-list-of-logical-and-physical-drives-from-the-command-line/
Comments