0

I'm trying to use the Vix API and i'm trying to receive some information of the virtual machines i'm working on. The information i need is the domain to which the VM is connected, and the list of users that are registered (i.e., have access) to the specific VM. I tried using 'google' and the documentation (https://www.vmware.com/support/developer/vc-sdk/visdk2xpubs/ReferenceGuide/) but i can't find how to get this information. Tried to allocate a few objects that might contain the the domain, but it didn't help.

4

1 回答 1

0

我不确定这是否会对您有所帮助,但下面是一个小型 Delphi 项目(使用与 vbScript 相同的 Vix COM/OLE 接口)的摘录,该项目从 Win7 VM 的环境中检索当前用户名。希望代码可以直接转换为 vbScript 或 VBA。显然,您可以以类似的方式检索任何其他环境变量的值,例如用户域。

我对 Vix COM API 进行了彻底的查看,但没有找到任何可以检索 VM 可用登录 ID 列表的内容。所以,如果我必须这样做,我会编写一个小型实用程序应用程序在 VM 中运行以获取它们。(您可能已经知道,但通过 Vix 界面在 VM 中运行应用程序很简单。)

代码

type  
  TForm1 = class(TForm)
    [...]
    VixLib : IVixLib;
    Job : IJob;
    Host : IHost;
    VM : IVM;
    Err : Int64;
    vWaitParams : OleVariant;
    vResults : OleVariant;
    vValue : OleVariant;
    Msg : String;
  end;
[...]
procedure TForm1.GetUserName;
begin
  // Prior to calling this code, you need to have successfully called
  // LogInGuest on the VM via Vix
  // change USERNAME to USERDOMAIN in the following line to get the domain
  Job := VM.ReadVariable(VIX_GUEST_ENVIRONMENT_VARIABLE, 'USERNAME', 0, Nil);
  vWaitParams := VarArrayOf([VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING]);
  Err := Job.Wait(vWaitParams, vValue);
  if Err <> 0 then
    raise Exception.Create('Error %d', [Err]);

  Msg := vValue[0];
  Caption := Msg;
end;
于 2015-07-20T14:34:43.777 回答