【问题标题】:Using Service Controller in Classic ASP在经典 ASP 中使用服务控制器
【发布时间】:2015-04-14 15:57:14
【问题描述】:

我目前正在尝试查看是否可以在我的经典 ASP 页面中使用ServiceController,以便该页面可以将自定义命令发送到我的 Windows 服务。我在网上阅读的所有文章和问题都是关于使用 ASP.NET 或其他应用程序/组件的(但遗憾的是,我仅限于使用 Classic ASP)。我的两次尝试都失败了,因为我收到了这个错误:

Microsoft VBScript compilation error '800a0401' Expected end of statement

这是我尝试在我的 asp 页面上使用ServiceController 的两次尝试:

尝试 #1 预期的语句结尾指向 '('

Dim myService
Set myService = New ServiceController("MyNewService")
myService.ExecuteCommand(0)
myService.ExecuteCommand(1)
myService.ExecuteCommand(2)

尝试 #2 预期的语句结尾指向“As”

Dim myService As New ServiceController("MyNewService")
myService.ExecuteCommand(0)
myService.ExecuteCommand(1)
myService.ExecuteCommand(2)

那么,可以在 Classic ASP 中使用 ServiceController 吗?请解释它如何可能或为什么不可能。

【问题讨论】:

  • 你确定ServiceController 被识别了吗?您是否包含了Class 定义?
  • VBScript 不支持带参数的构造函数。你试过Set myService = New ServiceController吗?
  • @haim770 是的,ServiceController 类没有定义,但亚历克斯的回答解释了原因。不过感谢您的帮助!
  • 他要求 1) 链接或 2) 为我工作。两者都非常离题。再次,转到元。讨论。

标签: .net vbscript asp-classic servicecontroller


【解决方案1】:

ServiceController 是一个 .Net 类,VBScript 不知道它是什么。

鉴于它也没有通过 COM 公开,因此无法在 VBScript 中使用。

创建一个 .Net COM Visible 程序集,将调用包装到 ServiceController,在 VBScript (Server.CreateObject()) 中对其进行实例化,并调用您在 C#/VB.Net 中实现的方法来满足您的需求。

【讨论】:

  • 好的,有道理。感谢您的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多