Connecting to a Remote Server on a different domain — how do I enter the username and password?

ぃ、小莉子 提交于 2019-12-11 08:57:07

问题


I have a vbscript where I am parsing information on a remote machine.

I have this line of code for the connection strComputer is defined to be the name of the server we are connecting to.

Set objWmiService = GetObject("winmgmts:{impersonationLevel=impersonate!\\" & strComputer & "\root\cimv2")

As long as I am executing the script on the SAME domain as the remote server, the script will run just fine. My requirement is to be able to run the script from one domain to access a remote computer on a different domain.

To do this, I need to provide a username and password. I think the username must have the domain as part of it?

Anyways, Is this possible? If so, how and where do I enter the username and password for this? I can simply add it as an argument.


回答1:


According to Microsoft it should be possible. You need to authenticate against the remote domain, though, e.g. like this:

computer = "..."
username = "OTHERDOMAIN\user"
password = "..."

Set locator = CreateObject("WbemScripting.SWbemLocator")
Set wmi = locator.ConnectServer(computer, "root\cimv2", username, password)
wmi.Security_.ImpersonationLevel = 3


来源:https://stackoverflow.com/questions/17976838/connecting-to-a-remote-server-on-a-different-domain-how-do-i-enter-the-userna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!