Using vbscript, is there a way to ask for username and password, and then
run the rest of the task based on those credentials?

What I'm doing exactly is this: I've created a script to allow me to add
domain users to the local admin group on a remote machine or lab of
machines. Unfortunately, in order to run it and have it run properly on the
remote machine, it must be run by someone who already has their domain
account in the machine's local admin group. What I'd like to do is have it
ask me for the machine's local admin acct and password, then, using those
credentials, add the new domain accounts to the local admin group.

Any ideas?

Thanks,

Doug

Re: vbscript and domain credentials by Richard

Richard
Thu May 10 14:18:49 CDT 2007

Doug wrote:

> Using vbscript, is there a way to ask for username and password, and then
> run the rest of the task based on those credentials?
>
> What I'm doing exactly is this: I've created a script to allow me to add
> domain users to the local admin group on a remote machine or lab of
> machines. Unfortunately, in order to run it and have it run properly on
> the remote machine, it must be run by someone who already has their domain
> account in the machine's local admin group. What I'd like to do is have
> it ask me for the machine's local admin acct and password, then, using
> those credentials, add the new domain accounts to the local admin group.

You can use the OpenDSObject method to specify alternate credentials. I have
used code similar to below:
============
Const ADS_SECURE_AUTHENTICATION = &H1
Const ADS_USE_ENCRYPTION = &H2

' Specify remote computer.
strComputer = "WEST023"

' Prompt for credentials.
strUser = InputBox("Enter Admin User")
strPassword = InputBox("Enter Password")

' Bind to domain group.
Set objDomainGroup = GetObject("WinNT://MyDomain/Test Group,group")

' Bind to local Administrators group on remote computer.
Set objNS = GetObject("WinNT:")
Set objLocalGroup = objNS.OpenDSObject("WinNT://" & strComputer _
& "/Administrators,group", strUser, strPassword, _
ADS_SECURE_AUTHENTICATION Or ADS_USE_ENCRYPTION)

' Check if domain group already member of local group.
If (objLocalGroup.IsMember(objDomainGroup.AdsPath) = False) Then
' Add domain group to local group.
objLocalGroup.Add(objDomainGroup.AdsPath)
End If

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--