public static async Task <string[]> GetWindowsAccountsListAsync() { try { var output = await ProcessLauncherUtil.RunCommandLineAsync(@"c:\windows\system32\iotsettings.exe -list account"); if (output != null && output.Output != null) { ServiceUtil.LogService.Write(output.ToString()); return(output.Output?.Split(" ", StringSplitOptions.RemoveEmptyEntries).Where(x => x.Contains("@")).ToArray()); } } catch (Exception ex) { ServiceUtil.LogService.WriteException(ex); } return(null); }
public static async Task <bool> ClearWindowsAccountAsync(string username) { try { var accounts = await GetWindowsAccountsListAsync(); var output = await ProcessLauncherUtil.RunCommandLineAsync(@"c:\windows\system32\iotsettings.exe" + $" -del account {username}"); if (output != null) { ServiceUtil.LogService.Write(output.ToString()); return(output.Result.ExitCode == 0); } } catch (Exception e) { ServiceUtil.LogService.Write(e.Message, LoggingLevel.Error); } return(false); }