Updated existing activex definitions

This commit is contained in:
Zev Spitz
2017-06-25 23:03:34 +02:00
parent ef795c7ceb
commit ed48fab28e
18 changed files with 1598 additions and 756 deletions

View File

@@ -0,0 +1,64 @@
//source -- https://msdn.microsoft.com/en-us/library/ebkhfaaz.aspx
//Generates a string describing the drive type of a given Drive object.
var showDriveType = (drive: Scripting.Drive) => {
switch (drive.DriveType) {
case Scripting.DriveTypeConst.Removable:
return 'Removeable';
case Scripting.DriveTypeConst.Fixed:
return 'Fixecd';
case Scripting.DriveTypeConst.Remote:
return 'Network';
case Scripting.DriveTypeConst.CDRom:
return 'CD-ROM';
case Scripting.DriveTypeConst.RamDisk:
return 'RAM Disk';
default:
return 'Unknown';
}
};
//Generates a string describing the attributes of a file or folder.
var showFileAttributes = (file: Scripting.File) => {
var attr = file.Attributes;
if (attr === 0) {
return 'Normal';
}
var attributeStrings: string[] = [];
if (attr & Scripting.FileAttribute.Directory) { attributeStrings.push('Directory'); }
if (attr & Scripting.FileAttribute.ReadOnly) { attributeStrings.push('Read-only'); }
if (attr & Scripting.FileAttribute.Hidden) { attributeStrings.push('Hidden'); }
if (attr & Scripting.FileAttribute.System) { attributeStrings.push('System'); }
if (attr & Scripting.FileAttribute.Volume) { attributeStrings.push('Volume'); }
if (attr & Scripting.FileAttribute.Archive) { attributeStrings.push('Archive'); }
if (attr & Scripting.FileAttribute.Alias) { attributeStrings.push('Alias'); }
if (attr & Scripting.FileAttribute.Compressed) { attributeStrings.push('Compressed'); }
return attributeStrings.join(',');
};
//source --https://msdn.microsoft.com/en-us/library/ts2t8ybh(v=vs.84).aspx
var showFreeSpace = (drvPath: string) => {
var fso = new ActiveXObject('Scripting.FileSystemObject');
var d = fso.GetDrive(fso.GetDriveName(drvPath));
var s = 'Drive ' + drvPath + ' - ';
s += d.VolumeName + '<br>';
s += 'Free Space: ' + d.FreeSpace / 1024 + ' Kbytes';
return (s);
};
//source -- https://msdn.microsoft.com/en-us/library/kaf6yaft(v=vs.84).aspx
var getALine = (filespec: string) => {
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.OpenTextFile(filespec, Scripting.IOMode.ForReading, false);
var s = '';
while (!file.AtEndOfLine) {
s += file.Read(1);
}
file.Close();
return (s);
};

View File

@@ -0,0 +1,64 @@
//source -- https://msdn.microsoft.com/en-us/library/ebkhfaaz.aspx
//Generates a string describing the drive type of a given Drive object.
var showDriveType = (drive: Scripting.Drive) => {
switch (drive.DriveType) {
case Scripting.DriveTypeConst.Removable:
return 'Removeable';
case Scripting.DriveTypeConst.Fixed:
return 'Fixecd';
case Scripting.DriveTypeConst.Remote:
return 'Network';
case Scripting.DriveTypeConst.CDRom:
return 'CD-ROM';
case Scripting.DriveTypeConst.RamDisk:
return 'RAM Disk';
default:
return 'Unknown';
}
};
//Generates a string describing the attributes of a file or folder.
var showFileAttributes = (file: Scripting.File) => {
var attr = file.Attributes;
if (attr === 0) {
return 'Normal';
}
var attributeStrings: string[] = [];
if (attr & Scripting.FileAttribute.Directory) { attributeStrings.push('Directory'); }
if (attr & Scripting.FileAttribute.ReadOnly) { attributeStrings.push('Read-only'); }
if (attr & Scripting.FileAttribute.Hidden) { attributeStrings.push('Hidden'); }
if (attr & Scripting.FileAttribute.System) { attributeStrings.push('System'); }
if (attr & Scripting.FileAttribute.Volume) { attributeStrings.push('Volume'); }
if (attr & Scripting.FileAttribute.Archive) { attributeStrings.push('Archive'); }
if (attr & Scripting.FileAttribute.Alias) { attributeStrings.push('Alias'); }
if (attr & Scripting.FileAttribute.Compressed) { attributeStrings.push('Compressed'); }
return attributeStrings.join(',');
};
//source --https://msdn.microsoft.com/en-us/library/ts2t8ybh(v=vs.84).aspx
var showFreeSpace = (drvPath: string) => {
var fso = new ActiveXObject('Scripting.FileSystemObject');
var d = fso.GetDrive(fso.GetDriveName(drvPath));
var s = 'Drive ' + drvPath + ' - ';
s += d.VolumeName + '<br>';
s += 'Free Space: ' + d.FreeSpace / 1024 + ' Kbytes';
return (s);
};
//source -- https://msdn.microsoft.com/en-us/library/kaf6yaft(v=vs.84).aspx
var getALine = (filespec: string) => {
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.OpenTextFile(filespec, Scripting.IOMode.ForReading, false);
var s = '';
while (!file.AtEndOfLine) {
s += file.Read(1);
}
file.Close();
return (s);
};

