node.js调用exe

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等信息,我下面的操作是查看当前系统中是否安装了某个网卡,如果不存在就安装。

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) => {     

 })

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值