Domino 9 und frühere Versionen > ND9: Entwicklung

Freien Speicherplatz auf Laufwerk über Lotusscript ermitteln

(1/2) > >>

schroederk:
Hallo,

ich würde gerne über Lotusscript den freien Speicherplatz der Laufwerke des Servers ermitteln.
Da es ja hierfür keine direkte Möglichkeit gibt, dachte ich an die Windows API.


--- Code: ---Declare Function GetDiskFreeSpace Lib "Kernel32" Alias _
"GetDiskFreeSpaceA" (ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters _
As Long) As Long

Sub Initialize
Dim drv As String
Dim ret As Long
Dim sectors As Long
Dim bytes As Long
Dim free As Long
Dim total As Long

drv = "C:\"
ret = GetDiskFreeSpace(drv, sectors, bytes, free, total)

MessageBox "S=" & sectors & " B=" & bytes & " F=" & free
End Sub

--- Ende Code ---


Für Laufwerk C:\ bekomme ich einen Wert zurück: S=8 N=512 F=36.264.391
Meinem Verständnis nach sollte sectors * bytes * free den freien Platz ermitteln.
Das Betriebssystem selber zeigt mir an: 37.992.173.568
Ich hab keinen Schimmer, was das also für Werte sind, bzw. wie ich auf den tatsächlichen freien Platz kommen kann.  :-:

Wenn ich als Laufwerk D:\ angebe, dann gibt mir die Funktion überall 0 zurück?  ???
Wieso funktioniert die Funktion nur bei C:\ ?

Weiß jemand, wie ich die korrekten Werte für alle lokalen Laufwerke ermitteln kann?

eknori (retired):
Hier eine Klasse, die ich irgendwann 2006 mal geschrieben habe ( funktioniert auch noch unter Win 10 , 2012, 2016 ... )

mit


--- Code: ---Sub Click(Source As Button)
Dim strComputer As String
Dim i As Integer
strComputer = "192.168.178.33"
Dim HDD As Variant

Set HDD = New HDD(strComputer)
For i = 0 To ( HDD.TOTALNUMBERS -1 )
Msgbox _
"Cyl: " & HDD.CYLINDER(i) &_
" Heads: " & HDD.HEADS(i) & _
" Sectors: " & HDD.SECTOR(i) & _
" Tracks: " & HDD.TRACKS(i) &_
" TracksPerCylinder: " & HDD.TRACKSPERCYLINDER(i)
Next
For i = 0 To ( HDD.TOTALNUMBERS -1 )
Msgbox HDD.MODEL(i)
Next
End Sub
--- Ende Code ---

bekommst du die Informationen für ALLE Laufwerke eines Rechners ( lokal oder remote )


--- Code: ---%REM
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Run-Time Requirements

WMI is preinstalled in Windows Server 2003, Windows XP, Windows Me, and Windows 2000.

Windows NT Workstation 4.0 SP4 and later:  
WMI is available through "Add/Remove Windows components" in Control Panel, as WBEM option install.
A later, more comprehensive, version is available as an Internet
download from http://www.microsoft.com/downloads.
See "WMI CORE 1.5 (Windows 95/98/NT 4.0)".

Windows 98/95:  
WMI CORE 1.5 (Windows 95/98/NT 4.0) is available as an Internet download from
http://www.microsoft.com/downloads.

This download requires Microsoft Internet Explorer version 5 or later.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
%END REM
Option Public
Option Declare

%REM
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 Version 1.0, Ulrich Krause, http://www.eknori.de

 Supported Platforms:
 ----------------------------------------------------
 Windows Server 2003
 Windows XP
 Windows 2000
 Windows NT 4.0
 Windows 98

 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_diskdrive.asp
 
 The Win32_DiskDrive WMI class represents a physical disk drive as seen by a computer running the Windows operating system.
 Any interface to a Windows physical disk drive is a descendent (or member) of this class.
 The features of the disk drive seen through this object correspond to the logical and management characteristics of the drive.
 In some cases, this may not reflect the actual physical characteristics of the device.
 Any object based on another logical device would not be a member of this class.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
