0

I am trying to make a ticket tool we have where I work a little better and make it so the tech team doesn't have to open Active Directory to make sure the ticket sender is eligible to make certain requests. What I need is the ability to run net user /domain <username> then collect the comment line and store it in a variable in VBA. The variable will then be sent in an email to the ticket software along with anything the user entered in the text boxes.

My thoughts were to run the command and send the output string to another variable then pull the line information from the larger output since I cant seem to find a way to get only the comment.

I've added a sample of the output below with an arrow pointing at the data that needs extracted into the variable.

I'm still pretty new to VBA so bear with me.

C:\Users\jdoe\Desktop>net user /domain jdoe
The request will be processed at a domain controller for domain StackOverflow.wh.

User name                    jdoe
Full Name                    John Doe
Comment                      Anlst Tech Supp  <----- this is what needs extracted
User's comment
Country/region code          000 (System Default)
Account active               Yes
Account expires              Never

Password last set            11/1/2021 8:58:44 AM
Password expires             1/30/2022 8:58:44 AM
Password changeable          11/1/2021 8:58:44 AM
Password required            Yes
User may change password     Yes

Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   1/15/2022 11:43:12 AM

Logon hours allowed          All

Local Group Memberships
Global Group memberships     *Domain Users

The command completed successfully.
  • 2
    Does this answer your question? [Capture output value from a shell command in VBA?](https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba) Simply add an `If` condition on the stream loop to check `'Comment'` at start of line. – Parfait Jan 16 '22 at 03:09

1 Answers1

0
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set config = objWMIService.ExecQuery("Select * From Win32_UserAccount")
For Each thing in Config
        Msgbox thing.caption & "  " & thing.Description
Next

Programmers don't call user's commands. They are for humans not programs.

See https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-useraccount for more info.

KL-1
  • 94
  • 1
  • 3