Script to find a file

Posted on 2011-10-26
Last Modified: 2012-06-27
I need a script to find a file located in the following location:

"C:\Documents and Settings\<username>\Application Data\Macromedia\Flash Player\\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe"

What I want is for a script to search a user's profile until it finds the "ciscounifiedaddin6x5.exe" file, when it does find it, I want it to call on an a program to run an installation. I know how to write a script that can do this if the file was located in the Program Files location or C:\ or C:\Windows or some other static location, but since user profile directories are of course different, how do I tell the script to scan a user profile's hidden Application Data location until it finds this file? I dont want the script to keep scanning even after it finds the  "ciscounifiedaddin6x5.exe", I just want it to keep scanning UNTIL it finds even just one of these files, and if so, run a program. Your help is greatly appreciated.

Thank you

Question by:the_ratzenator
    LVL 3

    Assisted Solution

    Below is a dos one liner that will do what you want. You need to paste it in to a text file to run it as I have written to be run from a file.

    This will enumerate all of the users in the directory and look specifically for the file in each users folder. If it finds it then it will run the file.

    I have tested this on my own system recreating a dummy file and using the path you provided and it works.
    FOR /F "usebackq delims=#" %%A IN (`Dir "%SystemDrive%\Documents and Settings" /b`) DO IF EXIST "%SystemDrive%\Documents and Settings\%%A\Application Data\Macromedia\Flash Player\\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe" "%SystemDrive%\Documents and Settings\%%A\Application Data\Macromedia\Flash Player\\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe"

    Open in new window

    LVL 6

    Accepted Solution

    strDir = "C:\Documents and Settings\"
    Set objDir = FSO.GetFolder(strDir)


    Sub getInfo(pCurrentDir)

    For Each aItem In pCurrentDir.Files
        If LCase(Right(Cstr(aItem.Name), 24)) = "ciscounifiedaddin6x5.exe" Then
          Set shell = CreateObject("WScript.Shell")
          shell.Run Chr(34) & aItem.Name & Chr(34), 1, false
       End If

    For Each aItem In pCurrentDir.SubFolders

    End Sub
    LVL 11

    Assisted Solution

    Clearly the 2 solutions above will work but I noticed you tagged AutoIT on this question, so just in case you wanted to use that:
    ;	If the script WILL run as the logged-in user whose profile you want to search, use this code
    If FileExists(@AppDataDir & "\Macromedia\Flash Player\\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe") Then
    ;	If the script WILL NOT run as the logged-in user whose profile you want to search, use this code
    #include <File.au3>
    $aFolderlist=_FileListToArray("C:\Documents and Settings\", "*", 2)
    For $i = 1 To $aFolderlist[0]
    	If FileExists("C:\Documents and Settings\" & $aFolderlist[$i] & "\Application Data\Macromedia\Flash Player\\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe") Then

    Open in new window


    Author Comment

    Sorry to respond so late. Gorby was right, they all worked great. Thanks alot for your help and for the many options you all have provided. I will give you all points.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In this article my aim is to list down the tools that are important for a Windows System Administrator (The Must Have!!) 1) The Basic: First of all the basics Ping, telnet, traceroute, whois net and netstat one must be familiar to these tools as…
    Communication between departments might not happen in two different languages, but they do exist in two different worlds. With different targets and performance goals the same phrase often means something completely different to each party. Learn ho…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now