Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Created August 2, 2015 02:02
Show Gist options
  • Save ArtemAvramenko/a7f761d26c8728417967 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/a7f761d26c8728417967 to your computer and use it in GitHub Desktop.
TypeScript declarations for Windows Scripting Host
// Windows Script Host APIS
// http://blogs.msdn.com/b/freik/archive/2012/10/19/goofing-around-with-typescript-amp-windows-script-host.aspx
declare var ActiveXObject: { new (s: string): any; };
interface IWScriptStringCollection {
Item(n: number): string;
Count: number;
length: number;
}
interface INamedStringCollection extends IWScriptStringCollection {
Exists: (name: string) => boolean;
}
interface IWScriptArguments extends IWScriptStringCollection {
Named: INamedStringCollection;
Unnamed: IWScriptStringCollection;
ShowUsage(): void;
}
interface IWshShortcut {
TargetPath: string;
FullName: string;
Save: () => void;
// Not used for URL Shortcuts
Arguments: IWScriptStringCollection;
// Not used for URL Shortcuts
Description: string;
// Not used for URL Shortcuts
Hotkey: string;
// Not used for URL Shortcuts
IconLocation: string;
// Not used for URL Shortcuts
WindowStyle: number;
// Not used for URL Shortcuts
WorkingDirectory: string;
}
interface IWScriptExec {
Status: number;
StdErr: TextStreamWriter;
StdOut: TextStreamWriter;
StdIn: TextStreamReader;
Terminate: () => void;
}
interface WshShell {
CurrentDirectory: string;
Environment: (envContext?: string) => IWScriptStringCollection;
SpecialFolders: (folderName: string) => string;
AppActivate: (title: string) => void;
CreateShortcut: (pathname: string) => IWshShortcut;
ExpandEnvironmentStrings: (envString: string) => string;
LogEvent: (type: number, message: string, target?: string) => boolean;
Popup: (text: string, secondsToWait?: number, title?: string, buttonType?: number) => number;
RegDelete: (name: string) => void;
RegRead: (name: string) => any;
RegWrite: (name: string, value: any, type?: string) => void;
SendKeys: (keys: string) => void;
Run: (command: string, windowsStyle?: number, waitOnReturn?: boolean) => number;
Exec: (command: string) => IWScriptExec;
}
interface WshNetwork {
ComputerName: string;
UserDomain: string;
UserName: string;
EnumerateNetworkDrives: () => IWScriptStringCollection;
MapNetworkDrive: (localName: string, remoteName: string, updateProfile?: boolean, user?: string, password?: string) => void;
RemoveNetworkDrive: (localName: string, force?: boolean, updateProfile?: boolean) => void;
}
interface WshRemoteError {
Description: string;
Line: number;
Character: number;
SourceText: string;
Source: string;
Number: number;
}
interface WshRemote {
Status: number;
Error: WshRemoteError;
Execute: () => void;
Terminate: () => void;
}
interface WshController {
CreateScript: (commandLine: string, machineName?: string) => WshRemote;
}
// FileSystemObject
interface IFSODrive {
AvailableSpace: number;
DriveLetter: string;
DriveType: number;
FileSystem: string;
FreeSpace: number;
IsReady: boolean;
Path: string;
RootFolder: string;
SerialNumber: string;
ShareName: string;
TotalSize: number;
VolumeName: string;
}
interface IFSOTextStream extends TextStreamWriter, TextStreamReader { }
interface IFSOFileSystemItem {
Copy: (dest: string, overwrite?: boolean) => void;
Delete: (force?: boolean) => void;
Move: (dest: string) => void;
Attributes: number;
DateCreated: Date;
DateLastAccessed: Date;
DateLastModified: Date;
Drive: IFSODrive;
Name: string;
Path: string;
ShortName: string;
ShortPath: string;
Size: number;
Type: string;
ParentFolder: IFSOFolder;
}
interface IFSOFileSystemCollection {
atEnd: () => boolean;
moveNext: () => void;
Count: number;
}
interface IFSOFileCollection {
item: () => IFSOFile;
}
interface IFSOFolderCollection {
item: () => IFSOFolder;
}
interface IFSODriveCollection {
item: () => IFSODrive;
}
interface IFSOFolder extends IFSOFileSystemItem {
Files: IFSOFileCollection;
SubFolders: IFSOFolderCollection;
IsRootFolder: boolean;
}
interface IFSOFile extends IFSOFileSystemItem {
OpenAsTextStream: (iomode?: number, format?: number) => IFSOTextStream;
Type: string;
}
interface IFileSystemObject {
Drives: IFSODriveCollection;
BuildPath: (path: string, name: string) => string;
CopyFile: (source: string, dest: string, overwrite?: boolean) => void;
CreateFolder: (name: string) => IFSOFolder;
CreateTextFile: (fileName: string, overwrite?: boolean, unicode?: boolean) => IFSOTextStream;
DeleteFile: (filespec: string, force?: boolean) => void;
DeleteFolder: (folderspec: string, force?: boolean) => void;
DriveExists: (driveOrPathSpec: string) => boolean;
FileExists: (fileSpec: string) => boolean;
FolderExists: (folderSpec: string) => boolean;
GetAbsolutePathName: (relPath: string) => string;
GetBaseName: (filename: string) => string;
GetDrive: (driveSpec: string) => IFSODrive;
GetDriveName: (fullPath: string) => string;
GetExtension: (path: string) => string;
GetFile: (filePath: string) => IFSOFile;
GetFileVersion: (filePath: string) => string;
GetFileName: (fileSpec: string) => string;
GetFolder: (fldrSpec: string) => IFSOFolder;
GetParentFolderName: (path: string) => string;
GetSpecialFolder: (which: number) => IFSOFolder;
GetTempName: () => string;
MoveFile: (sourceSpec: string, dest: string) => void;
MoveFolder: (sourceSpec: string, dest: string) => void;
OpenTextFile: (path: string, iomode?: number, create?: boolean, format?: number) => IFSOTextStream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment