/build/static/layout/Breadcrumb_cap_w.png

Script to delete user files

how to Write a script to delete a file in C:\users\user_name\applicationdata\

and as well as in Xp C: Documents and setting \user_name\application data


0 Comments   [ + ] Show comments

Answers (5)

Posted by: jagadeish 11 years ago
Red Belt
2

For XP:

Step 1 : Find out the folder names that are present in "C:\Documents and Setting" folder

Step 2: Skip, Administrator,All Users, Default User

Step 3: Check whether the files/folders to be deleted are exist or not in remaining folders

Step 4: Delete the files/folder if they exist

Windows Vista/ 7

Step 1 : Find out the folder names that are present in "C:\Users" folder

Step 2: Skip Administrator,Public, Default

Step 3: Check whether the files/folders to be deleted are exist or not in remaining folder

Step 4: Delete the files/folder if they exist


Comments:
  • Write VBScript and keep it in custom action... - jagadeish 11 years ago
Posted by: piyushnasa 11 years ago
Red Belt
1

You will have to write a script with username variable to get from the logged on user and then run it in active setup rather than in MSI.

This will ensure that the right user id is picked up.

Also if you want to write a script inside MSI, then write a VBScript and make the package to repair through self heal by launch of advertised shortcut. In that case as well the right username variable will be picked up.

Posted by: SMal.tmcc 11 years ago
Red Belt
1

you can add a delete to their login script for a file by using variables

you can use %UserProfile% which points to {SystemDrive}:\Documents and Settings\{username} in XP and {SystemDrive}:\Users\{username} in windows 7

also %AppData% which points to {SystemDrive}:\Documents and Settings\{username}\Application Data in XP and {SystemDrive}:\Users\{username}\AppData\Roaming in windows 7

Posted by: Arminius 11 years ago
Second Degree Green Belt
1

We've got a script that does that.  Rather than writing it for each OS, I grab profile locations from the registry.  (If you can do that, that also helps with a bunch of other stuff as well...).  Ignore short SIDS (less than 20 characters) to skip service accounts.  Then pull from each SID where the profile is, detect if the directory is there, then process it.  If you use ActiveSetup to put this stuff there, delete the Active Setup main reg key from HKLM and use the above to locate the ntuser.dat file, load that into users/temp[SID] and remove the Active Setup key from there (in case you reinstall later and want to run ActiveSetup again...)  Also, check the allUsers account in case something is there. 


Comments:
  • Would you mind Sharing it here :D - rock_star 11 years ago
Posted by: rock_star 11 years ago
4th Degree Black Belt
1

Here is another way to do same :

 



Dim StrDocandSettings,strSysDrive
Dim aryUser
Dim fso
Dim WshShell, objShell
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject( "WScript.Shell" )
strSysDrive=objShell.ExpandEnvironmentStrings("%SystemDrive%")

If IsVista Then

Set StrDocandSettings = fso.getFolder(strSysDrive & "\users")


Set aryUser = StrDocandSettings.SubFolders



For Each strUserName in aryUser
If strUserName.name = "Public" Then
Else
If fso.FileExists(StrDocandSettings & "\" & strUserName.name & "\applicationdata\Filename.txt") Then
    fso.DeleteFile StrDocandSettings & "\" & strUserName.name & "\applicationdata\Filename.txt" , True
End If

End If
Next

Else
Set StrDocandSettings = fso.getFolder(strSysDrive & "\Documents and Settings")


Set aryUser = StrDocandSettings.SubFolders


For Each strUserName in aryUser

If strUserName.name = "All Users" Then

Else

If fso.FileExists(StrDocandSettings & "\" & strUserName.name & "\applicationdata\Filename.txt") Then
fso.DeleteFile StrDocandSettings & "\" & strUserName.name & "\applicationdata\Filename.txt" , True
End If

End If

Next

End If



 
Function IsVista
Dim WshShell, strVal
Set WshShell = CreateObject("WScript.Shell")
IsVista = False
On Error Resume Next
strVal = WshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProductName")
Err.Clear
On Error Goto 0
If Instr(LCase(strVal), "windows vista") > 0 Then
    IsVista = True
End If
If Instr(LCase(strVal), "windows 7") > 0 Then
    IsVista = True
End If
End Function


 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