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

Comments

Please log in to comment

Community Chosen Answer

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

Answered 09/21/2012 by: jagadeish
Red Belt

  • Write VBScript and keep it in custom action...
Please log in to comment

Answers

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.

Answered 09/20/2012 by: piyushnasa
Red Belt

Please log in to comment
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

Answered 09/21/2012 by: SMal.tmcc
Red Belt

Please log in to comment
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. 

Answered 09/21/2012 by: Arminius
Second Degree Green Belt

  • Would you mind Sharing it here :D
Please log in to comment
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


Answered 10/02/2012 by: rock_star
Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity