Looking for some help with Vbscript
Hi
I'm Looking for somehelp with a VBscript.
My Scenario:-
We have some 500 machines on which users have a folder {ex: game} which has sub folders and files in it. I'm looking for script which will search for Executable game.exe in the 'game' folder and if located delete the "game" folder and subfolders and files in it.
so the problem is this folder is not in a fixed location. I mean it can be any where in the C drive and also the name of the 'game' folder is different on some machines.
I have found a script to search for this game.exe and delete if found but i want to delete the entire directory of game.exe
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
find_file "game","exe"
Function find_file(filename, extension)
Set colItems = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Drive = 'C:' AND FileName='" & filename & "' AND Extension='" & extension & "'",,48)
For Each objItem in colItems
WScript.Echo "Found " & objItem.Name & " in " & objItem.Drive & objItem.Path
objItem.Delete
Next
End Function
Any help is much appreciated and thank you for your time.
Thanks
I'm Looking for somehelp with a VBscript.
My Scenario:-
We have some 500 machines on which users have a folder {ex: game} which has sub folders and files in it. I'm looking for script which will search for Executable game.exe in the 'game' folder and if located delete the "game" folder and subfolders and files in it.
so the problem is this folder is not in a fixed location. I mean it can be any where in the C drive and also the name of the 'game' folder is different on some machines.
I have found a script to search for this game.exe and delete if found but i want to delete the entire directory of game.exe
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
find_file "game","exe"
Function find_file(filename, extension)
Set colItems = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Drive = 'C:' AND FileName='" & filename & "' AND Extension='" & extension & "'",,48)
For Each objItem in colItems
WScript.Echo "Found " & objItem.Name & " in " & objItem.Drive & objItem.Path
objItem.Delete
Next
End Function
Any help is much appreciated and thank you for your time.
Thanks
0 Comments
[ + ] Show comments
Answers (5)
Please log in to answer
Posted by:
dchristian
13 years ago
Posted by:
acidburn777
13 years ago
Posted by:
acidburn777
13 years ago
Posted by:
anonymous_9363
13 years ago
Like so much script which you find, this has zero error-trapping (a hobby-horse of mine, in case anyone hadn't noticed).
For example, there's no check to see if the file actually got deleted. In your case, you should add a check that makes sure the folder gets deleted. Once you're more proficient, you'll get into the habit of error-trapping EVERYTHING. Essentially, any program must assume that NOTHING will work, including creation of popular objects e.g FileSystemObject.
For example, there's no check to see if the file actually got deleted. In your case, you should add a check that makes sure the folder gets deleted. Once you're more proficient, you'll get into the habit of error-trapping EVERYTHING. Essentially, any program must assume that NOTHING will work, including creation of popular objects e.g FileSystemObject.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.