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)
您可以使用net命令来执行此操作。
对于删除用户帐户。
\n\nnet user YourUsername /del\nRun Code Online (Sandbox Code Playgroud)\n\n对于添加。
\n\nnet user YourUserName YourPassword /add\nRun Code Online (Sandbox Code Playgroud)\n\n欲了解更多信息,请阅读How to Use the Net User Command。
有一个命令行工具可以执行此操作,调用Delprof2(Microsoft\xe2\x80\x99s 的非官方后继者)Delprof)。
用法:delprof2 [/l] [/u] [/q] [/p] [/r] [/c:[\\\\]<computername>] [/d:<days> [/ntuserini]] [/ed:<pattern>] [/id:<pattern>] [/i]
/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\nRun Code Online (Sandbox Code Playgroud)\n\nDelprof2 的实际示例,远程删除用户配置文件。
\n\ndelprof2.exe -c:192.168.175.129 -p \nRun Code Online (Sandbox Code Playgroud)\n\n
| 归档时间: |
|
| 查看次数: |
62089 次 |
| 最近记录: |