You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下用node-windows部署Node.js后台服务遇.vbs脚本引擎错误

解决node-windows部署服务时的".vbs"脚本引擎错误

尝试用node-windows将Node.js脚本部署为Windows后台服务,已全局安装并关联node-windows,但执行service.js时出现错误:

Windows Script Host: There is no script engine for file extension ".vbs"

已尝试在CMD中执行assoc .vbs=VBSFile命令,问题仍未解决。

相关代码

service.js

var Service = require("node-windows").Service;

console.log("entered");

// Create a new service object
var svc = new Service({
  name: "myService",
  description: "my service",
  script:
    "C:\\path-to-my-script\\example.js",
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on("install", function () {
  console.log(" entered install ");
  svc.start();
});

// Listen for the "start" event and let us know when the
// process has actually started working.
svc.on("start", function () {
  console.log(
    svc.name + " started!\nVisit http://127.0.0.1:3000 to see it in action."
  );
});

svc.on("error", function () {
  console.log(svc.name + " error occured");
});

svc.install();

console.log(" completed");

example.js

var http = require("http");

const hostname = "127.0.0.1";
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader("Content-Type", "text/plain");
  res.end("Hello World");
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

解决方法

  • 修复VBScript脚本引擎关联
    打开管理员CMD,执行两条命令:

    assoc .vbs=VBSFile
    ftype VBSFile=%SystemRoot%\System32\WScript.exe "%1" %*
    

    第一条关联扩展名与文件类型,第二条指定该类型的执行程序。

  • 重新注册VBScript引擎
    管理员CMD中执行:

    regsvr32 vbscript.dll
    

    确认弹出注册成功提示。

  • 以管理员身份运行安装命令
    右键CMD/PowerShell选择“以管理员身份运行”,再执行node service.js,node-windows安装服务需要管理员权限。

  • 重装node-windows
    卸载并重新全局安装:

    npm uninstall -g node-windows
    npm install -g node-windows
    
  • 检查WScript.exe完整性
    确认C:\Windows\System32\WScript.exe存在,若缺失需修复系统组件或从同版本正常系统复制该文件。

内容的提问来源于stack exchange,提问作者Mat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 22:30:53