Solved

Creating/Disabling local user on a remote computer with VBscript

Posted on 2010-08-23
2
845 Views
Last Modified: 2012-05-10
Hi,

I am trying to modify couple of scripts that I have found on here http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/usersgroups/localusers/ to be executed with alternate credentials and I am having some troubles.  The alternate credentials that I want to use is a local user on a target computer.

Here are the two scripts:

'Creating user
strComputer = "MyComputer"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "test"
objUser.SetInfo

Open in new window


'Disable User
strComputer = "MyComputer"
Set objUser = GetObject("WinNT://" & strComputer & "/Guest")
objUser.AccountDisabled = True
objUser.SetInfo

Open in new window


I found an article that talks about specifying alternate users here http://blogs.technet.com/b/heyscriptingguy/archive/2004/12/13/how-can-i-run-a-script-under-alternate-credentials.aspx but can't figure out how to user their example to modify my two scripts.

Can anyone assist?

Thanks
Alex
0
Comment
Question by:Alexey91
  • 2
2 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 33502280
Hello there,

It should go like this.

Chris
Set objNamespace = GetObject("WinNT:")
Set objComputer = objNamespace.OpenDSObject("WinNT://" & strComputer, "SomeUsername", "SomePassword", 0)
Set objUser = objComputer.Create("user", "Admin2")
objUser.SetPassword "test"
objUser.SetInfo

Open in new window

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 33502286

Missed the "where", SomeUsername and SomePassword represent the account you wish to connect to the remote system with.

Chris
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question