创build一个batch file,删除所有用户和默认用户以外的所有用户数据文件夹?

我正在使用Windows XP,并希望创build一个batch file,删除All UsersDefault User以外的所有用户数据文件夹。 我怎样才能做到这一点?

首先,你不想删除操作系统级别的文件夹,而应该使用delprof来完成这个任务。 其次,您不能删除当前login的用户的configuration文件,因此计划将其作为计算机启动脚本来运行,或者在您已知的计算机上远程运行,但没有当前login的用户。

所以你需要看看这个知识库文章 ,这将提供你所需要的所有信息。 你想要的具体命令将是这样的:

 delprof /q /i /c:computername 

我为另一个用户写了一个不同的问题,但它会做你想做的(并且比你刚刚删除用户文件夹的build议更清洁)。

这是一个VBScript,所以只需保存为一个.vbs文件并双击。 它会要求您要检查的PC的完全合格的域名。 然后,它会列出该机器上的每个用户configuration文件,并让您select删除configuration文件(以及用户文件夹)。

如果您遇到权限问题,请将UserName =“”和Password =“”行更改为对目标PC具有本地pipe理权限的帐户。

 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