Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Disable\Enable user groups from Command line or Api

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?
0
SouthDev
Asked:
SouthDev
  • 3
  • 2
1 Solution
 
ManuelGuerraCommented:
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
objUser.SetInfo

Good Luck, MG
0
 
SouthDevAuthor Commented:
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))
            Else
                  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")
                     Else
                          Set User = GetObject("WinNT://" & strDomainName & "/" & Member.Name & ",user")
                     End If
                     User.accountDisabled = blnDisableAccount
                     User.setinfo
                     Set User = Nothing
                End If
            Next
     Next i
     
ExitLogic:
    '***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
0
 
ManuelGuerraCommented:
SouthDev,
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
objUser.SetInfo
0
 
ManuelGuerraCommented:
Please check your rights, "Access Denied" is just a problem for not enough rights.
MG
0
 
SouthDevAuthor Commented:
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
0

Featured Post

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now