zoukankan      html  css  js  c++  java
  • 扩展 xp_fixeddrives

     

    xp_fixeddrvies提供磁盘分区的信息太少,如下的脚本提供磁盘分区的使用情况,运行需要管理员权限!
    if not exists( select * from sys.configurations(nolock) cc 
     where cc.name='xp_cmdshell' 
     and cc.value_in_use=1)
     begin
        exec sp_configure 'show advanced options',1
        reconfigure
    
        exec sp_configure 'xp_cmdshell',1
        reconfigure
     end
    
    if OBJECT_ID('tempdb..#fixeddrives_temp') is not null
    drop table #fixeddrives_temp;
    Go
    
    
    if OBJECT_ID('tempdb..#totaldrives_temp') is not null
    drop table #totaldrives_temp;
    Go
    
    create table tempdb..#fixeddrives_temp(drive char(1),freesize bigint)
    create table tempdb..#totaldrives_temp(size varchar(100));
    insert into  #totaldrives_temp exec xp_cmdshell 'wmic LogicalDisk get deviceid,size'
    insert into  #fixeddrives_temp exec xp_fixeddrives
    
    select    f.drive,
            t.[totalsizeMB] as [总空间MB],
            (t.[totalsizeMB]-cast(f.freesize as decimal(20,0))) as [已用空间MB],
            f.freesize as [未用空间MB],
    cast(((t.[totalsizeMB]-cast(f.freesize as bigint))*100.0/t.[totalsizeMB]) as decimal(5,1)) as [已使用%],
    cast((cast(f.freesize as bigint)*100.0/t.[totalsizeMB]) as decimal(5,1)) as [未使用%]
    from 
    (
    
    select rtrim(left(LTRIM(size),1)) as drive,
    cast(replace(replace(replace(ltrim(RIGHT(rtrim(size),LEN(size)-2)),char(9),''),char(10),''),CHAR(13),'') as bigint)/1024/1024 as [totalsizeMB]
    
    from  #totaldrives_temp 
    where size not like '%DeviceID  Size%' and LEN(size) not IN (0,1)
    ) AS t
    inner join #fixeddrives_temp f
    on t.drive=f.drive


     

  • 相关阅读:
    枚举
    log4j 简单应用
    [luogu4728 HNOI2009] 双递增序列 (dp)
    [luogu3760 TJOI2017] 异或和(树状数组)
    [luogu1485 HNOI2009] 有趣的数列 (组合数学 卡特兰数)
    [luogu4054 JSOI2009] 计数问题(2D BIT)
    [luogu2594 ZJOI2009]染色游戏(博弈论)
    [luogu2591 ZJOI2009] 函数
    [luogu2148 SDOI2009] E&D (博弈论)
    [luogu2154 SDOI2009] 虔诚的墓主人(树状数组+组合数)
  • 原文地址:https://www.cnblogs.com/fly_zj/p/2485876.html
Copyright © 2011-2022 走看看