yellowdog
(Starting to like KiXtart)
2011-03-08 02:47 PM
Loop to delete a file in all users profiles

Hello,

Problem: I have to suppress a file located in a particular directory for each user profile on the workstation.

What would look like that code ???

I have to loop on C:\Documents and Settings\%userprofile%\Application Data\ICAClient
and suppress a file for each user.

Thanks


eriqjaffe
(Hey THIS is FUN)
2011-03-08 03:51 PM
Re: Loop to delete a file in all users profiles

You could use the DirPlus() UDF to generate an array of the user profile directories and then just loop through that:


 Code:
$dir = dirplus("c:\documents and settings","/ad")

for each $thing in $dir
    if exist ($thing + "\Application Data\ICAClient\filename.ext"
        del $thing + "\Application Data\ICAClient\filename.ext"
    endif
next



yellowdog
(Starting to like KiXtart)
2011-03-08 04:47 PM
Re: Loop to delete a file in all users profiles

It sounds good to me, I'm gonna see if I can manage with it.

Thanks a lot eriqjaffe ;\)


yellowdog
(Starting to like KiXtart)
2011-03-08 05:46 PM
Re: Loop to delete a file in all users profiles

Everything is fine, thanks a lot for your help.............

NTDOCAdministrator
(KiX Master)
2011-03-13 08:04 AM
Re: Loop to delete a file in all users profiles

Another method of going through the profiles, would need to modify for any specific path.

 Code:
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')

Dim $ProfilesDirectory, $Profiles
If InGroup(@WKSTA+'\'+SidToName('S-1-5-32-544'))
  ;User has Admin rights so delete file from all profiles
  $ProfilesDirectory = ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList','ProfilesDirectory'))
  $Profiles = Dir ($ProfilesDirectory)
  While $Profiles <> '' And Len($ProfilesDirectory)>15
    If $Profiles
      If GetFileAttr($ProfilesDirectory+'\'+$Profiles+'\Local Settings\Temp') & 16
        If Len($ProfilesDirectory+'\'+$Profiles)>25
          If GetFileAttr($ProfilesDirectory+'\'+$Profiles+'\Local Settings\Temp') & 16
            ;DEL ($ProfilesDirectory+'\'+$Profiles+'\Local Settings\Temp','*.TMP')
            ;Untested code but gives the idea
          EndIf
        EndIf
      EndIf
    EndIf
    $Profiles = Dir ()
  Loop
Else
  ;User does not have Admin rights so only clean the users file
  Dim $CurrentUserTemp
  $CurrentUserTemp = ExpandEnvironmentVars(ReadValue('HKCU\Environment','TEMP'))
  ;Check and verify the path length is good and that the location exists
  If Len($CurrentUserTemp)>15
    If GetFileAttr($CurrentUserTemp) & 16
      ;DEL ($CurrentUserTemp,'*.TMP')
      ;Untested code but gives the idea
    EndIf
  EndIf
EndIf
Exit @ERROR