Hard Drive Volume Number and OS Info

  • Hi!

    Is it possible to get the hard drive volume number (or serial number) and operating system name of the machine that the SQL Server is on from a stored procedure?

    Dave

  • Yes.

    -- Create temp table to hold the xp_cmdshell results

    IF OBJECT_ID('tempdb..#tbl1', 'TABLE') IS NOT NULL

    DROP TABLE #tbl1

    CREATE TABLE #tbl1 (Idx INT IDENTITY(1, 1), Txt NVARCHAR(4000))

    INSERT INTO #tbl1 (Txt)

    EXEC xp_cmdshell 'ver'

    INSERT INTO #tbl1 (Txt)

    EXEC xp_cmdshell 'vol'

    SELECT * FROM #tbl1

    Enjoy. PS- if you're using this in SQL2K5 you have to enable xp_cmdshell. This can be done by running

    EXEC sp_configure 'xp_cmdshell', 1

    RECONFIGURE WITH OVERRIDE

  • Thanks!  That got the job done.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply