如何使用FSharp.Management WMI提供程序与远程计算机连接?

3

我已经修改了来自FSharp管理项目的示例脚本,以连接远程主机而不是localhost:

System.IO.Directory.SetCurrentDirectory (__SOURCE_DIRECTORY__)

#r @"System.Management.dll"
#r @"..\Packages\FSharp.Management.0.3.1\lib\net40\FSharp.Management.dll"
#r @"..\Packages\FSharp.Management.0.3.1\lib\net40\FSharp.Management.WMI.dll"

open FSharp.Management

type Remote = WmiProvider<"remotehost@username:password">
let data = Remote.GetDataContext()

很不幸,我在Remote上得到一个错误,提示GetDataContext未定义。但是,如果我将WmiProvider更改为WmiProvider<"localhost">,那么它将按预期工作。

我不确定登录是否正确,但如果我将用户名或密码更改为我知道不正确的内容,则WmiProvider行会返回RPC错误,因此我确信已成功登录。

1个回答

4
实际上,WmiProvider 与系统通信有两个不同的时间点:设计时间和运行时间。在您的示例代码中,您正在设计时间连接 WmiProvider 到远程机器,这意味着它将尝试从远程机器检索 WMI“类型”。您可以尝试在设计时间使用 localhost,因为您说那似乎有效,然后在运行时间使用远程机器。
只在运行时间仅使用远程系统的示例如下:
open FSharp.Management

type WmiContext = WmiProvider<"localhost">

let wmiContext = WmiContext.GetDataContext("remoteMachine")

感谢您的回答。在我的示例中,我试图让WMI基础设施工作,并仅访问常见的Windows WMI类型。不幸的是,我需要的实际WMI类型不在本地主机上,因为它们是远程应用程序的一部分。 - David J

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接