513
types/activex-scripting/index.d.ts vendored Normal file
View File

@@ -0,0 +1,513 @@
// Type definitions for Scripting -
// Project: https://msdn.microsoft.com/en-us/library/bstcxhf7.aspx
// Defintions by: Zev Spitz <https://github.com/zspitz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace Scripting {
//Enums
const enum __MIDL___MIDL_itf_scrrun_0000_0000_0001 {
Alias = 1024,
Archive = 32,
Compressed = 2048,
Directory = 16,
Hidden = 2,
Normal = 0,
ReadOnly = 1,
System = 4,
Volume = 8
}
const enum __MIDL___MIDL_itf_scrrun_0001_0001_0001 {
CDRom = 4,
Fixed = 2,
RamDisk = 5,
Remote = 3,
Removable = 1,
UnknownType = 0
}
const enum __MIDL___MIDL_itf_scrrun_0001_0001_0002 {
SystemFolder = 1,
TemporaryFolder = 2,
WindowsFolder = 0
}
const enum __MIDL___MIDL_itf_scrrun_0001_0001_0003 {
StdErr = 2,
StdIn = 0,
StdOut = 1
}
const enum CompareMethod {
BinaryCompare = 0,
DatabaseCompare = 2,
TextCompare = 1
}
const enum DriveTypeConst {
CDRom = 4,
Fixed = 2,
RamDisk = 5,
Remote = 3,
Removable = 1,
UnknownType = 0
}
const enum FileAttribute {
Alias = 1024,
Archive = 32,
Compressed = 2048,
Directory = 16,
Hidden = 2,
Normal = 0,
ReadOnly = 1,
System = 4,
Volume = 8
}
const enum IOMode {
ForAppending = 8,
ForReading = 1,
ForWriting = 2
}
const enum SpecialFolderConst {
SystemFolder = 1,
TemporaryFolder = 2,
WindowsFolder = 0
}
const enum StandardStreamTypes {
StdErr = 2,
StdIn = 0,
StdOut = 1
}
const enum Tristate {
TristateFalse = 0,
TristateMixed = -2,
TristateTrue = -1,
TristateUseDefault = -2
}
//Interfaces
/** Scripting.Dictionary */
interface Dictionary {
/** Add a new key and item to the dictionary. */
Add(Key: any, Item: any): void;
/** Set or get the string comparison method. */
CompareMode: CompareMethod;
/** Get the number of items in the dictionary. */
readonly Count: number;
/** Determine if a given key is in the dictionary. */
Exists(Key: any): boolean;
HashVal(Key: any): any;
/** Set or get the item for a given key */
Item(Key: any): any;
/** Get an array containing all items in the dictionary. */
Items(): any;
/** Change a key to a different key. */
Key(Key: any): any;
/** Get an array containing all keys in the dictionary. */
Keys(): any;
/** Remove a given key from the dictionary. */
Remove(Key: any): void;
/** Remove all information from the dictionary. */
RemoveAll(): void;
}
/** Drive Object */
interface Drive {
/** Get available space */
readonly AvailableSpace: any;
/** Drive letter */
readonly DriveLetter: string;
/** Drive type */
readonly DriveType: DriveTypeConst;
/** Filesystem type */
readonly FileSystem: string;
/** Get drive free space */
readonly FreeSpace: any;
/** Check if disk is available */
readonly IsReady: boolean;
/** Path */
readonly Path: string;
/** Root folder */
readonly RootFolder: Folder;
/** Serial number */
readonly SerialNumber: number;
/** Share name */
readonly ShareName: string;
/** Get total drive size */
readonly TotalSize: any;
/** Name of volume */
VolumeName: string;
}
/** Collection of drives associated with drive letters */
interface Drives {
/** Number of drives */
readonly Count: number;
/** Get drive */
Item(Key: any): Drive;
}
/** Script Encoder Object */
interface Encoder {
/** Call the Encoder determined by szExt, passing bstrStreamIn and optional arguments */
EncodeScriptFile(szExt: string, bstrStreamIn: string, cFlags: number, bstrDefaultLang: string): string;
}
/** File object */
interface File {
/** File attributes */
Attributes: FileAttribute;
/**
* Copy this file
* @param boolean [OverWriteFiles=true]
*/
Copy(Destination: string, OverWriteFiles?: boolean): void;
/** Date file was created */
readonly DateCreated: VarDate;
/** Date file was last accessed */
readonly DateLastAccessed: VarDate;
/** Date file was last modified */
readonly DateLastModified: VarDate;
/**
* Delete this file
* @param boolean [Force=false]
*/
Delete(Force?: boolean): void;
/** Get drive that contains file */
readonly Drive: Drive;
/** Move this file */
Move(Destination: string): void;
/** Get name of file */
Name: string;
/**
* Open a file as a TextStream
* @param Scripting.IOMode [IOMode=1]
* @param Scripting.Tristate [Format=0]
*/
OpenAsTextStream(IOMode?: IOMode, Format?: Tristate): TextStream;
/** Get folder that contains file */
readonly ParentFolder: Folder;
/** Path to the file */
readonly Path: string;
/** Short name */
readonly ShortName: string;
/** Short path */
readonly ShortPath: string;
/** File size */
readonly Size: any;
/** Type description */
readonly Type: string;
}
/** Collection of files in a folder */
interface Files {
/** Number of folders */
readonly Count: number;
/** Get file */
Item(Key: any): File;
}
/** FileSystem Object */
interface FileSystemObject {
/** Generate a path from an existing path and a name */
BuildPath(Path: string, Name: string): string;
/**
* Copy a file
* @param boolean [OverWriteFiles=true]
*/
CopyFile(Source: string, Destination: string, OverWriteFiles?: boolean): void;
/**
* Copy a folder
* @param boolean [OverWriteFiles=true]
*/
CopyFolder(Source: string, Destination: string, OverWriteFiles?: boolean): void;
/** Create a folder */
CreateFolder(Path: string): Folder;
/**
* Create a file as a TextStream
* @param boolean [Overwrite=true]
* @param boolean [Unicode=false]
*/
CreateTextFile(FileName: string, Overwrite?: boolean, Unicode?: boolean): TextStream;
/**
* Delete a file
* @param boolean [Force=false]
*/
DeleteFile(FileSpec: string, Force?: boolean): void;
/**
* Delete a folder
* @param boolean [Force=false]
*/
DeleteFolder(FolderSpec: string, Force?: boolean): void;
/** Check if a drive or a share exists */
DriveExists(DriveSpec: string): boolean;
/** Get drives collection */
readonly Drives: Drives;
/** Check if a file exists */
FileExists(FileSpec: string): boolean;
/** Check if a path exists */
FolderExists(FolderSpec: string): boolean;
/** Return the canonical representation of the path */
GetAbsolutePathName(Path: string): string;
/** Return base name from a path */
GetBaseName(Path: string): string;
/** Get drive or UNC share */
GetDrive(DriveSpec: string): Drive;
/** Return drive from a path */
GetDriveName(Path: string): string;
/** Return extension from path */
GetExtensionName(Path: string): string;
/** Get file */
GetFile(FilePath: string): File;
/** Return the file name from a path */
GetFileName(Path: string): string;
/** Retrieve the file version of the specified file into a string */
GetFileVersion(FileName: string): string;
/** Get folder */
GetFolder(FolderPath: string): Folder;
/** Return path to the parent folder */
GetParentFolderName(Path: string): string;
/** Get location of various system folders */
GetSpecialFolder(SpecialFolder: SpecialFolderConst): Folder;
/**
* Retrieve the standard input, output or error stream
* @param boolean [Unicode=false]
*/
GetStandardStream(StandardStreamType: StandardStreamTypes, Unicode?: boolean): TextStream;
/** Generate name that can be used to name a temporary file */
GetTempName(): string;
/** Move a file */
MoveFile(Source: string, Destination: string): void;
/** Move a folder */
MoveFolder(Source: string, Destination: string): void;
/**
* Open a file as a TextStream
* @param Scripting.IOMode [IOMode=1]
* @param boolean [Create=false]
* @param Scripting.Tristate [Format=0]
*/
OpenTextFile(FileName: string, IOMode?: IOMode, Create?: boolean, Format?: Tristate): TextStream;
}
/** Folder object */
interface Folder {
/** Folder attributes */
Attributes: FileAttribute;
/**
* Copy this folder
* @param boolean [OverWriteFiles=true]
*/
Copy(Destination: string, OverWriteFiles?: boolean): void;
/**
* Create a file as a TextStream
* @param boolean [Overwrite=true]
* @param boolean [Unicode=false]
*/
CreateTextFile(FileName: string, Overwrite?: boolean, Unicode?: boolean): TextStream;
/** Date folder was created */
readonly DateCreated: VarDate;
/** Date folder was last accessed */
readonly DateLastAccessed: VarDate;
/** Date folder was last modified */
readonly DateLastModified: VarDate;
/**
* Delete this folder
* @param boolean [Force=false]
*/
Delete(Force?: boolean): void;
/** Get drive that contains folder */
readonly Drive: Drive;
/** Get files collection */
readonly Files: Files;
/** True if folder is root */
readonly IsRootFolder: boolean;
/** Move this folder */
Move(Destination: string): void;
/** Get name of folder */
Name: string;
/** Get parent folder */
readonly ParentFolder: Folder;
/** Path to folder */
readonly Path: string;
/** Short name */
readonly ShortName: string;
/** Short path */
readonly ShortPath: string;
/** Sum of files and subfolders */
readonly Size: any;
/** Get folders collection */
readonly SubFolders: Folders;
/** Type description */
readonly Type: string;
}
/** Collection of subfolders in a folder */
interface Folders {
/** Create a new folder */
Add(Name: string): Folder;
/** Number of folders */
readonly Count: number;
/** Get folder */
Item(Key: any): Folder;
}
/** TextStream object */
interface TextStream {
/** Is the current position at the end of a line? */
readonly AtEndOfLine: boolean;
/** Is the current position at the end of the stream? */
readonly AtEndOfStream: boolean;
/** Close a text stream */
Close(): void;
/** Current column number */
readonly Column: number;
/** Current line number */
readonly Line: number;
/** Read a specific number of characters into a string */
Read(Characters: number): string;
/** Read the entire stream into a string */
ReadAll(): string;
/** Read an entire line into a string */
ReadLine(): string;
/** Skip a specific number of characters */
Skip(Characters: number): void;
/** Skip a line */
SkipLine(): void;
/** Write a string to the stream */
Write(Text: string): void;
/** Write a number of blank lines to the stream */
WriteBlankLines(Lines: number): void;
/**
* Write a string and an end of line to the stream
* @param string [Text='']
*/
WriteLine(Text?: string): void;
}
}
//Global interfaces
interface ActiveXObject {
set(obj: Scripting.Dictionary, propertyName: 'Item', parameterTypes: [any], newValue: any): void;
new(progid: 'Scripting.Dictionary'): Scripting.Dictionary;
new(progid: 'Scripting.Encoder'): Scripting.Encoder;
new(progid: 'Scripting.FileSystemObject'): Scripting.FileSystemObject;
}
interface EnumeratorConstructor {
new(col: Scripting.Dictionary): any;
new(col: Scripting.Drives): Scripting.Drive;
new(col: Scripting.Files): Scripting.File;
new(col: Scripting.Folders): Scripting.Folder;
}

View File

@@ -0,0 +1 @@
{ "dependencies": { "activex-helpers": "*"}}

View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["scripthost"],
"strict": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"activex-scripting-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint / dt.json" }