%END REM
Class HDD
Private varHDD_HEADS As Variant
Private varHDD_SECTOR As Variant
Private varHDD_TRACKS As Variant
Private varHDD_CYLINDER As Variant
Private varHDD_SIZE As Variant
Private varHDD_NAME As Variant
Private varHDD_TRACKSPERCYLINDER As Variant
Private varHDD_PARTITIONS As Variant
Private varHDD_MODEL As Variant

Private HDD_MANUFACTURER As String

Private HDD_TOTAL_NUMBERS As Integer

Private WMIService As Variant
Private colHDDDrives As Variant

Public Sub New ( computer As String )
HDD_TOTAL_NUMBERS = 0

If computer = "" Or Ucase(computer) = "LOCALHOST" Then computer = "."

Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set colHDDDrives = WMIService.ExecQuery("Select * from Win32_DISKDrive",,48)

Forall HDD In colHDDDrives

Redim Preserve HDD_MODEL ( HDD_TOTAL_NUMBERS ) As String
HDD_MODEL ( HDD_TOTAL_NUMBERS )   = HDD.Model

Redim Preserve HDD_PARTITIONS ( HDD_TOTAL_NUMBERS ) As String
HDD_PARTITIONS ( HDD_TOTAL_NUMBERS )   = HDD.Partitions

Redim Preserve HDD_CYLINDER ( HDD_TOTAL_NUMBERS ) As String
HDD_CYLINDER ( HDD_TOTAL_NUMBERS )   = HDD.TotalCylinders

Redim Preserve HDD_HEADS ( HDD_TOTAL_NUMBERS ) As String
HDD_HEADS ( HDD_TOTAL_NUMBERS )   = HDD.TotalHeads

Redim Preserve HDD_SECTOR ( HDD_TOTAL_NUMBERS ) As String
HDD_SECTOR ( HDD_TOTAL_NUMBERS )   = HDD.TotalSectors

Redim Preserve HDD_TRACKS ( HDD_TOTAL_NUMBERS ) As String
HDD_TRACKS ( HDD_TOTAL_NUMBERS )   = HDD.TotalTracks

Redim Preserve HDD_TRACKSPERCYLINDER ( HDD_TOTAL_NUMBERS ) As String
HDD_TRACKSPERCYLINDER ( HDD_TOTAL_NUMBERS )   = HDD.TracksPerCylinder

Redim Preserve HDD_NAME ( HDD_TOTAL_NUMBERS ) As String
HDD_NAME ( HDD_TOTAL_NUMBERS )   = HDD.Name

Redim Preserve HDD_SIZE ( HDD_TOTAL_NUMBERS ) As String
HDD_SIZE ( HDD_TOTAL_NUMBERS )  = HDD.Size

HDD_TOTAL_NUMBERS = HDD_TOTAL_NUMBERS + 1

End Forall
varHDD_MODEL = HDD_MODEL
varHDD_SIZE = HDD_SIZE
varHDD_NAME = HDD_NAME
varHDD_CYLINDER = HDD_CYLINDER
varHDD_HEADS = HDD_HEADS
varHDD_SECTOR = HDD_SECTOR
varHDD_TRACKS = HDD_TRACKS
varHDD_TRACKSPERCYLINDER = HDD_TRACKSPERCYLINDER
varHDD_PARTITIONS = HDD_PARTITIONS
End Sub

Public Property Get MODEL  ( i As Integer )  As String
%REM
Manufacturer's model number of the disk drive.
%END REM
MODEL = varHDD_MODEL (i)
End Property

Public Property Get PARTITIONS  ( i As Integer )  As Integer
%REM
Number of partitions on this physical disk drive that are recognized by the operating system.
%END REM
PARTITIONS = varHDD_PARTITIONS (i)
End Property

Public Property Get CYLINDER  ( i As Integer )  As String
%REM
Total number of cylinders on the physical disk drive.
Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.
The value may be inaccurate if the drive uses a translation scheme to support high capacity disk sizes.
Consult the manufacturer for accurate drive specifications.
%END REM
CYLINDER = varHDD_CYLINDER (i)
End Property

