复制代码
- @echo off
- ::for /d %%i in (C:\Users\*) do if /i "%%~ni" neq "%username%" if /i "%%~ni" neq "adminad" rd /s /q "%%i"
- pause
复制代码
- using System;
- using System.Diagnostics;
- using System.Security;
- using System.IO;
- using Microsoft.Win32;
- /**
- author:ivor
- 提权调用自己然后按条件删除C:\\Users子文件夹 和 ProfileList 子项
- */
- namespace UpPrivilege
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (args.Length == 0)
- {
- Lanch(Environment.UserName, Environment.CommandLine);
- }
- else
- {
- DeleteUserProfile(args[0]);
- Console.Write("press any key to exit....");
- Console.ReadKey();
- }
- }
- public static void Lanch(String domainUser, String file)
- {
- /**
- 提权运行
- 测试域local.domain用户test密码test
- */
- ProcessStartInfo psi = new ProcessStartInfo();
- psi.Domain = "local.domain";
- psi.UserName = "test";
- psi.Password = ConvertToSecuretString("test");
- psi.FileName = file;
- psi.Arguments = domainUser;
- psi.UseShellExecute = false;
- Process p = new Process();
- p.StartInfo = psi;
- p.Start();
- }
- public static SecureString ConvertToSecuretString(String passWord)
- {
- /**
- 加密密码字符串
- */
- if (passWord == null)
- throw new ArgumentNullException("passWord");
- unsafe
- {
- fixed (char* passwordChars = passWord)
- {
- SecureString securePassword = new SecureString(passwordChars, passWord.Length);
- securePassword.MakeReadOnly();
- return securePassword;
- }
- }
- }
- public static void DeleteUserProfile(String domainUser)
- {
- /**
- 删除用户文件夹
- */
- const String REG_PATH = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
- const String USERS_FOLDER = "C:\\Users";
- DirectoryInfo dir = new DirectoryInfo(USERS_FOLDER);
- DirectoryInfo[] dirs = dir.GetDirectories();
- foreach (DirectoryInfo d in dirs)
- {
- if (d.Name != domainUser & d.Name != "adminad")
- {
- Console.WriteLine("{0} is deleting!", d.Name);
- Console.WriteLine(d.FullName);
- Console.ReadKey();
- d.Delete(true);
- DeleteProfileList(REG_PATH, d.FullName);
- }
- }
- }
- public static bool DeleteProfileList(String profileList, String domainUser)
- {
- /**
- 清理注册表
- */
- String subkey;
- RegistryKey subReg;
- RegistryKey key = Registry.LocalMachine;
- RegistryKey myreg = key.OpenSubKey(profileList, true);
- Console.WriteLine(profileList);
- foreach (var k in myreg.GetSubKeyNames())
- {
- Console.WriteLine("=========items=========");
- Console.WriteLine(k);
- Console.WriteLine("=========items=========");
- subkey = String.Format("{0}\\{1}", profileList, k);
- subReg = key.OpenSubKey(subkey);
- foreach (var sk in subReg.GetValueNames())
- {
- if (sk == "ProfileImagePath")
- {
- String ProfileImagePath = subReg.GetValue(sk).ToString();
- if (ProfileImagePath == domainUser)
- {
- Console.WriteLine(ProfileImagePath + "\n");
- myreg.DeleteSubKeyTree(k);
- return true;
- }
- }
- }
- }
- return false;
- }
- }
- }
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |