.net で Windows 2003 R2 のクオータ情報を参照する
Windowsでクォータといったら、ディスククォータを指すが、
R2からディレクトリクォータを設定できるようになった。
しかーし、.Net でディレクトリクォータ情報をいじれないと、思っていたのはかなり前の話。
見つけました。
Programming FSRM quotas | How Things (Should) Work
ついでにmsdnの情報。
FSRM Interfaces | Microsoft Docs
開発環境はXPで、実行環境がR2の場合は、
R2の%WINDIR%\System32のsrmlib.dllをコピーしてXPの%WINDIR%\System32にコピーしたあと、
プロジェクトの参照設定を行う。
名前空間は以下のとおり。
using Microsoft.Storage;
さもないと、実行環境でエラーになる可能性がある。
もちろん、開発が終わったら、srmlib.dllをXPから削除する。
ちなみに、ディスククォータについてはWMIから取得できる。
コマンドラインからクラスを生成してくれるので、
かなり使いやすく構成されている。
11/5 追記
各種クラスの利用方法が不明&Windows 2003 R2で使えるか不明だったので、
簡単にまとめてみた。(MSDNからの引用だから怒られる...?)
ちなみに、このAPIを使用する場合は、Administratorアカウントもしくは、管理者権限を有するグループに所属するアカウントである必要がある。
Interface | Description | 説明 | XP,Vista,7 | 2003 | 2003 R2 | 2008 | 2008 R2 |
---|---|---|---|---|---|---|---|
IFsrmAction | Base class for all action interfaces. | アクションインターフェイスの基底クラス | No | No | Yes? | Yes | Yes |
IFsrmActionCommand | Used to run a command or script in response to a quota or file screen event. | クォータやファイルスクリーンイベントに対してのコマンドもしくはスクリプトを実行に使われます。 | No | No | Yes? | Yes | Yes |
IFsrmActionEmail | Used to send an e-mail message in response to a quota or file screen event. | クォータやファイルスクリーンイベントに対しての電子メールの送信に使われます。 | No | No | Yes? | Yes | Yes |
IFsrmActionEmail2 | Used to limit the number of expired files listed in the e-mail notification. | 電子メールで通知するファイル数を制限するのに使われます。 | No | No | No | No | Yes |
IFsrmActionEventLog | Used to log an event to the Windows Application Event Log in response to a quota or file screen event. | クォータやファイルスクリーンイベントに対してWindows イベントログのアプリケーションログへの記録に使われます。 | No | No | Yes? | Yes | Yes |
IFsrmActionReport | Used to generate a report in response to a quota or file screen event. | クォータやファイルスクリーンイベントに対してレポート出力で使われます。 | No | No | Yes? | Yes | Yes |
IFsrmAutoApplyQuota | Used to automatically apply the directory quota to new subdirectories that will be created in the specified directory. | 指定されたディレクトリのサブディレクトリに対してディレクトリクォータを自動的に適用するのに使われます。 | No | No | Yes? | Yes | Yes |
IFsrmClassificationManager | Manages file classification. | ファイル分類を管理 | No | No | No | No | Yes |
IFsrmClassificationRule | Defines a classification rule. | 分類ルールの実装 | No | No | No | No | Yes |
IFsrmClassifierModuleDefinition | Defines a classifier module. | 分類モジュールの実装 | No | No | No | No | Yes |
IFsrmClassifierModuleImplementation | Classifier modules implement this interface. FSRM calls the module's implementation when it runs classification. | このインターフェイスを使って分類モジュールを実装します。分類が実行されるときにFSRMよりこのモジュールの実装が呼び出されます。 | No | No | No | No | Yes |
IFsrmCollection | Defines a collection of FSRM objects. | FSRMオブジェクトのコレクション定義。 | No | No | Yes | Yes | Yes |
IFsrmCommittableCollection | Defines a collection of FSRM objects that can have objects added to or removed from the collection. All objects in the collection can also be committed in a single batch operation. | FSRMオブジェクトのコレクション定義で、コレクションへの追加と削除機能を持っています。1つの操作でコレクションに追加されているすべてのオブジェクトに対して操作が実行されます。 | No | No | ? | ? | ? |
IFsrmDerivedObjectsResult | Used to access the results when the source template calls the CommitAndUpdateDerived method. | ソーステンプレートがCommitAndUpdateDerivedメソッドをコールしたときに結果へのアクセスのために使われます。 | No | No | Yes? | Yes | Yes |
IFsrmExportImport | Used to export and import FSRM objects. | FSRMオブジェクトの入力・出力に使われます。 | No | No | Yes? | Yes | Yes |
IFsrmFileGroup | Used to define a group of files based on name patterns. | 命名規則に基づいたファイルグループの定義に使われます。 | No | No | Yes | Yes | Yes |
IFsrmFileGroupImported | Used to configure imported file group objects. | インポートされたファイルグループオブジェクトの設定に使われます。 | No | No | Yes? | Yes | Yes |
IFsrmFileGroupManager | Used to manage file group objects. | ファイルグループオブジェクトの管理に使われます。 | No | No | Yes | Yes | Yes |
IFsrmFileManagementJob | Defines a file management job. | ファイル管理ジョブを定義します。 | No | No | No | No | Yes |
IFsrmFileManagementJobManager | Used to manage file management jobs. | ファイル管理ジョブの管理に使われます。 | No | No | No | No | Yes |
IFsrmFileScreen | Used to configure a file screen to block the saving of files to a specified directory. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenBase | Base class for all screen interfaces. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenException | Used to configure an exception that excludes the specified files from file screen processing. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenManager | Used to manage file screen objects. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenTemplate | Used to configure templates from which new file screens can be derived. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenTemplateImported | Used to save imported file screen templates. | No | No | Yes? | Yes | Yes | |
IFsrmFileScreenTemplateManager | Used to manage file screen templates. | No | No | Yes? | Yes | Yes | |
IFsrmMutableCollection | Used to manage a collection of FSRM objects that can have objects added to or removed from the collection. | No | No | Yes? | Yes | Yes | |
IFsrmObject | Base class for all FSRM objects. | No | No | Yes | Yes | Yes | |
IFsrmPathMapper | Used to retrieve the network share paths that are mapped to a local path. | No | No | Yes | Yes | Yes | |
IFsrmPipelineModuleConnector | Creates the communication channel between FSRM and your pipeline module implementation. | No | No | No | No | Yes | |
IFsrmPipelineModuleDefinition | Defines a module that is used to classify files or store and retrieve properties from files. | No | No | No | No | Yes | |
IFsrmPipelineModuleImplementation | Classifiers and storage modules implement this interface. | No | No | No | No | Yes | |
IFsrmProperty | Defines an instance of a property. | No | No | No | No | Yes | |
IFsrmPropertyBag | Contains the classification properties for a file. | No | No | No | No | Yes | |
IFsrmPropertyCondition | Defines a property condition that the file management job uses to determine if the file is expired. | No | No | No | No | Yes | |
IFsrmPropertyDefinition | Defines a property that you want to use to classify files. | No | No | No | No | Yes | |
IFsrmQuota | Used to define a quota for a specified directory. | No | No | Yes | Yes | Yes | |
IFsrmQuotaBase | Base interface for all quota interfaces. | No | No | Yes | Yes | Yes | |
IFsrmQuotaManager | Used to manage quotas. | No | No | Yes | Yes | Yes | |
IFsrmQuotaManagerEx | Used to manage quotas, extended version. | No | No | No | No | Yes | |
IFsrmQuotaObject | Base class for the quota and automatic quota interfaces. | No | No | Yes | Yes | Yes | |
IFsrmQuotaTemplate | Used to configure templates from which new quota objects can be derived. | No | No | Yes | Yes | Yes | |
IFsrmQuotaTemplateImported | Used to modify and save imported quota templates. | No | No | Yes? | Yes | Yes | |
IFsrmQuotaTemplateManager | Used to manage quota templates. | No | No | Yes | Yes | Yes | |
IFsrmReport | Used to configure the description and filters for a single report. | No | No | Yes | Yes | Yes | |
IFsrmReportJob | Used to configure report jobs. | No | No | Yes | Yes | Yes | |
IFsrmReportManager | Used to manage report jobs. | No | No | Yes | Yes | Yes | |
IFsrmReportScheduler | Used to manage scheduled tasks for report jobs. | No | No | Yes | Yes | Yes | |
IFsrmRule | Defines a rule. | ルールを定義 | No | No | No | No | Yes |
IFsrmSetting | Used to configure FSRM. | FSRMの設定に使われます。 | No | No | Yes | Yes | Yes |
IFsrmStorageModuleDefinition | Defines a storage module that is used to read and write property values. | プロパティ値の読み書きに使われるためのストレージモジュールを定義します。 | No | No | No | No | Yes |
IFsrmStorageModuleImplementation | Storage modules implement this interface. | ストレージモジュールの基底 | No | No | No | No | Yes |
WMIではディレクトリクォータを取得できない
以下のクラスで取得を試みたが、ディスククォータのみ取得された...
- Win32_QuotaEvent
- Win32_DiskQuota
- Win32_QuotaSetting
- Win32_VolumeQuotaSetting
- Win32_VolumeUserQuota
サンプルコード
お待たせしました(?)
サンプルを提供できるようになりました。
脳内コンパイルなので、コーディング際は、実際のメソッドに従って実装してください。
Pathの引数に何を設定すればいいのかわからなかった...
空の文字列を引数に与えると、正しく取得できるから不思議。
ちなみに、実行する場合はAdministrator権限を持つユーザーでなくてはならないらしい。
クォータ一覧
IsrmQuotaManager _srmQuotaMgr = new SrmQuotaManager(); foreach (IsrmQuota _quota in _srmQuotaMgr.EnumQuotas("")) { Debug.WriteLine("対象パス: " + _quota.Path); Debug.WriteLine("使用済み: " + _quota.QuotaUsed); Debug.WriteLine("制限(バイト): " + _quota.QuotaLimit); }
なお、自動適用クォータで適用されたクォーター一覧も上記コードで表示される。
自動適用クォータ一覧
IsrmQuotaManager _srmQuotaMgr = new SrmQuotaManager(); foreach (IsrmAutoApplyQuota _autoQuota in _srmQuotaMgr.EnumAutoApplyQuotas("")) { // このパス直下のフォルダに適用される Debug.WriteLine("対象パス: " + _autoQuota.Path); Debug.WriteLine("制限(バイト): " + _autoQuota.QuotaLimit); //_autoQuota.ExcludeFolders 除外フォルダのコレクション //_autoQuota.SourceTemplateName テンプレート名。 SrmQuotaTemplateManagerのメソッドからテンプレートを取得できる }
案外、やってみればなんとかなるものだ...
*1:ファイル種別によるクォータについては言及しない