从命令行删除用户配置文件 Windows 7

Sta*_*hod 5 windows-7 vbscript

我经常需要删除计算机上除两个帐户之外的所有用户配置文件。我想要一个可以为我执行此操作的脚本。

该脚本必须适用于 Windows 7。

公司政策使得下载和使用任何第三方实用程序变得困难,因此下载可以完成任务的工具不是一个可接受的替代方案。

目前我有一个执行其他相关功能的 vbscript,因此如果我可以在 VBscript 中执行此操作,那就太好了。如果有一种方法可以直接从 Windows 命令行执行此操作,那也可以,我可以从 VB 脚本中调用它。

我在网上查了一下,找不到使用 VBscript 或 Windows 7 默认安装的 microsoft cmdline 实用程序来执行此操作的方法。

有谁知道我该如何执行此操作?

小智 5

我想为其他可能希望在 Windows 10 中解决此问题的人提供更多最新的解决方案

看到 Microsoft 更喜欢 CIM 而不是 WMI,并且 win32_UserProfile 对象的 Delete() 方法被隐藏,人们可能会认为 @user318485 发布的方法可能会被删除或弃用。

以编程方式删除用户配置文件的最新方法是使用 PowerShell

Get-CimInstance -ClassName win32_UserProfile | Where-Object {$_.LocalPath -like "*username*"} | Remove-CimInstance
Run Code Online (Sandbox Code Playgroud)


std*_*err 1

您可以使用net命令来执行此操作。

\n\n

对于删除用户帐户。

\n\n
net user YourUsername /del\n
Run Code Online (Sandbox Code Playgroud)\n\n

对于添加。

\n\n
net user YourUserName YourPassword /add\n
Run Code Online (Sandbox Code Playgroud)\n\n

欲了解更多信息,请阅读How to Use the Net User Command

\n\n
\n\n

有一个命令行工具可以执行此操作,调用Delprof2(Microsoft\xe2\x80\x99s 的非官方后继者)Delprof)。

\n\n

用法:delprof2 [/l] [/u] [/q] [/p] [/r] [/c:[\\\\]<computername>] [/d:<days> [/ntuserini]] [/ed:<pattern>] [/id:<pattern>] [/i]

\n\n
   /l   List only, do not delete (what-if mode)\n   /u   Unattended (no confirmation)\n   /q   Quiet (no output and no confirmation)\n   /p   Prompt for confirmation before deleting each profile\n   /r   Delete local caches of roaming profiles only, not local profiles\n   /c   Delete on remote computer instead of local machine\n   /d   Delete only profiles not used in x days\n   /ntuserini\n        When determining profile age for /d, use the file NTUSER.INI\n        instead of NTUSER.DAT for age calculation\n   /ed  Exclude profile directories whose name matches this pattern\n        Wildcard characters * and ? can be used in the pattern\n        May be used more than once and can be combined with /id\n   /id  Include only profile directories whose name matches this pattern\n        Wildcard characters * and ? can be used in the pattern\n        May be used more than once and can be combined with /ed\n   /i   Ignore errors, continue deleting\n
Run Code Online (Sandbox Code Playgroud)\n\n

Delprof2 的实际示例,远程删除用户配置文件。

\n\n
delprof2.exe -c:192.168.175.129 -p \n
Run Code Online (Sandbox Code Playgroud)\n\n

在此输入图像描述

\n

  • net user YourUsername /del /domain 将帐户从域控制器中删除,这不是我想要的。我只想删除本地计算机上的配置文件数据。delprof2.exe 是第三方实用程序。公司政策使我很难使用任何第三方实用程序。 (6认同)
  • 它适用于本地帐户,但我正在尝试从属于域的帐户中删除存储在计算机上的配置文件数据。 (2认同)

归档时间:

查看次数:

62089 次

最近记录:

5 年,4 月 前