我正在使用 Windows XP,想创建一个批处理文件,删除除 和 之外的所有用户数据文件夹All Users
。Default User
我该如何实现?
答案1
首先,你不想在操作系统级别删除文件夹,而是应该使用删除行来实现这一点。其次,您无法删除当前登录用户的配置文件,因此计划将其作为计算机启动脚本运行,或者针对您知道已打开但当前没有用户登录的计算机远程运行它。
所以你需要看看此知识库文章这将为您提供所需的所有信息。您需要的特定命令如下:
delprof /q /i /c:computername
答案2
我为另一个有不同问题的用户写了这个,但它会按照你想要的方式运行(并且比你建议的删除用户文件夹要干净得多)。
这是一个 VBScript,因此只需将其保存为 .vbs 文件并双击即可。它会要求您输入要检查的 PC 的完全限定域名。然后它会列出该机器上的每个用户配置文件,并让您选择删除配置文件(以及用户文件夹)。
如果您遇到权限问题,请将 UserName =“” 和 Password =“” 行更改为对目标 PC 具有本地管理员权限的帐户。
Option Explicit
On Error Resume Next
Dim strComputer
Dim objWMIService
Dim propValue
Dim objItem
Dim SWBemlocator
Dim UserName
Dim Password
Dim colItems
Dim strMessage
Dim deleteResponse
strComputer = ""
UserName = ""
Password = ""
strMessage = ""
strComputer = InputBox("Please enter the FQDN of the new computer:")
If strComputer = "" Then
WScript.quit
End If
If Not Ping (strComputer) Then
MsgBox "The computer (" + strComputer + ") is not responding to ping - exiting"
WScript.quit
End if
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from Win32_UserProfile",,48)
For Each objItem in colItems
strMessage = ""
If not objItem.LastDownloadTime = "" Then
strMessage = strMessage + "LastDownloadTime: " & left(objItem.LastDownloadTime,8) + Chr(10) + Chr(13)
End If
If Not objItem.LastUploadTime = "" Then
strMessage = strMessage + "LastUploadTime: " & left(objItem.LastUploadTime,8) + Chr(10) + Chr(13)
End if
if not objItem.LastUseTime = "" then
strMessage = strMessage + "LastUseTime: " & left(objItem.LastUseTime,8) + Chr(10) + Chr(13)
End If
If Not objItem.Loaded = "" Then
strMessage = strMessage + "Loaded: " & objItem.Loaded + Chr(10) + Chr(13)
End If
If not objItem.LocalPath = "" then
strMessage = strMessage + "LocalPath: " & objItem.LocalPath + Chr(10) + Chr(13)
End If
if not objItem.RefCount = "" then
strMessage = strMessage + "RefCount: " & objItem.RefCount + Chr(10) + Chr(13)
End If
if not objItem.RoamingConfigured = "" then
strMessage = strMessage + "RoamingConfigured: " & objItem.RoamingConfigured + Chr(10) + Chr(13)
End If
if not objItem.RoamingPath = "" then
strMessage = strMessage + "RoamingPath: " & objItem.RoamingPath + Chr(10) + Chr(13)
End If
if not objItem.RoamingPreference = "" then
strMessage = strMessage + "RoamingPreference: " & objItem.RoamingPreference + Chr(10) + Chr(13)
End If
if not objItem.SID = "" then
strMessage = strMessage + "SID: " & objItem.SID + Chr(10) + Chr(13)
End If
if not objItem.Special = "" then
strMessage = strMessage + "Special: " & objItem.Special + Chr(10) + Chr(13)
End If
if not objItem.Status = "" then
strMessage = strMessage + "Status: " & objItem.Status + Chr(10) + Chr(13)
End If
strMessage = strMessage + Chr(10) + Chr(13) + Chr(10) + Chr(13) + "Do you wish to delete this profile?"
deleteResponse = MsgBox (strMessage,35,"Profile Found")
Select Case deleteResponse
Case 6
Err.Clear
objItem.Delete_
If Err.Number = 0 Then
MsgBox("Profile " & objitem.localpath & " on " & strComputer & " deleted")
Else
MsgBox("Profile " & objitem.localpath & " on " & strComputer & " NOT deleted - Is user logged in?")
End If
End Select
Next
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
else
Ping = True
end if
Next
End Function