Dogfundays
11th April 2008 16:16 UTC
search users for folder and delete it
Hi, I have a folder that may be under any user in c:\Documents and Settings. I am looking for a way that searches for this folder and then deletes it.
I have searched the web and found oneway that you need VB but I can't use VB here. Any ideas?
Thanks for your time,
Daniel James
11th April 2008 17:46 UTC
Re: search users for folder and delete it
Originally posted by Dogfundays
Hi, I have a folder that may be under any user in c:\Documents and Settings. I am looking for a way that searches for this folder and then deletes it.
Have you looked at the
Locate function in FileFuncs.nsh? You can use that to search for the directory, and then delete it with RmDir in the callback.
There's also a 'Locate' plug-in, which you may or may not prefer.
Dogfundays
11th April 2008 18:59 UTC
Thanks I'm looking into it now.
Afrow UK
11th April 2008 19:16 UTC
Might be easier to use EnumRegKey to look at users in HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList
Also, I would not hard code C:\Documents and Settings as it may be different. Read from HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList ProfilesDirectory to get the path set for the machine.
Use ExpandEnvStrings on results.
You could also get the Documents and Settings path and locate the directories using FindFirst, FindNext, FindClose (IMO using Locate is a little bit much if you just want to locate a sub-directory under these folders).
Stu
Daniel James
13th April 2008 18:32 UTC
Originally posted by Afrow UK
Might be easier to use EnumRegKey to look at users in HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList
You're right :o I misread the question (as "a folder that may be under any
folder in c:\Documents and Settings").
Also, I would not hard code C:\Documents and Settings as it may be different. Read from HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList ProfilesDirectory to get the path set for the machine.
Yes. $PROFILE will get the right directory name for the machine, but your way is still probably easier.
You could also get the Documents and Settings path and locate the directories using FindFirst, FindNext, FindClose (IMO using Locate is a little bit much if you just want to locate a sub-directory under these folders).
I'm not so sure about that ... You need to find each user's home directory and then look inside it for the named directory that you want to delete. Locate does it in one hit, but requires a callback. Not much to choose between them, I'd say (though using the registry is easier).
Locate is certainly the easiest way if you're looking for a directory with a given name that you know is at some arbitrary location in the tree but you don't know where or at what depth (which is how I misread the question).
Dogfundays
14th April 2008 14:54 UTC
This is the path that we are trying to locate.
C:\Documents and Settings\%Users%\Dir
Once we find the directory we would like to delete it the problem is the searching for the directory I have tried locate but I do not have a good handle on it.
One problem is I'm new to NISI and the learning curve is getting in the way.
Thanks for the help,
Dogfundays
14th April 2008 19:13 UTC
Here is what I have so far. The problem is that it will not find the directory but will find everything inside the dir that has an extension (${Locate} "C:\" "D=1 /L=F /M=AutoShutdown.* /S=1K") The AutoShutdown I have tried with and with out the .*
Does anyone see the problem?
Name "Output"
OutFile "Output.exe"
!include "FileFunc.nsh"
!insertmacro Locate
Section
${Locate} "C:\" "D=1 /L=F /M=AutoShutdown.* /S=1K" "remove"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0=$R0"
SectionEnd
Function remove
# $R9="C:\Documents and Settings\%Users%\AutoShutdown"
# $R8="C:\"
# $R7="c:\AutoShutdown"
# $R6="5"
StrCpy $R0 $R9
Delete '$R0$\n$\nFind next' +2
;MessageBox MB_YESNO '$R0$\n$\nFind next?' IDYES +2
StrCpy $0 StopLocate
Push $0
FunctionEnd