Solved

Creating/Disabling local user on a remote computer with VBscript

Posted on 2010-08-23
2
842 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now