Re: Do...Loop search execution problem
- From: "Matthew G" <mrguerreros@xxxxxxxxx>
- Date: 5 Mar 2007 23:33:39 -0800
On Feb 23, 3:18 am, "ThatsIT.net.au" <me@thatsit> wrote:
<mrguerre...@xxxxxxxxx> wrote in message
news:1172165584.233458.212680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi-
I've patched some code together for a script that will (hopefully)
delete an icon when the script detects that the cd the icon is linked
to is no longer in the drive. This is part of an HTA file I've created
for software support/installation.
Problem is that when the script loops that it doesn't actually search
again. I've tried playing with the placement of the do...loop stuff
but all I've succeeded in doing is getting the "loop without do"
error. The rest of the script works great but halfway isn't complete.
Here's the offending code...
this code needs to be in the loop, you need to reexecute the query to check
if the colFiles.Count = 0
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'autorun' " & _
"AND Extension = 'hta' AND Drive = '" & strDrive & "'")
start the loop with somthing like
dim aCount
aCount = 1
do until aCount = 0
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'autorun' " & _
"AND Extension = 'hta' AND Drive = '" & strDrive & "'")
aCount = colFiles.Count
' your code here
loop
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_CDROMDrive")
For Each objItem in colItems
strDrive = objItem.Drive
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'autorun' " & _
"AND Extension = 'hta' AND Drive = '" & strDrive & "'")
Do
Do While colFiles.Count = 1
wScript.Sleep 10000
If colFiles.Count = 0 Then
Exit Do
End If
Loop
Loop Until colFiles.Count = 0
Set fso = CreateObject("Scripting.FileSystemObject")
ThisDrive = fso.GetDriveName(currdir)
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strDesktop & "\cdrom.lnk")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)
Next
WScript.quit
Thanks for the help in advance
Thanks. I appreciate the help. immensely
.
- Prev by Date: Re: HTA - Mutliple questions about using WScript.Shell's Run Method and control.exe
- Next by Date: WMI - Printer Model
- Previous by thread: How to open a hta file so it runs in the current window
- Next by thread: WMI - Printer Model
- Index(es):
Relevant Pages
|