Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
PABluesMan
Starting Member
26 Posts |
Posted - 2008-03-26 : 12:34:19
|
Here ya go. The advantage of this is that it does not rely on [xp_cmdshell] or any external command-line utilities. Enjoy!/*******************************************************************************/CREATE FUNCTION fnc_GetDriveSizes (@Drive CHAR (1))RETURNS @Drives TABLE (Drive CHAR (1), TotalMB MONEY, FreeMB MONEY)ASBEGINDECLARE @FSO INTDECLARE @hr INTDECLARE @oDrive INTDECLARE @RawSize VARCHAR (20)DECLARE @RawFree VARCHAR (20)DECLARE @Size DECIMAL (32, 2)DECLARE @Free DECIMAL (32, 2)DECLARE @DI TABLE ( Drive VARCHAR (1), TotalMB DECIMAL (32, 8), FreeMB DECIMAL (32, 8) )EXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @FSO OUTEXEC @hr = sp_OAMethod @FSO, 'GetDrive', @oDrive OUT, @DriveEXEC @hr = sp_OAGetProperty @oDrive, 'TotalSize', @RawSize OUTEXEC @hr = sp_OAGetProperty @oDrive, 'AvailableSpace', @RawFree OUTSET @Size = CONVERT (BIGINT, @RawSize) / 1048576.0SET @Free = CONVERT (BIGINT, @RawFree) / 1048576.0EXEC @hr = sp_OADestroy @FSOINSERT @Drives (Drive, TotalMB, FreeMB)VALUES (@Drive, @Size, @Free)RETURNEND/*******************************************************************************/I geek, therefore I am |
|
jordanam
Yak Posting Veteran
62 Posts |
Posted - 2008-04-30 : 13:18:42
|
But it does require allowing OLE automation procedures, at least according to my error log.Msg 15281, Level 16, State 1, Procedure sp_OACreate, Line 1SQL Server blocked access to procedure 'sys.sp_OACreate' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online. Msg 15281, Level 16, State 1, Procedure sp_OAMethod, Line 1SQL Server blocked access to procedure 'sys.sp_OAMethod' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online. Msg 15281, Level 16, State 1, Procedure sp_OAGetProperty, Line 1SQL Server blocked access to procedure 'sys.sp_OAGetProperty' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online. Msg 15281, Level 16, State 1, Procedure sp_OAGetProperty, Line 1SQL Server blocked access to procedure 'sys.sp_OAGetProperty' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online. Msg 15281, Level 16, State 1, Procedure sp_OADestroy, Line 1SQL Server blocked access to procedure 'sys.sp_OADestroy' of component 'Ole Automation Procedures' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ole Automation Procedures' by using sp_configure. For more information about enabling 'Ole Automation Procedures', see "Surface Area Configuration" in SQL Server Books Online. |
|
|
|
|
|
|
|