This module takes charge of basis handling Windows OS (Partly similar to Node.js-OS).
Requires
Namespaces
Members
(static, constant) envVars :object
Windows Environment Variables. Wsh.OS.getEnvVars
execution result and the referer of process.env
.
Type:
- object
Example
console.dir(Wsh.OS.envVars);
// Outputs: {
// ALLUSERSPROFILE: "C:\ProgramData",
// APPDATA: "C:\Users\UserName\AppData\Roaming",
// CommonProgramFiles: "C:\Program Files\Common Files",
// CommonProgramFiles(x86): "C:\Program Files (x86)\Common Files",
// CommonProgramW6432: "C:\Program Files\Common Files",
// COMPUTERNAME: "MYPC0123",
// ComSpec: "C:\WINDOWS\system32\cmd.exe",
// HOMEDRIVE: "C:",
// HOMEPATH: "\Users\UserName",
// ... }
(static, constant) EOL :string
Windows system-specific end-of-line marker. Similar to Node.js os.eol.
Type:
- string
Example
Wsh.OS.EOL; // Returns: '\r\n'
Methods
(static) activateProcess(processName, optionsopt) → {number}
- Source:
Activates the specified processes. AppActivate
Example
Wsh.OS.activateProcess('Code.exe');
// Returns: 18321
Wsh.OS.activateProcess('C:\\Windows\\System32\\cmd.exe');
// Returns: 12591
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
processName |
number | string | The PID or process name or full path. |
|
options |
typeGetProcessesOptions |
<optional> |
Optional parameters. |
Returns:
- The process ID to be activated.
- Type
- number
(static) addUser(userName, password) → {void}
- Source:
Adds the new user in this local Windows.
Example
Wsh.OS.addUser('MyUserName', 'mY-P@ss');
Parameters:
Name | Type | Description |
---|---|---|
userName |
string | The user name to add. |
password |
string | The user's password. |
Throws:
-
- If an error occurs during command execution, or if the command exits with a value other than 0.
- Type
- string
Returns:
- Type
- void
(static) arch() → {string}
Returns the operating system CPU architecture. Similar to Node.js os.arch().
Example
Wsh.OS.arch(); // Returns: 'amd64'
Returns:
- The operating system CPU architecture.
- Type
- string
(static) assignDriveLetter(dirPath, letteropt, userNameopt, passwordopt) → {string}
- Source:
Assigns the drive letter to the directory.
Example
var assignLetter = Wsh.OS.assignDriveLetter; // Shorthand
assignLetter('C:\\My Data', 'X');
// Return 'X'
assignLetter('\\\\MyNAS\\MultiMedia', 'M', 'myname', 'mY-p@ss');
// Return 'M'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dirPath |
string | The path of directory to assign. |
|
letter |
string |
<optional> |
The drive letter. |
userName |
string |
<optional> |
The user name. |
password |
string |
<optional> |
The password. |
Returns:
- The assigned letter.
- Type
- string
(static) attachAdminAuthorityToUser(userName) → {void}
- Source:
Adds the administrator authority to the user.
Example
Wsh.OS.attachAdminAuthorityToUser('MyUserName');
Parameters:
Name | Type | Description |
---|---|---|
userName |
string | The user name to add administrator authority. |
Throws:
-
- If an error occurs during command execution, or if the command exits with a value other than 0.
- Type
- string
Returns:
- Type
- void
(static) cmdCodeset() → {string}
Returns the chara-code of CommandPrompt on this Windows.
Example
Wsh.OS.cmdCodeset(); // Returns: 'shift_jis'
Returns:
- The code page value an operating system uses. See CodeSet.
- Type
- string
(static) convToCmdlineStr(cmdStr, argsopt, optionsopt) → {string}
Converts the command and arguments to a command line string.
Example
var os = Wsh.OS;
os.convToCmdlineStr('net', ['use', '/delete']);
// Returns: 'net user /delete'
os.convToCmdlineStr('net', ['use', '/delete'], { shell: true });
// Returns: 'C:\Windows\System32\cmd.exe /S /C"net user /delete"'
os.convToCmdlineStr('net', 'use /delete', { shell: true, closes: false });
// Returns: 'C:\Windows\System32\cmd.exe /S /K"net user /delete"'
// The 2nd argument: Array vs String
// Array is escaped
os.convToCmdlineStr('D:\\My Apps\\app.exe',
['/RegExp="^(A|The) $"', '-f', 'C:\\My Data\\img.doc']);
// Returns: '"D:\\My Apps\\app.exe" "/RegExp=\\"^^(A^|The) $\\"" -f "C:\\My Data\\img.doc"'
// String is not escaped
os.convToCmdlineStr('D:\\My Apps\\app.exe',
'/RegExp="^(A|The) $" -f C:\\My Data\\img.doc');
// Returns: '/RegExp="^(A|The) $" -f C:\\My Data\\img.doc'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments to format. |
options |
typeConvToCommandOptions |
<optional> |
Optional parameters. |
Returns:
- The converted command.
- Type
- string
(static) deleteUser(userName) → {void}
- Source:
Delete the user in this local Windows.
Example
Wsh.OS.deleteUser('MyUserName');
Parameters:
Name | Type | Description |
---|---|---|
userName |
string | The user name to add. |
Throws:
-
- If an error occurs during command execution, or if the command exits with a value other than 0.
- Type
- string
Returns:
- Type
- void
(static) escapeForCmd(str) → {string}
Example
var os = Wsh.OS; // Shorthand
os.escapeForCmd('tag=R&B'); // Returns: 'tag=R^&B'
os.escapeForCmd('>');
// Returns: '>' // Not escaped. It's a redirect character.
os.escapeForCmd('/RegExp="^(A|The) $"');
// Returns: '"/RegExp=\\"^^(A^|The) $\\""'
os.escapeForCmd('<%^[yyyy|yy]-MM-DD%>');
// Returns: '^<%^^[yyyy^|yy]-MM-DD%^>'
os.escapeForCmd(300);
// Returns: '300'
os.escapeForCmd('C:\\Program Files');
// Returns: 'C:\\Program Files');
os.escapeForCmd('C:\\Windows\\System32\\notepad.exe');
// Returns: 'C:\\Windows\\System32\\notepad.exe'
os.escapeForCmd('"C:\\Program Files (x86)\\Windows NT"');
// Returns: '\\"C:\\Program Files (x86)\\Windows NT\\"'
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string to convert. |
Returns:
- The string escaped for Command-Prompt.
- Type
- string
(static) exec(cmdStr, argsopt, optionsopt) → {typeExecObject|string}
Asynchronously executes the command with WScript.Shell.Exec. Note that a DOS window is always displayed. WshScriptExec object
Example
var os = Wsh.OS;
// Ex.1 CMD-command
// Throws a Error. `mkdir` is the CMD command
os.shExec('mkdir', 'D:\\Temp');
// With the `shell` option
var oExec1 = os.shExec('mkdir', 'D:\\Temp1', { shell: true });
console.log(oExec1.ExitCode); // 0 (always)
while (oExec1.Status == 0) WScript.Sleep(300); // Waiting the finished
console.log(oExec1.Status); // 1 (It means finished)
fso.FolderExists('D:\\Temp1'); // Returns: true
// Ex.2 Exe-file
var oExec2 = os.shExec('ping.exe', ['127.0.0.1']);
console.log(oExec2.ExitCode); // 0 (always)
while (oExec2.Status == 0) WScript.Sleep(300); // Waiting the finished
console.log(oExec2.Status); // 1 (It means finished)
var result = oExec2.StdOut.ReadAll();
console.log(result); // Outputs the result of ping 127.0.0.1
// Ex.3 Dry Run
var cmd = os.shExec('mkdir', 'D:\\Temp3', { shell: true, isDryRun: true });
console.log(cmd);
// Outputs:
// dry-run [os.shExec]: C:\Windows\System32\cmd.exe /S /C"mkdir D:\Temp3"
fso.FolderExists('D:\\Temp3'); // Returns: false
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments. |
options |
typeOsExecOptions |
<optional> |
Optional parameters. |
Returns:
- If options.isDryRun is true, returns string.
- Type
- typeExecObject | string
(static) execSync(cmdStr, argsopt, optionsopt) → {typeExecSyncReturn|string}
Synchronize of Wsh.OS.shExec
Example
var os = Wsh.OS;
// Ex1. CMD-command
// Throws a Error. `mkdir` is the CMD command
os.shExecSync('mkdir', 'D:\\Temp');
// With the `shell` option
var retObj1 = os.shExecSync('mkdir', 'D:\\Temp', { shell: true });
console.dir(retObj1);
// Outputs: {
// exitCode: 0,
// stdout: "",
// stderr: "",
// error: false };
// Ex2. Exe-file
var retObj2 = os.shExecSync('ping.exe', ['127.0.0.1']);
console.dir(retObj2);
// Outputs: {
// exitCode: 0,
// stdout: <The result of ping 127.0.0.1>,
// stderr: "",
// error: false };
// Ex.3 Dry Run
var cmd = os.shExecSync('ping.exe', '127.0.0.1', { isDryRun: true });
console.log(cmd);
// Outputs:
// dry-run [os.shExecSync]: C:\Windows\System32\cmd.exe /S /C"C:\Windows\System32\PING.EXE 127.0.0.1"
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments. |
options |
typeOsExecOptions |
<optional> |
Optional parameters. |
Returns:
- If options.isDryRun is true, returns string.
- Type
- typeExecSyncReturn | string
(static) freemem() → {number}
Returns the amount of free system memory in bytes as an integer. Similar to Node.js os.freemem().
Example
Wsh.OS.freemem(); // Returns: 176822642
Returns:
- The amount of free system memory in bytes as an integer.
- Type
- number
(static) getDrivesInfo() → {Array}
- Source:
Gets the Drives-collection of all Drive objects available on the local machine. See Drives property and Wsh.Constants.driveTypes.}
Example
Wsh.OS.getDrivesInfo();
// Returns: [
// 0: {
// letter: "C",
// name: "Windows",
// type: 2
// },
// 1: {
// letter: "D",
// name: "BackUp",
// type: 2
// },
// 2: {
// letter: "Q",
// name: "CD-ROM",
// type: 4
// },
// 3: {
// letter: "S",
// name: "microSD",
// type: 1
// } ]
Returns:
- The drive info.
- Type
- Array
(static) getEnvVars() → {object}
Returns Windows Environment Variables. The execution result of this function is already stored in the global variable Wsh.OS.envVars
.
Example
Wsh.OS.getEnvVars();
// Returns: {
// ALLUSERSPROFILE: "C:\ProgramData",
// APPDATA: "C:\Users\UserName\AppData\Roaming",
// CommonProgramFiles: "C:\Program Files\Common Files",
// CommonProgramFiles(x86): "C:\Program Files (x86)\Common Files",
// CommonProgramW6432: "C:\Program Files\Common Files",
// COMPUTERNAME: "MYPC0123",
// ComSpec: "C:\WINDOWS\system32\cmd.exe",
// HOMEDRIVE: "C:",
// HOMEPATH: "\Users\UserName",
// ... }
Returns:
- Windows Environment Variables.
- Type
- object
(static) getHardDriveLetters() → {Array}
- Source:
Gets the Drives-collection of all Hard-Drive objects available on the local machine.
Example
Wsh.OS.getHardDriveLetters();
// Returns: [
// 0: {
// letter: "C",
// name: "Windows",
// type: 2
// },
// 1: {
// letter: "D",
// name: "BackUp",
// type: 2
// } ]
Returns:
- The Hard-drives info.
- Type
- Array
(static) getProcessIDs(processName, optionsopt) → {Array}
- Source:
Gets processes IDs that the specified process string.
Example
var getPIDs = Wsh.OS.getProcessIDs; // Shorthand
var pIDs = getPIDs('Chrome.exe');
// Returns: [33221, 22044, 43113, 42292, 17412]
var pIDs = getPIDs('C:\\Program Files\\Git\\bin\\git.exe');
// Returns: [1732, 4316]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
processName |
number | string | The PID or process name or full path. |
|
options |
typeGetProcessesOptions |
<optional> |
Optional parameters. |
Returns:
- The Array of processes ID.
- Type
- Array
(static) getProcessObj(processName, optionsopt) → {object|null}
- Source:
Gets an Object matching the specified process ID or string.
Example
var getProcessObj = Wsh.OS.getProcessObj; // Shorthand
var pObj = getProcessObj('wscript.exe');
// Returns: {
// Caption: 'wscript.exe',
// CommandLine: 'C:\\Windows\\System32\\wscript.exe //nologo C:\\MockGUI.wsf',
// CreationClassName: 'Win32_Process',
// CreationDate: '20200628110828.532484+540',
// CSCreationClassName: 'Win32_ComputerSystem',
// CSName: 'MYCOMPNAME',
// Description: 'wscript.exe',
// ExecutablePath: 'C:\\Windows\\System32\\wscript.exe',
// ExecutionState: null,
// Handle: '5678',
// HandleCount: 241,
// InstallDate: null,
// KernelModeTime: '312500',
// MaximumWorkingSetSize: 1380,
// MinimumWorkingSetSize: 200,
// Name: 'wscript.exe',
// OSCreationClassName: 'Win32_OperatingSystem',
// OSName: 'Microsoft Windows 10 Pro|C:\\WINDOWS|\\Device\\Harddisk0\\Partition4',
// OtherOperationCount: '123',
// OtherTransferCount: '4567',
// PageFaults: 3462,
// PageFileUsage: 3260,
// ParentProcessId: 12628,
// PeakPageFileUsage: 3504,
// PeakVirtualSize: '2203497648128',
// PeakWorkingSetSize: 12892,
// Priority: 8,
// PrivatePageCount: '3338240',
// ProcessId: 7580,
// QuotaNonPagedPoolUsage: 15,
// QuotaPagedPoolUsage: 267,
// QuotaPeakNonPagedPoolUsage: 15,
// QuotaPeakPagedPoolUsage: 267,
// ReadOperationCount: '45',
// ReadTransferCount: '4631',
// SessionId: 1,
// Status: null,
// TerminationDate: null,
// ThreadCount: 11,
// UserModeTime: '0',
// VirtualSize: '2203497648128',
// WindowsVersion: '10.0.12345',
// WorkingSetSize: '13164544',
// WriteOperationCount: '0',
// WriteTransferCount: '0' }
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
processName |
number | string | The PID or process name or full path. |
|
options |
typeGetProcessesOptions |
<optional> |
Optional parameters. |
Returns:
- The Object of the process.
- Type
- object | null
(static) getProcessObjs(processName, optionsopt) → {Array.<object>}
- Source:
Gets an Array of objects matching the specified process ID or string.
Example
var getProcessObjs = Wsh.OS.getProcessObjs; // Shorthand
var pObjs = getProcessObjs('chrome.exe');
// Returns: [
// {
// Caption: 'chrome.exe',
// CommandLine: ...
// ...
// }, {
// Caption: 'chrome.exe',
// CommandLine: ...
// ...
// }, {
// Caption: 'chrome.exe',
// CommandLine: ...
// ...
// }]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
processName |
number | string | The PID or process name or full path. |
|
options |
typeGetProcessesOptions |
<optional> |
Optional parameters. |
Returns:
- The Array of objects of the process.
- Type
- Array.<object>
(static) getStrFromClipboard() → {string}
[Experimental] Gets the string from Clipboard.
Returns:
- Type
- string
(static) getTheLastFreeDriveLetter() → {string}
- Source:
Gets the last Drive-letter to be able to assign.
Example
Wsh.OS.getTheLastFreeDriveLetter(); // Returns: 'Y'
Returns:
- The last drive letter to be able to assign.
- Type
- string
(static) getThisParentProcessID() → {number}
- Source:
Gets the parent-process ID of this process.
Example
Wsh.OS.getThisParentProcessID();
// Returns: 5277
Returns:
- The parent process ID.
- Type
- number
(static) getThisProcessID() → {number}
- Source:
Gets this process ID.
Example
Wsh.OS.getThisProcessID();
// Returns: 18321 (PID of cscript.exe or wscript.exe)
Returns:
- This process ID.
- Type
- number
(static) hasUAC() → {boolean}
Checks whether or not that this Windows have UAC
Example
Wsh.OS.hasUAC(); // Returns: true
Returns:
- If having UAC returns true.
- Type
- boolean
(static) homedir() → {string}
Returns the string path of the current user's home directory. Similar to Node.js os.homedir().
Example
Wsh.OS.homedir(); // Returns: 'C:\\Users\\UserName'
Returns:
- The path of the current user's home directory.
- Type
- string
(static) hostname() → {string}
Returns the computer name of the operating system as a string. Similar to Node.js os.hostname().
Example
Wsh.OS.hostname(); // Returns: 'MYPC0123'
Returns:
- The computer name.
- Type
- string
(static) is64arch() → {boolean}
Identifies whether this Windows CPU architecture is 64bit or not.
Example
Wsh.OS.is64arch(); // Returns: true
Returns:
- Returns true if the architecture is 64bit, else false.
- Type
- boolean
(static) isAdmin() → {boolean}
Checks if this process is running as Administrator authority.
Example
Wsh.OS.isAdmin(); // Returns: false
Returns:
- true -> running as Administrator authority.
- Type
- boolean
(static) isExistingDrive(driveLetter) → {boolean}
- Source:
Checks if the drive existing.
Example
Wsh.OS.isExistingDrive('D');
// Returns: true
// Note that 'D:\' can not work.
Parameters:
Name | Type | Description |
---|---|---|
driveLetter |
string | The drive letter to check. |
Returns:
- If the drive is existing, returns true.
- Type
- boolean
(static) isUacDisable() → {boolean}
Checks whether enabled or disabled UAC.
Example
Wsh.OS.isUacDisable(); // Returns: true
Returns:
- If enabled UAC returns true.
- Type
- boolean
(static) joinCmdArgs(args, optionsopt) → {string}
Escapes and joines the Array of arguments for Command-Prompt.
Example
Wsh.OS.joinCmdArgs([
'C:\\Program Files (x86)\\Hoge\\foo.exe',
'1>&2', // Redirect
'C:\\Logs\\err.log',
'|', //Pipe
'tag=R&B',
'/RegExp="^(A|The) $"',
'<%^[yyyy|yy]-MM-DD%>'
]);
// Returns: '"C:\\Program Files (x86)\\Hoge\\foo.exe" 1>&2 C:\\Logs\\err.log | tag=R^&B "/RegExp=\\"^^(A^|The) $\\"" ^<%^^[yyyy^|yy]-MM-DD%^>'
// @NOTE If you include standard output, divide the array elements
Wsh.OS.joinCmdArgs(['ping.exe', 'localhost', '>', 'C:\\My Logs\\stdout.log]);
// Or, do not put space in between the dest and quoted it
Wsh.OS.joinCmdArgs(['ping.exe', 'localhost', '1>"C:\\My Logs\\stdout.log"]);
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Array.<string> | string | The arguments to convert. If args is String, return this string value. |
|||||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
- The string of escaped and joined.
- Type
- string
(static) makeTmpPath(prefixopt, postfixopt) → {string}
Creates the unique path on the %TEMP%
Example
var os = Wsh.OS; // Shorthand
os.makeTmpPath();
// Returns: 'C:\\Users\\UserName\\AppData\\Local\\Temp\\rad6E884.tmp'
os.makeTmpPath();
// Returns: 'C:\\Users\\UserName\\AppData\\Local\\Temp\\rad20D90.tmp'
os.makeTmpPath('cache-', '.tmp');
// Returns: 'C:\\Users\\UserName\\AppData\\Local\\Temp\\cache-radA8812.tmp.tmp'
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
prefix |
string |
<optional> |
The prefix name of the path. |
postfix |
string |
<optional> |
The postfix name of the path.. |
Returns:
- The unique path on the %TEMP%.
- Type
- string
(static) platform() → {string}
Returns win32 which is the string identifying Windows. Similar to Node.js os.platform().
Example
Wsh.OS.platform(); // Returns: 'win32'
Returns:
- Returns 'win32'
- Type
- string
(static) release() → {string}
Returns the operating system as a string. Similar to Node.js os.release().
Example
Wsh.OS.release(); // Returns: 10.0.18363
Returns:
- The version of the operating system as a string.
- Type
- string
(static) removeAssignedDriveLetter(letter) → {void}
- Source:
Removes the assigning drive letter.
Example
Wsh.OS.removeAssignedDriveLetter('Y');
Parameters:
Name | Type | Description |
---|---|---|
letter |
string | The assigning drive letter to remove. |
Throws:
-
- If an error occurs during command execution, or if the command exits with a value other than 0.
- Type
- string
Returns:
- Type
- void
(static) run(cmdStr, argsopt, optionsopt) → {number|string}
Asynchronously runs the application with WScript.Shell.Run. WSH Run method
Example
var os = Wsh.OS;
var fso = Wsh.FileSystemObject;
// Ex1. CMD-command
// Throws a Error. `mkdir` is the CMD command
os.shRun('mkdir', 'D:\\Temp1');
// With the options
os.shRun('mkdir', 'D:\\Temp1', { shell: true, winStyle: 'hidden' });
// Returns: Always 0
while (!fso.FolderExists('D:\\Temp1')) { // Waiting the created
WScript.Sleep(300);
}
fso.FolderExists('D:\\Temp1'); // Returns: true
// Ex2. Exe-file
os.shRun('notepad.exe', ['D:\\Test2.txt'], { winStyle: 'activeMax' });
// Returns: Always 0
// Ex.3 Dry Run
var cmd = os.shRun('mkdir', 'D:\\Temp3', { shell: true, isDryRun: true });
console.log(cmd);
// Outputs:
// dry-run [_shRun]: C:\Windows\System32\cmd.exe /S /C"mkdir D:\Temp3"
fso.FolderExists('D:\\Temp3'); // Returns: false
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments. |
options |
typeShRunOptions |
<optional> |
Optional parameters. |
Returns:
- Returns 0 except when options.isDryRun is true.
- Type
- number | string
(static) runAsAdmin(cmdStr, argsopt, optionsopt) → {void|string}
Asynchronously runs the application as administrator authority with WScript.Shell.ShellExecute. WSH ShellExecute method
Example
var os = Wsh.OS;
// Ex1. CMD-command
// Throws a Error. `mklink` is the CMD command
os.runAsAdmin('mklink', 'D:\\Temp-Symlink D:\\Temp');
// With the `shell` option
os.runAsAdmin('mklink', 'D:\\Temp-Symlink D:\\Temp', {
shell: true
});
// Ex2. Exe-file
os.runAsAdmin('D:\\MyApp\\Everything.exe', ['-instance', 'MySet']);
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments. |
options |
typeShRunOptions |
<optional> |
Optional parameters. |
Returns:
- Returns undefined except when options.isDryRu is =true.
- Type
- void | string
(static) runSync(cmdStr, argsopt, optionsopt) → {number|string}
Synchronize of Wsh.OS.shRun
Example
var os = Wsh.OS;
var fso = Wsh.FileSystemObject;
// Ex1. CMD-command
// Throws a Error. `mkdir` is the CMD command
os.shRunSync('mkdir', 'D:\\Temp1');
// With the options
var retVal1 = os.shRunSync('mkdir', 'D:\\Temp1', {
shell: true, winStyle: 'hidden'
});
console.log(retVal1); // Outputs the number of the result code
fso.FolderExists('D:\\Temp1'); // Returns: true
// Ex2. Exe-file
var retVal2 = os.shRunSync('notepad.exe', ['D:\\Test2.txt'], {
winStyle: 'activeMax'
});
// Waits until the notepad process is finished
console.log(retVal2); // Outputs the number of the result code
// Ex.3 Dry Run
var cmd = os.shRunSync('mkdir', 'D:\\Temp3', { shell: true, isDryRun: true });
console.log(cmd);
// Outputs:
// dry-run [_shRun]: C:\Windows\System32\cmd.exe /S /C"mkdir D:\Temp3"
fso.FolderExists('D:\\Temp3'); // Returns: false
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cmdStr |
string | The executable file path or The command of Command-Prompt. |
|
args |
Array.<string> | string |
<optional> |
The arguments. |
options |
object |
<optional> |
Optional parameters. See typeConvToCommandOptions and typeShRunOptions. |
Returns:
- Returns code from the app except when options.isDryRun is true.
- Type
- number | string
(static) setStrToClipboardAO(str) → {void}
[Experimenta] Sets the string to the Clipboard.
Parameters:
Name | Type | Description |
---|---|---|
str |
string |
Returns:
- Type
- void
(static) surroundCmdArg(str) → {string}
Surrounds a file path and argument with double quotes.
Example
var os = Wsh.OS; // Shorthand
os.surroundCmdArg('C:\\Windows\\System32\\notepad.exe'); // No space
// Returns: 'C:\\Windows\\System32\\notepad.exe'
os.surroundCmdArg('C:\\Program Files'); // Has a space
// Returns: '"C:\\Program Files"'
os.surroundCmdArg('"C:\\Program Files (x86)\\Windows NT"'); // Already quoted
// Returns: '"C:\\Program Files (x86)\\Windows NT"'
os.surroundCmdArg('D:\\2011-01-01家族で初詣'); // Non-ASCII chars
// Returns: '"D:\\2011-01-01家族で初詣"'
os.surroundCmdArg('D:\\Music\\R&B'); // Ampersand
// Returns: '"D:\\Music\\R&B"'
os.surroundCmdArg('abcd1234'); // Returns: 'abcd1234'
os.surroundCmdArg('abcd 1234'); // Returns: '"abcd 1234"
os.surroundCmdArg('あいうえお'); // Returns: '"あいうえお"'
// A command control character
os.surroundCmdArg('|'); // Returns: '|'
os.surroundCmdArg('>'); // Returns: '>'
// Inner quoted
os.surroundCmdArg('-p"My p@ss wo^d"'); // Returns: '-p"My p@ss wo^d"'
os.surroundCmdArg('1> "C:\\logs.txt"'); // Returns: '"1> "C:\\logs.txt""'
os.surroundCmdArg('1>"C:\\logs.txt"'); // Returns: '1>"C:\\logs.txt"'
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The path to surround. |
Returns:
- The surrounded path.
- Type
- string
(static) sysInfo() → {object}
Returns the local computer OS system infomation. Win32_OperatingSystem class.
Example
Wsh.OS.sysInfo();
// Returns: {
// BuildNumber: '12345',
// BuildType: 'Multiprocessor Free',
// Caption: 'Microsoft Windows 10 Pro',
// CodeSet: '987',
// CountryCode: '81',
// CreationClassName: 'Win32_OperatingSystem',
// CSCreationClassName: 'Win32_ComputerSystem',
// CSDVersion: null,
// CSName: 'COMPNAME',
// CurrentTimeZone: 540,
// DataExecutionPrevention_32BitApplications: true,
// DataExecutionPrevention_Available: true,
// DataExecutionPrevention_Drivers: true,
// DataExecutionPrevention_SupportPolicy: 2,
// Debug: false,
// Description: '',
// Distributed: false,
// EncryptionLevel: 256,
// ForegroundApplicationBoost: 2,
// FreePhysicalMemory: '15674120',
// FreeSpaceInPagingFiles: '8773316',
// FreeVirtualMemory: '18820380',
// InstallDate: '20l71221152304.000000+540',
// LargeSystemCache: null,
// LastBootUpTime: '20181003042152.994157+540',
// LocalDateTime: '20181003051042.787000+540',
// Locale: '0411',
// Manufacturer: 'Microsoft Corporation',
// MaxNumberOfProcesses: -1,
// MaxProcessMemorySize: '137438953344',
// MUILanguages: [ 'ja-JP' ],
// Name: 'Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk0\Partition4',
// NumberOfLicensedUsers: 0,
// NumberOfProcesses: 212,
// NumberOfUsers: 2,
// OperatingSystemSKU: 48,
// Organization: '',
// OSArchitecture: '64 ビット',
// OSLanguage: 1041,
// OSProductSuite: 256,
// OSType: 18,
// OtherTypeDescription: null,
// PAEEnabled: null,
// PlusProductID: null,
// PlusVersionNumber: null,
// PortableOperatingSystem: false,
// Primary: true,
// ProductType: 1,
// RegisteredUser: 'Username',
// SerialNumber: '12345-67890-12345-ABOEM',
// ServicePackMajorVersion: 0,
// ServicePackMinorVersion: 0,
// SizeStoredInPagingFiles: '8912896',
// Status: 'OK',
// SuiteMask: 272,
// SystemDevice: '\Device\HarddiskVolume4',
// SystemDirectory: 'C:\WINDOWS\system32',
// SystemDrive: 'C:',
// TotalSwapSpaceSize: null,
// TotalVirtualMemorySize: '42392460',
// TotalVisibleMemorySize: '33479564',
// Version: '10.0.12345',
// WindowsDirectory: 'C:\WINDOWS' }
Returns:
- The local computer OS system infomation.
- Type
- object
(static) terminateProcesses(processName, optionsopt) → {void}
- Source:
Terminates the specified processes.
Example
Wsh.OS.terminateProcesses('cmd.exe');
// Terminates all cmd.exe processes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
processName |
number | string | The PID or process name or full path. |
|
options |
typeGetProcessesOptions |
<optional> |
Optional parameters. |
Returns:
- Type
- void
(static) tmpdir() → {string}
Returns the operating system's default directory for temporary files as a string. Similar to Node.js os.tmpdir().
Example
Wsh.OS.tmpdir();
// Returns: 'C:\\Users\\UserName\\AppData\\Local\\Temp'
Returns:
- The path of directory for temporary.
- Type
- string
(static) totalmem() → {number}
Returns the total amount of system memory in bytes as an integer. Similar to Node.js os.totalmem().
Example
Wsh.OS.release(); // Returns: 34276515840
Returns:
- The total amount of system memory in bytes as an integer.
- Type
- number
(static) type() → {string}
Returns the operating system name. Similar to Node.js os.type()
Example
Wsh.OS.type(); // Returns: 'Windows_NT'
Returns:
- The operating system name.
- Type
- string
(static) userInfo() → {object}
Returns information about the currently effective user. Similar to Node.js os.userInfo().
Example
Wsh.OS.userInfo();
// Returns: {
// uid: -1,
// gid: -1,
// username: 'UserName',
// homedir: 'C:\Users\UserName',
// shell: null }
Returns:
- The object of effective user.
- Type
- object
(static) writeTempText(txtData, extopt) → {string}
Writes the string on a temporary file and returns the file-path.
Example
var os = Wsh.OS; // Shorthand
var tmpPath = os.writeTempText('Foo Bar');
// Returns: 'C:\\Users\\UserName\\AppData\\Local\\Temp\\rad91A81.tmp'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
txtData |
string | Thes string data. |
||
ext |
string |
<optional> |
''
|
The extension of the tempporary text file. |
Returns:
- The temporary file path.
- Type
- string