Page 1 of 1 1
Topic Options
#201716 - 2011-03-08 02:47 PM Loop to delete a file in all users profiles
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
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

Top
#201717 - 2011-03-08 03:51 PM Re: Loop to delete a file in all users profiles [Re: yellowdog]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
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



Edited by eriqjaffe (2011-03-08 03:53 PM)

Top
#201718 - 2011-03-08 04:47 PM Re: Loop to delete a file in all users profiles [Re: eriqjaffe]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
It sounds good to me, I'm gonna see if I can manage with it.

Thanks a lot eriqjaffe ;\)

Top
#201720 - 2011-03-08 05:46 PM Re: Loop to delete a file in all users profiles [Re: yellowdog]
yellowdog Offline
Starting to like KiXtart

Registered: 2005-06-14
Posts: 102
Everything is fine, thanks a lot for your help.............
Top
#201742 - 2011-03-13 08:04 AM Re: Loop to delete a file in all users profiles [Re: yellowdog]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 84 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.078 seconds in which 0.039 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org