title: Windows, add user by Rust
body: <p>I use winapi NetUserAdd to add a user,account added succsess,execute command <code>net user</code>,shows as below picture and cannot find users by control panel.</p>
  <p><a href="https://i.stack.imgur.com/XtSDO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XtSDO.png" alt="enter image description here" /></a></p>
  <p>What wrong with LPSWTR or USER_INFO_1 struct to LPBYTE?</p>
  <pre><code>
  use winapi::um::lmaccess::{USER_INFO_1,NetUserAdd,UF_SCRIPT};
  use std::iter::{once};
  use std::os::windows::ffi::OsStrExt;
  use std::ffi::OsStr;
  
  pub fn winstr(value: &amp;str) -&gt; Vec&lt;u16&gt; {
      OsStr::new(value).encode_wide().chain(once(0)).collect()
  }
  
  fn main() {
  
          let username:String =  &quot;Test&quot;.to_string();
          let password:String = &quot;Test******&quot;.to_string();
          let mut user = USER_INFO_1{
              usri1_name:winstr(&amp;username).as_mut_ptr(),
              usri1_password:winstr(&amp;password).as_mut_ptr(),
              usri1_priv:1,
              usri1_password_age: 0,
              usri1_home_dir: std::ptr::null_mut(),
              usri1_comment: std::ptr::null_mut(),
              usri1_flags:UF_SCRIPT,
              usri1_script_path: std::ptr::null_mut(),
          };
          
          let mut error = 0 ;
          unsafe{
              NetUserAdd(std::ptr::null_mut(),1,&amp;mut user as *mut _ as _,&amp;mut error);
          }
          
          println!(&quot;{}&quot;,error);//result is 0,means success.
  
  }
  
  </code></pre>