diff --git a/types/activex-diskquota/activex-diskquota-tests.ts b/types/activex-diskquota/activex-diskquota-tests.ts new file mode 100644 index 0000000000..2672b590ca --- /dev/null +++ b/types/activex-diskquota/activex-diskquota-tests.ts @@ -0,0 +1,44 @@ +const collectionToArray = (col: any) => { // tslint:disable-line no-unnecessary-generics + const results: T[] = []; + const enumerator = new Enumerator(col); + enumerator.moveFirst(); + while (!enumerator.atEnd()) { + results.push(enumerator.item()); + enumerator.moveNext(); + } + return results; +}; + +// https://msdn.microsoft.com/en-us/library/windows/desktop/bb787925(v=vs.85).aspx +(() => { + const enumUsers = (label: string) => { + const volume = new ActiveXObject('Microsoft.DiskQuota'); + volume.Initialize(label, true); + collectionToArray(volume).forEach(x => { + // Use the QuotaUser object to retrieve or set one or more of the user's disk quota properties + }); + }; +})(); + +// https://msdn.microsoft.com/en-us/library/windows/desktop/bb787916(v=vs.85).aspx +(() => { + const volume = new ActiveXObject('Microsoft.DiskQuota'); + volume.Initialize('MYDISK', true); + ActiveXObject.on(volume, 'OnUserNameChanged', ['pUser'], p => { + // Code to handle the event. + }); +})(); + +// https://msdn.microsoft.com/en-us/library/windows/desktop/bb787904(v=vs.85).aspx +(() => { + const dqc = new ActiveXObject('Microsoft.DiskQuota'); + dqc.Initialize('MYDISK', true); + const findName = (name: string) => { + try { + return dqc.FindUser(name); + } catch { } + try { + return dqc.FindUser(dqc.TranslateLogonNameToSID(name)); + } catch { } + }; +})(); diff --git a/types/activex-diskquota/index.d.ts b/types/activex-diskquota/index.d.ts new file mode 100644 index 0000000000..d27863de3c --- /dev/null +++ b/types/activex-diskquota/index.d.ts @@ -0,0 +1,152 @@ +// Type definitions for DiskQuotaTypeLibrary 1.0 +// Project: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773938(v=vs.85).aspx +// Definitions by: Zev Spitz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.5 + +declare namespace DiskQuotaTypeLibrary { + // tslint:disable-next-line no-const-enum + const enum AccountStatusConstants { + dqAcctDeleted = 2, + dqAcctInvalid = 3, + dqAcctResolved = 0, + dqAcctUnavailable = 1, + dqAcctUnknown = 4, + dqAcctUnresolved = 5, + } + + // tslint:disable-next-line no-const-enum + const enum QuotaStateConstants { + dqStateDisable = 0, + dqStateEnforce = 2, + dqStateTrack = 1, + } + + // tslint:disable-next-line no-const-enum + const enum UserNameResolutionConstants { + dqResolveAsync = 2, + dqResolveNone = 0, + dqResolveSync = 1, + } + + /** Automation interface for DiskQuotaUser */ + class DIDiskQuotaUser { + private 'DiskQuotaTypeLibrary.DIDiskQuotaUser_typekey': DIDiskQuotaUser; + private constructor(); + + /** Name of user's account container */ + readonly AccountContainerName: string; + + /** Status of user's account */ + readonly AccountStatus: AccountStatusConstants; + + /** User's display name */ + readonly DisplayName: string; + + /** Unique ID number */ + readonly ID: number; + + /** Invalidate data cached in user object */ + Invalidate(): void; + + /** User's logon account name */ + readonly LogonName: string; + + /** User's quota limit (bytes) */ + QuotaLimit: number; + + /** User's quota limit (text) */ + readonly QuotaLimitText: string; + + /** User's quota warning threshold (bytes) */ + QuotaThreshold: number; + + /** User's quota warning threshold (text) */ + readonly QuotaThresholdText: string; + + /** Quota charged to user (bytes) */ + readonly QuotaUsed: number; + + /** Quota charged to user (text) */ + readonly QuotaUsedText: string; + } + + /** Microsoft Disk Quota */ + class DiskQuotaControl { + private 'DiskQuotaTypeLibrary.DiskQuotaControl_typekey': DiskQuotaControl; + private constructor(); + + /** Add a user quota entry by Name */ + AddUser(LogonName: string): DIDiskQuotaUser; + + /** Default quota limit applied to new volume users (byte value) */ + DefaultQuotaLimit: number; + + /** Default quota limit applied to new volume users (text string) */ + readonly DefaultQuotaLimitText: string; + + /** Default warning threshold applied to new volume users (byte value) */ + DefaultQuotaThreshold: number; + + /** Default warning threshold applied to new volume users (text string) */ + readonly DefaultQuotaThresholdText: string; + + /** Delete a user quota entry */ + DeleteUser(pUser: DIDiskQuotaUser): void; + + /** Find a user quota entry by Name */ + FindUser(LogonName: string): DIDiskQuotaUser; + + /** Promote a user quota entry to the head of the name resolution queue */ + GiveUserNameResolutionPriority(pUser: DIDiskQuotaUser): void; + + /** Initialize the quota control object for a specified volume */ + Initialize(path: string, bReadWrite: boolean): void; + + /** Invalidate the cache of user name information */ + InvalidateSidNameCache(): void; + + /** Write event log entry when user exceeds quota limit */ + LogQuotaLimit: boolean; + + /** Write event log entry when user exceeds quota warning threshold */ + LogQuotaThreshold: boolean; + + /** Indicates if quota information is out of date */ + readonly QuotaFileIncomplete: boolean; + + /** Indicates if quota information is being rebuilt */ + readonly QuotaFileRebuilding: boolean; + + /** State of the volume's disk quota system */ + QuotaState: QuotaStateConstants; + + /** Terminate the user name resolution thread */ + ShutdownNameResolution(): void; + + /** Translates a user logon name to a security ID */ + TranslateLogonNameToSID(LogonName: string): string; + + /** Control the resolution of user Security IDs to user Names */ + UserNameResolution: UserNameResolutionConstants; + } +} + +interface ActiveXObject { + on( + obj: DiskQuotaTypeLibrary.DiskQuotaControl, event: 'OnUserNameChanged', argNames: ['pUser'], handler: ( + this: DiskQuotaTypeLibrary.DiskQuotaControl, parameter: {readonly pUser: DiskQuotaTypeLibrary.DIDiskQuotaUser}) => void): void; + new(progid: K): ActiveXObjectNameMap[K]; +} + +interface ActiveXObjectNameMap { + 'Microsoft.DiskQuota': DiskQuotaTypeLibrary.DiskQuotaControl; +} + +interface EnumeratorConstructor { + new(col: DiskQuotaTypeLibrary.DiskQuotaControl): Enumerator; +} + +interface SafeArray { + _brand: SafeArray; +} diff --git a/types/activex-diskquota/package.json b/types/activex-diskquota/package.json new file mode 100644 index 0000000000..d9b1031263 --- /dev/null +++ b/types/activex-diskquota/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "activex-helpers": "*" + } +} \ No newline at end of file diff --git a/types/activex-diskquota/tsconfig.json b/types/activex-diskquota/tsconfig.json new file mode 100644 index 0000000000..b7430e47f9 --- /dev/null +++ b/types/activex-diskquota/tsconfig.json @@ -0,0 +1,22 @@ + +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es5", "scripthost"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "activex-diskquota-tests.ts" + ] +} \ No newline at end of file diff --git a/types/activex-diskquota/tslint.json b/types/activex-diskquota/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/activex-diskquota/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file