Create a local Windows account of DOS command with c sharp

  • 2020-05-05 11:43:52
  • OfStack

Other methods see. Create an Windows account (DirectoryServices)   locally with C#
http://yaosansi.com/blog/article.asp?id=917      

Under WinForm the program can be written as       (has been tested and needs to be run as Administrator)        

    using       System;        
    namespace       eg        
    {        
    class           test        
    {        
    static           void           Main()        
    {        

    // declares a program information class        
    System.Diagnostics.ProcessStartInfo           Info           =           new           System.Diagnostics.ProcessStartInfo();        

    // set the external program name        
    Info.FileName           =           "net.exe";        

    // sets the startup parameter (command-line parameter) of the external program to test.txt        
    Info.Arguments           =           "       user       abc       /add";        

    // set the external program working directory to           D:\        
    Info.WorkingDirectory           =           "D:\\";        

    // declares a program class        
    System.Diagnostics.Process           Proc           ;        

    try        
    {        
    //        
    // start the external program        
    //        
    Proc           =           System.Diagnostics.Process.Start(Info);        
    }        
    catch(System.ComponentModel.Win32Exception           e)        
    {        
    Console. WriteLine (& quot; The system could not find the specified program file. \ r {0} & quot; ,           e);        
    return;        
    }        
    }        
    }        
    }        

Note: the ASPNET account belongs to the Users group. The Users group does not have complete control over the computer. As for why you can't see it in the process because it's running on the command line, you can only see it under CMD:       net       user          





    add administrator:        
    System.Diagnostics.Process.Start("CMD.exe","/c       net       user       admin       123456       /add");        
    System.Diagnostics.Process.Start("CMD.exe","/c       net       localgroup       administrators       admin       /add");        

    changes the password of admin to 250:        
    System.Diagnostics.Process.Start("CMD.exe","/c       net       user       admin       250       ");        
    delete administrator:        
    System.Diagnostics.Process.Start("CMD.exe","/c       net       user       admin       /del");    




Under CMD can operate it completely, can directly call command line tools such as       System. Diagnostics. Process. Start (& quot; net       user      ... & quot;) ;        

               

    is used to add/create/change the user account        

    syntax:        

    net       user       < username >       [password       or       *]       [/add]       [options]       [/domain]        
    net       user       < username]       /delete       /domain        

    username       account name        
    password     assign or change the password        
    *       password prompt        
    /domain       performs         in a domain
    /add       create an account        
    /delete       delete an account        
    /active:[yes         no]       activate or stop an account        
    /comment:" < text > & quot; Add descriptive description        
   /counterycode.nnn     nnn    
    /expires: < date       or       never > Format: month, day, year or day, month, year (the format is determined by the country code)        
    /fullname:" < name > & quot;       full account name        
    /homedir: < path >       user home directory path        
    /passwordchg:[yes     or     no]       sets whether the user can change the password        
    /passwordreq:[yes          ]       sets whether the user needs a password
    /profilepath: < path >       setting environment file path        
    /scriptpath: < path >       login script path        
    /times: < times       or       all > The number of hours a user can log in is      
    /usercomment:" < text > & quot;       account description information        
    /workstations: < machine       names >       user name allowed to login.       *       represents all users  

Related articles: