如何使用C#删除Windows用户帐户文件夹?

时间:2022-04-13 16:46:33

I have application which creates some windows user accounts, on uninstallation I remove the Windows User Account, but the folder for that user remains there (For example C:\Documents and Settings\UserName\"

我有应用程序创建一些Windows用户帐户,在卸载时我删除了Windows用户帐户,但该用户的文件夹仍然存在(例如C:\ Documents and Settings \ UserName \“

How can I remove that folder using C#?

如何使用C#删除该文件夹?

Thanks,

1 个解决方案

#1


Something along the lines of this?

有什么东西沿着这个?

DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
dir = dir.Parent.Parent.Parent;
DirectoryInfo[] userDirs = dir.GetDirectories(userName);

foreach (DirectoryInfo userDir in userDirs)
{
    userDir.Delete(true);
}

#1


Something along the lines of this?

有什么东西沿着这个?

DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
dir = dir.Parent.Parent.Parent;
DirectoryInfo[] userDirs = dir.GetDirectories(userName);

foreach (DirectoryInfo userDir in userDirs)
{
    userDir.Delete(true);
}