如何在远程计算机上使用FSharp.Management WMI Provider

时间:2016-03-18 12:53:20

标签: f# wmi

我已经从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()

不幸的是,我得到一个错误,GetDataContext没有在Remote上定义。但是,如果我将WmiProvider更改为WmiProvider&lt;&#34; localhost&#34;&gt;它按预期工作。

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

1 个答案:

答案 0 :(得分:4)

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

仅在运行时使用远程系统的示例如下:

open FSharp.Management

type WmiContext = WmiProvider<"localhost">

let wmiContext = WmiContext.GetDataContext("remoteMachine")