[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
for 循环里面要开启变量延迟

TOP

本帖最后由 ivor 于 2018-3-8 20:46 编辑

1.following registry key should be remove:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList


2.Use My Computer or Windows Explorer to remove the appropriate Windows\Profiles\User name folders. To remove all profiles, remove the Windows\Profiles folder.


所以说注册表你也要操作,否则会出先下次登陆无法准备桌面

TOP

你可以通过传递参数%1 获取标准用户名

TOP

本帖最后由 ivor 于 2018-3-9 09:30 编辑
  1. using System;
  2. using System.Diagnostics;
  3. using System.Security;
  4. using System.IO;
  5. using Microsoft.Win32;
  6. /**
  7.     author:ivor
  8.     提权调用自己然后按条件删除C:\\Users子文件夹 和 ProfileList 子项
  9.     */
  10. namespace UpPrivilege
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             if (args.Length == 0)
  17.             {
  18.                 Lanch(Environment.UserName, Environment.CommandLine);
  19.             }
  20.             else
  21.             {
  22.                 DeleteUserProfile(args[0]);
  23.                 Console.Write("press any key to exit....");
  24.                 Console.ReadKey();
  25.             }
  26.         }
  27.         public static void Lanch(String domainUser, String file)
  28.         {
  29.             /**
  30.                 提权运行
  31.                 测试域local.domain用户test密码test
  32.             */
  33.             ProcessStartInfo psi = new ProcessStartInfo();
  34.             psi.Domain = "local.domain";
  35.             psi.UserName = "test";
  36.             psi.Password = ConvertToSecuretString("test");
  37.             psi.FileName = file;
  38.             psi.Arguments = domainUser;
  39.             psi.UseShellExecute = false;
  40.             Process p = new Process();
  41.             p.StartInfo = psi;
  42.             p.Start();
  43.         }
  44.         public static SecureString ConvertToSecuretString(String passWord)
  45.         {
  46.             /**
  47.                 加密密码字符串
  48.             */
  49.             if (passWord == null)
  50.                 throw new ArgumentNullException("passWord");
  51.             unsafe
  52.             {
  53.                 fixed (char* passwordChars = passWord)
  54.                 {
  55.                     SecureString securePassword = new SecureString(passwordChars, passWord.Length);
  56.                     securePassword.MakeReadOnly();
  57.                     return securePassword;
  58.                 }
  59.             }
  60.         }
  61.         public static void DeleteUserProfile(String domainUser)
  62.         {
  63.             /**
  64.                 删除用户文件夹
  65.             */
  66.             const String REG_PATH = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
  67.             const String USERS_FOLDER = "C:\\Users";
  68.             DirectoryInfo dir = new DirectoryInfo(USERS_FOLDER);
  69.             DirectoryInfo[] dirs = dir.GetDirectories();
  70.             foreach (DirectoryInfo d in dirs)
  71.             {
  72.                 if (d.Name != domainUser & d.Name != "adminad")
  73.                 {
  74.                     Console.WriteLine("{0} is deleting!", d.Name);
  75.                     Console.WriteLine(d.FullName);
  76.                     Console.ReadKey();
  77.                     d.Delete(true);
  78.                     DeleteProfileList(REG_PATH, d.FullName);
  79.                 }
  80.             }
  81.         }
  82.         public static bool DeleteProfileList(String profileList, String domainUser)
  83.         {
  84.             /**
  85.                 清理注册表
  86.             */
  87.             String subkey;
  88.             RegistryKey subReg;
  89.             RegistryKey key = Registry.LocalMachine;
  90.             RegistryKey myreg = key.OpenSubKey(profileList, true);
  91.             Console.WriteLine(profileList);
  92.             foreach (var k in myreg.GetSubKeyNames())
  93.             {
  94.                 Console.WriteLine("=========items=========");
  95.                 Console.WriteLine(k);
  96.                 Console.WriteLine("=========items=========");
  97.                 subkey = String.Format("{0}\\{1}", profileList, k);
  98.                 subReg = key.OpenSubKey(subkey);
  99.                 foreach (var sk in subReg.GetValueNames())
  100.                 {
  101.                     if (sk == "ProfileImagePath")
  102.                     {
  103.                         String ProfileImagePath = subReg.GetValue(sk).ToString();
  104.                         if (ProfileImagePath == domainUser)
  105.                         {
  106.                             Console.WriteLine(ProfileImagePath + "\n");
  107.                             myreg.DeleteSubKeyTree(k);
  108.                             return true;
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.             return false;
  114.         }
  115.     }
  116. }
复制代码

TOP

返回列表