process

process

Source:

The process object is a global that provides information about, and control over, the current WSH process.

Requires

Members

(constant) env :object

Source:

Returns an object containing the user environment. Similar to Node.js process.env. Alias of Wsh.OS.envVars.

Type:
  • object
Example
console.dir(process.env);
// 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) arch :string

Source:

CPU architecture for Wscript.exe/Cscript.exe was compiled. Similar to Node.js process.arch. process.arch = os.arch?

Type:
  • string
Example
console.log(process.arch); // amd64

(static, constant) argv :Array.<string>

Source:

Returns an array containing the process command. Similar to Node.js process.argv

Type:
  • Array.<string>
Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.dir(process.argv);
// Outputs: [
//   "C:\Windows\system32\cscript.exe",
//   "D:\Run.wsf",
//   "-n",
//   "arg"]

(static, constant) argv0 :string

Source:

Returns the original value of argv[0]. Similar to Node.js process.argv0

Type:
  • string
Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.log(process.argv0); // C:\Windows\system32\cscript.exe

(static, constant) execArgv :Array.<string>

Source:

Returns the set of the WSH options passed when the process was launched. Similar to Node.js process.execArgv.

Type:
  • Array.<string>
Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.dir(process.execArgv);
// Output: [
//   "//nologo",
//   "//job:run"]

(static, constant) execPath :string

Source:

Returns the absolute pathname of the executable that started the WSH process. Similar to Node.js process.execPath.

Type:
  • string
Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.log(process.execPath); // C:\Windows\system32\cscript.exe

(static) exitCode :number

Source:

A number which will be the process exit code, when the process either exits gracefully, or is exited via process.exit() without specifying a code. Similar to Node.js process.exitCode.

Type:
  • number
Example
process.exitCode = 1;
process.exit();
// This process returns 1 and exits

console.log('Do not reach here');

(static, constant) pid :number

Source:

Returns the PID of the WSH process. Similar to Node.js process.pid.

Type:
  • number
Example
console.log(process.pid); // 38579

(static, constant) platform :string

Source:

Returns a string identifying the operating system platform. Similar to Node.js process.platform.

Type:
  • string
Example
console.log(process.platform); // win32

(static, constant) ppid :number

Source:

Returns the PID of the current parent process. Similar to Node.js process.ppid.

Type:
  • number
Example
console.log(process.ppid); // 12173

(static, constant) release :string

Source:

Returns an Object containing metadata related to the current release. Similar to Node.js process.release.

Type:
  • string
Example
console.dir(process.release);
// Outputs: {
//   name: "JScript",
//   sourceUrl: "https://github.com/tuckn/WshModeJs/archive/master.zip" }

(static, constant) version :string

Source:

Returns the WSH version string. Similar to Node.js process.version.

Type:
  • string
Example
console.log(process.version); // v5.8.16384

(static, constant) versions :string

Source:

Returns the WSH version string. Similar to Node.js process.versions.

Type:
  • string
Example
console.dir(process.versions);
// Outputs: {
//   wsh: "5.812",
//   jscript: "5.8.16384" }

(static, constant) wsArgs :Array.<string>

Source:

Returns an array of specified arguments for the WSH script. This is WScript.Arguments converted to JScript array.

Type:
  • Array.<string>
Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.dir(process.wsArgs);
// Output: [
//   "-n",
//   "arg 1"]

Methods

isAdmin() → {boolean}

Source:

Checks if this process is running as Administrator authority. Alias of Wsh.OS.isAdmin.

Example
process.isAdmin(); // false
Returns:
Type
boolean

kill()

Source:

Sends the signal to the process identified by the PID or the process name. Alias of Wsh.OS.terminateProcesses. Similar to Node.js process.kill().

Example
process.kill('chrome.exe');
// Terminates all chrome.exe processes.

(static) cwd() → {string}

Source:

Returns the current working directory of the WSH process. Similar to Node.js process.cwd().

Example
// Ex. Run the command below
// C:\tuckn\test> cscript //nologo D:\Run.wsf //job:test -n "arg 1"
console.log(process.cwd); // C:\tuckn\test
Returns:
Type
string

(static) exit(exitCodeopt) → {void}

Source:

Instructs WSH to terminate the process. Similar to Node.js process.exit(). @todo Support Chakra(JScript11). Chakra can not use WScript.Quit.

Example
process.exit(1);
// This process returns 1 and exits

console.log('Do not reach here');
Parameters:
Name Type Attributes Default Description
exitCode number <optional>
0

The exit code.

Returns:
Type
void

(static) restartAsAdmin(optionsopt) → {void|string}

Source:

Executes the self process as HighWIL. and die

Example
if (!process.isAdmin()) process.restartAsAdmin();

console.log('This process is running as admin-authority.');
Parameters:
Name Type Attributes Description
options object <optional>

Optional Parameters.

Properties
Name Type Attributes Default Description
isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
  • If isDryRun is true, returns the command log string. Not execute.
Type
void | string

(static) restartAsUser(optionsopt) → {void|string}

Source:

Executes calling the self process as Medium WIL. and die

Example
if (process.isAdmin()) process.restartAsUser();

console.log('This process is running as user-authority.');
Parameters:
Name Type Attributes Description
options object <optional>

Optional Parameters.

Properties
Name Type Attributes Default Description
isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
  • If isDryRun is true, returns the command log string. Not execute.
Type
void | string

(static) stderr(errMsg)

Source:

Outputs error line of standard stream. GetStandardStream method).

Example
process.stderr('Error occurred!');
// In Console
// Error occurred!
Parameters:
Name Type Description
errMsg string

The error message to print.

(static) stdin(msgLine)

Source:

[W.I.P] @todo Inputs standard stream. GetStandardStream method).

Parameters:
Name Type Description
msgLine string

The line message to input.

(static) stdout(msgLine)

Source:

Output a standard stream. GetStandardStream method).

Example
process.stdout('Hello World!');
// In Console
// Hello World!
Parameters:
Name Type Description
msgLine string

The line message to print.

(static) wait(waitSec, optionsopt) → {boolean|string}

Source:

Stops the process for the specified number of seconds. The difference from WScript.Sleep, Shows a countdown window.

Example
process.wait(5);
// Waiting for 5 sec

console.log('5 seconds have passed.');
Parameters:
Name Type Attributes Description
waitSec number

The waiting sec.

options object <optional>

Optional Parameters.

Properties
Name Type Attributes Default Description
winStyle number | string <optional>
activeDef

See Wsh.Constants.windowStyles.

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
  • If canceled the wait, returns false, else true. If isDryRun is true, returns the command log string. Not execute.
Type
boolean | string