VbScript to delete files
Hi All ,
I am looking for a Vbscript which can delete files from all user profiles present on the computer. Can anyone help me with that? Thanks in advance
I am looking for a Vbscript which can delete files from all user profiles present on the computer. Can anyone help me with that? Thanks in advance
0 Comments
[ + ] Show comments
Answers (8)
Please log in to answer
Posted by:
jan thielemans
17 years ago
I have a script that first looks in the registry for a list of the profiles on the pc, then they are removed from the registry and also the files under documents and settings will be removed. (Except from the user who is working on that computer), so it also works for remote computers as well for the local computer
Posted by:
msi_learner
17 years ago
Posted by:
jan thielemans
17 years ago
So,
give it a try
(the script connects to \\computer\c$ as the v-drive)
Jan
' this script removes the cached profiles on a pc
' use : in doswindow : cscript verwijderprofiles.vbs computername
' *******************************************************************
'On Error Resume Next
' om te connecteren met de registry
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = wscript.Arguments.Item(0)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(shutdown)}!\\" _
& strComputer & "\root\cimv2")
Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
' koppelen van de c-schijf (v)
Set objShell = CreateObject("Wscript.Shell")
Set objNetwork = Wscript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "v:","\\" & strComputer & "\c$"
wscript.echo " v-schijf is gekoppeld"
'zoeken in registry naar info over profiles
For Each objSubkey In arrSubkeys
if left(objsubkey,8) ="S-1-5-21" then
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
gebruiker = Split(strValue,"\")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
if colcomputer.count = 0 then
wie = ""
else
For Each objComputer in colComputer
if isnull(objcomputer.username) then
wie = ""
else
wie = objcomputer.username
wie = Right(wie,len(wie)-5)
wscript.echo wie & " is ingelogd op " & strComputer
end if
Next
end if
if gebruiker(2) <> wie and left(gebruiker(2),10) <> "Administra" then
objRegistry.DeleteKey HKEY_LOCAL_MACHINE,strSubPath,strValueName
wscript.Echo gebruiker(2) & " wordt verwijderd"
' objShell.Run ("%comspec% /c rmdir /s/q \\" & strComputerv & "\c$\Docume~1\" & gebruiker(2)&""),0,TRUE
objShell.Run ("%comspec% /c rmdir /s/q v:\Docume~1\" & gebruiker(2)&""),0,TRUE
' objShell.Run ("%comspec% /c rmdir /s/q '%\\" & strComputer & "\c$\Documents and settings\" & gebruiker(2)& "%'"),0,TRUE
end if
end if
Next
objNetwork.RemoveNetworkDrive "v:"
'wscript.Echo " v-schijf is ontkoppeld"
give it a try
(the script connects to \\computer\c$ as the v-drive)
Jan
' this script removes the cached profiles on a pc
' use : in doswindow : cscript verwijderprofiles.vbs computername
' *******************************************************************
'On Error Resume Next
' om te connecteren met de registry
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = wscript.Arguments.Item(0)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(shutdown)}!\\" _
& strComputer & "\root\cimv2")
Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
' koppelen van de c-schijf (v)
Set objShell = CreateObject("Wscript.Shell")
Set objNetwork = Wscript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "v:","\\" & strComputer & "\c$"
wscript.echo " v-schijf is gekoppeld"
'zoeken in registry naar info over profiles
For Each objSubkey In arrSubkeys
if left(objsubkey,8) ="S-1-5-21" then
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue
gebruiker = Split(strValue,"\")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
if colcomputer.count = 0 then
wie = ""
else
For Each objComputer in colComputer
if isnull(objcomputer.username) then
wie = ""
else
wie = objcomputer.username
wie = Right(wie,len(wie)-5)
wscript.echo wie & " is ingelogd op " & strComputer
end if
Next
end if
if gebruiker(2) <> wie and left(gebruiker(2),10) <> "Administra" then
objRegistry.DeleteKey HKEY_LOCAL_MACHINE,strSubPath,strValueName
wscript.Echo gebruiker(2) & " wordt verwijderd"
' objShell.Run ("%comspec% /c rmdir /s/q \\" & strComputerv & "\c$\Docume~1\" & gebruiker(2)&""),0,TRUE
objShell.Run ("%comspec% /c rmdir /s/q v:\Docume~1\" & gebruiker(2)&""),0,TRUE
' objShell.Run ("%comspec% /c rmdir /s/q '%\\" & strComputer & "\c$\Documents and settings\" & gebruiker(2)& "%'"),0,TRUE
end if
end if
Next
objNetwork.RemoveNetworkDrive "v:"
'wscript.Echo " v-schijf is ontkoppeld"
Posted by:
jmcfadyen
17 years ago
Posted by:
jan thielemans
17 years ago
Posted by:
msi_learner
17 years ago
Posted by:
jmcfadyen
17 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.