How to use variables to add full name in python with net user

  Kiến thức lập trình

I’ve been working on a script for a bit in python to create new users with input. I’m down to this one line and trying to get the last 2 variables for description and full name to carry over.

subprocess.run(["net", "user", user, password, "/add", "/comment: %description%", "/fullname: %full_name%"], check=True)

As that’s written it creates the user with the right user name and password but the description, aka comment, is %description% and the full name is %full_name%. Those are both variables that are already defined in my code in the program, and are working correctly.

I’ve been trying all kinds of things, I only recently discovered I should have the comment and fullname after the add command. I just want the value of these 2 variables to be passed to the comment and fullname commands.

Here’s the full code in case it’s helpful

import subprocess, os, sys
from easygui import passwordbox
print("""Hello, I am C-3PO. I understant you'd like to add some new users to your system today
I'll be happy to assist you with this task.""")

Count = int(input("How many users are we creating today?"))

Total = 0

GroupName = input("""We want to be sure all of the new users can find each other; comradery is so important you know.
Let’s create a group for them. What would you like the group to be called?""")
subprocess.run(["net", "localgroup", GroupName, "/add"], check=True)

total = 0

while total != Count:
    first_name = input("What is the first name of the user you'd like to create? ")
    middle_name = input("What is their middle name, if they don't have one kindly press enter. ")
    last_name = input("Also, may I know their last name? ")
    username = (first_name[0:1] + last_name)
    full_name = f"{first_name} {middle_name} {last_name}"
    password = passwordbox("What password would you like to give " + full_name + "? ")
    description = input("Would you like to tell me a little about " + full_name + "? If not simply press enter. ")
    user=username
    group = GroupName

    subprocess.run(["net", "user", user, password, "/add", "/comment: %description%", "/fullname: %full_name%"], check=True)
#    subprocess.run(["net", "user", user, "/Comment:"description, "/fullname:", full_name, "/add"], check=True)
    subprocess.run(["net", "localgroup", GroupName, user,"/add"], check=True)
    total += 1

print("nIt's been a pleasure in helping you add these {count} users today.")
print("I do hope you'll inform Master James of my performance.")

Ignore the line that are commented out as it’ll be removed, I’m just using it to save variable names.

LEAVE A COMMENT