Envin
Envin

Reputation: 1523

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

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.

Upvotes: 1

Views: 3943

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200273

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

Upvotes: 2

Related Questions