1.通过下面的命令可以调用exe

const child = require('child_process')

child.exec(`${path路径}`, (err, stdout, stderr) => {

    console.log(err, stdout, stderr)

 })

2.如果想给调用的路径传参,就在路径后面加传参的内容

  const child = require('child_process')

  child.exec(`${path} 12 34`, (err, stdout, stderr) => {

        console.log(err, stdout, stderr)

  })

3. 在调用的exe文件中

const { remote } = require('electron')

let arg = remote.process.argv // 这个接收参数,是一个数组

4. ipconfig/all命令能查看当前电脑有多少个网卡,还有网卡的ip信息,DNS等信息,我下面的操作是查看当前系统中是否安装了某个网卡,如果不存在就安装。

node.js调用exe

node.js调用exe

let binaryEncoding = "binary";

let iconv = require("iconv-lite");

let encoding = "cp936"; 

const child = require('child_process')

child.exec( `ipconfig/ALL`, { encoding: binaryEncoding }, (err, stdout, stderr) => {

          let des = iconv.decode(Buffer.from(stdout, binaryEncoding), encoding); //这个是解决返回的信息乱码的问题

          console.log(des.includes("TAP-Windows Adapter V9"));

  }

 );

5. 关机命令

const child = require('child_process')

child.exec('shutdown -s -t 0 -f')

6.修改ip(乱码的方法可以参考方法四)

const child = require('child_process')

 child .exec(`netsh interface ip set address name="以太网" static ${address} ${mask} ${gatework}`, { encoding: binaryEncoding, windowsHide: true }, (error, stdout, stderr) => {

       if (!error) {

               console.log('设置地址成功!')

       } else {

               console.log('设置地址失败!')

       }

              // console.log(iconv.decode(new Buffer(stdout, binaryEncoding), encoding))

     })

7.修改系统时间

const child = require('child_process')

exec(`date ${year}/${mon}/${day} & time ${hour}:${mi}:${ss}`, (err, stdout, stderr) => {     

 })

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
猜你喜欢
  • 2021-11-10
  • 2021-06-01
  • 2022-01-26
  • 2022-01-16
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案