Disable\Enable user groups from Command line or Api

Posted on 2003-03-24
Medium Priority
Last Modified: 2013-12-04
I am looking for a way to programtically disable and enable different windows user groups using visual basic 6. The purpose of this object is to disable any potential users during nightly jobs and then enable them after completion.

Does anyone know of any console commands I can send or API's I can use to accomplish this?
Question by:SouthDev
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

ManuelGuerra earned 500 total points
ID: 8199767
You can't disable a group, but you can disable a user.
An example for disable a user with a .vbs :

Set ObjUser=GetObject("WinNT://MyDomain/MyAccount,user")
objUser.AccountDisabled = True

Good Luck, MG

Author Comment

ID: 8203470
I am currently trying to implement this method but I get a "General Access Denied Error" upon reaching the set info command.

Public Function Execute(ByVal pstrGroup As String, _
                        ByVal pblnUseDomain As Boolean, _
                        ByVal pblnActive As Boolean) As Long

'*** Strings
    Dim strComputerName As String
    Dim strUserName As String
    Dim strDomainName As String
    '*** Booleans
    Dim blnDisableAccount As Boolean
    '*** Objects
    Dim objWshNet As Object
    Dim oDomain
    Dim User, Member
    '*** Arrays
    Dim arrGroups() As String
    '*** Integers
    Dim i As Integer
    On Error GoTo ExitLogic
    Set objWshNet = CreateObject("WScript.Network")
    strComputerName = objWshNet.ComputerName
    strUserName = objWshNet.UserName
    strDomainName = objWshNet.UserDomain
    blnDisableAccount = Not (pblnActive)
    arrGroups = Split(pstrGroup, ",")
    ' loop through provided groups as long as groups are valid for the parameters provided
    For i = 0 To UBound(arrGroups)
            If Not pblnUseDomain Then
                 Set oDomain = GetObject("WinNT://" & strComputerName & "/" & arrGroups(i))
                  Set oDomain = GetObject("WinNT://" & strDomainName & "/" & arrGroups(i))
            End If
            For Each Member In oDomain.members
               If Member.Class = "User" Then
                     If Not pblnUseDomain Then
                          Set User = GetObject("WinNT://" & strComputerName & "/" & Member.Name & ",user")
                          Set User = GetObject("WinNT://" & strDomainName & "/" & Member.Name & ",user")
                     End If
                     User.accountDisabled = blnDisableAccount
                     Set User = Nothing
                End If
     Next i
    '***Set all object references to nothing
    Set objWshNet = Nothing
    Set oDomain = Nothing
    Set User = Nothing
    Set Member = Nothing
    Erase arrGroups
    if err.number <> 0 then
         msgBox err.description, vbCritical, "Error"
    end if
end  function

Expert Comment

ID: 8203813
Access Denied? check your rights, do you have enough rights? please put the next code in a new file called test.vbs and run it with "cscript test.vbs" please replace MyDomain with a valid domain or computer and MyAccount with a valid account:

Set ObjUser=GetObject("WinNT://MyDomain/MyAccount,user")
objUser.AccountDisabled = True

Expert Comment

ID: 8203901
Please check your rights, "Access Denied" is just a problem for not enough rights.

Author Comment

ID: 8204144
Yeah I am able to succefully alter local computer users/groups for which I have access to but the domain  option fails due to rights. Hopefully there are no security rules disable scripting on the network this will eventually be implemnted on.

Thanks for the help

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

In today's information driven age, entrepreneurs have so many great tools and options at their disposal to help turn good ideas into a thriving business. With cloud-based online services, such as Amazon's Web Services (AWS) or Microsoft's Azure, bus…
Security measures require Windows be logged in using Standard User login (not Administrator).  Yet, sometimes an application has to be run “As Administrator” from a Standard User login.  This paper describes how to create a shortcut icon to launch a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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