Public Property Get HEADS  ( i As Integer )  As String
%REM
Total number of heads on the disk drive.
Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.
The value may be inaccurate if the drive uses a translation scheme to support high capacity disk sizes.
Consult the manufacturer for accurate drive specifications.
%END REM
HEADS = varHDD_HEADS (i)
End Property

Public Property Get SECTOR  ( i As Integer )  As String
%REM
Total number of sectors on the disk drive.
Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.
The value may be inaccurate if the drive uses a translation scheme to support high capacity disk sizes.
Consult the manufacturer for accurate drive specifications.
%END REM
SECTOR = varHDD_SECTOR (i)
End Property

Public Property Get TRACKS  ( i As Integer )  As String
%REM
Total number of tracks on the disk drive.
Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.
The value may be inaccurate if the drive uses a translation scheme to support high capacity disk sizes.
Consult the manufacturer for accurate drive specifications.
%END REM
TRACKS = varHDD_TRACKS (i)
End Property

Public Property Get TRACKSPERCYLINDER  ( i As Integer )  As String
%REM
Number of tracks in each cylinder on the physical disk drive.
Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.
The value may be inaccurate if the drive uses a translation scheme to support high capacity disk sizes.
Consult the manufacturer for accurate drive specifications.
%END REM
TRACKSPERCYLINDER = varHDD_TRACKSPERCYLINDER (i)
End Property

Public Property Get HDDNAME  ( i As Integer )  As String
%REM
Label by which the object is known. When subclassed, the property can be overridden to be a key property.
This property is inherited from CIM_ManagedSystemElement.
%END REM
HDDNAME = varHDD_NAME (i)
End Property

Public Property Get SIZE  ( i As Integer ) As Double
%REM
Size of the disk drive.
It is calculated by multiplying the total number of cylinders, tracks in each cylinder, sectors in each track,
and bytes in each sector.
%END REM
SIZE = varHDD_SIZE (i)
End Property

Public Property Get TOTALNUMBERS As Integer
%REM
Total number of disk drives installed on the system
%END REM
TOTALNUMBERS =  HDD_TOTAL_NUMBERS
End Property

End Class
--- Ende Code ---

schroederk:
Herzlichen Dank für Dein Script. Das werde ich in jedem Fall ausprobieren.  :D

DominoDancing:
Hallo K.,

ich habe hierzu ein Programmdokument auf den zugehörigen Servern erstellt (Batchdatei-Aufruf), das per Befehlszeile eine dir-Eingabeaufforderung auf den entsprechenden Laufwerken in jeweils eine Datei umgeleitet hat (z.B. dir c:\ > c:\temp\laufwerkc.txt). Dann habe ich diese Dateien per Script ausgewertet (letzte Zeile der Datei vor Bytes frei).

Ja, klar ist das von Eknori chicer, komplexer, allgemeingültiger etc., eben einfach eknoriger. Aber meins tut's auch. :) Ist halt nur so 'ne Idee von mir.

Liebe Grüße
René

platzebo:
Es geht auch kürzer :)
Hab mir ein Script geschrieben um mir eine Nachricht zukommen zu lassen, wenn der Platz am Server zu klein wird - vielleicht hilft es Dir
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object

Sub Initialize
   
   Dim session As New NotesSession
   Dim db As NotesDatabase   
   Dim objFSO As Variant
   Dim colDrives As Variant
   Dim memo As NotesDocument
   
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set colDrives = objFSO.Drives
   Forall objDrive In colDrives
      
      If Cstr(objDrive.DriveLetter) = gNDparam.getItemValue("hddDriveLetter")(0) Then
         If Cdbl(objDrive.AvailableSpace) < Cdbl(gNDparam.getItemValue("hddLimit")(0)) Then
            Set db = session.CurrentDatabase
            Set memo = db.CreateDocument
            memo.form = "Memo"
            memo.subject = "HDD-Limit am Server " + db.server + " erreicht. Bitte alte Daten entfernen"
            memo.sendTo = gNDparam.getItemValue("sendToHDDLimit")(0)
            Call memo.Send(False)
         End If
      End If
      
   End Forall
   
End Sub

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln