Use pure Node. JS to pop up the Windows system message box instance (MessageBox), node. jsmessagebox

Source: Internet
Author: User

Use pure Node. JS to pop up the Windows system message box instance (MessageBox), node. jsmessagebox

Node. JS is a console program. If you want to pop up a Windows Prompt box from Node. JS, there are many ways to implement it. For example, with the help of electron or node-webkit:

Pop-up message box in Electron

The interfaces of Electron and Windows are perfect, and various Window native mechanisms can be called, such as creating system tray icons. Open the folder selection box. Here we use dialog to bring up a system message prompt box:

Const {app, BrowserWindow, Menu, Tray, shell, dialog, ipcMain} = require ('electron') var parseCommand = function () {dialog. showMessageBox ({title: 'error', type: 'error', message: 'This file is not bound to OnceDoc'})} var initApp = function () {parseCommand ()} app. on ('ready', initApp)

Run the above Code using electron:

electron app.js

Call the VB script to pop up the message box

Electron is indeed more convenient, but it is relatively large, and message pop-up is relatively slow. We can use child_process to call the VB script to pop up the message box.

For example, we create a new VB script file named vb. message. vbs. The content is as follows:

msgbox WScript.Arguments(1), vbInformation, WScript.Arguments(0)

This script will pop up the first and second parameters as the title and content of the prompt box. You can call it in Node. JS:

Var cp = require ('child _ Process') var initApp = function () {var vbsPath = path. join (_ dirname, 'vb. message. vbs ') cp.exec('cscript.exe' + vbsPath + '"prompt" "this file is not bound to OnceDoc"', function (err, stdout, stderr) {if (err) {fs. writeFileSync ('Log. log', err. toString () }}} initApp ()

Use ActiveXObject to pop up the message box

VB scripts need to create additional files. With ActiveXObject, you can directly write scripts in Node. JS, for example:

var cp  = require('child_process')var initApp = function() { cp.exec('mshta "javascript:var sh=new ActiveXObject("WScript.Shell"); sh.Popup("Message!", 10, "Title!", 64 );close()"')}initApp()

In addition to the pop-up box, you can use vb and activex scripts to implement some advanced functions, such as connecting to the database. In addition, msg.exe supports inter-process communication.

Based on the message prompts, some systems may not have msg.exe installed, and this method cannot customize the message title.

Cp.exe c ('msg % username % "What does this mean? I don't know "')

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.