Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to find a file

Posted on 2011-10-26
4
Medium Priority
?
587 Views
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\www.macromedia.com\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

0
Comment
Question by:the_ratzenator
4 Comments
 
LVL 3

Assisted Solution

by:Hobett
Hobett earned 664 total points
ID: 37033682
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\www.macromedia.com\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe" "%SystemDrive%\Documents and Settings\%%A\Application Data\Macromedia\Flash Player\www.macromedia.com\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe"

Open in new window

0
 
LVL 6

Accepted Solution

by:
morpheios earned 668 total points
ID: 37033760
strDir = "C:\Documents and Settings\"
Set objDir = FSO.GetFolder(strDir)

getInfo(objDir)

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
      WScript.Quit
   End If
Next

For Each aItem In pCurrentDir.SubFolders
   getInfo(aItem)
Next

End Sub
0
 
LVL 11

Assisted Solution

by:TheGorby
TheGorby earned 668 total points
ID: 37059225
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\www.macromedia.com\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe") Then
	Run("C:\Path\RunTheInstallation.exe")
	Exit
EndIf
;-------------------------------------------------------------------------------------------
;	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\www.macromedia.com\bin\ciscounifiedaddin6x5\ciscounifiedaddin6x5.exe") Then
		Run("C:\Path\RunTheInstallation.exe")
		Exit
	EndIf
Next

Open in new window

0
 

Author Comment

by:the_ratzenator
ID: 37096219
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.
0

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Introducing Priority Question, our latest feature.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month20 days, 22 hours left to enroll

810 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