Solved

What is wrong in this script?

Posted on 2011-03-21
11
420 Views
Last Modified: 2012-05-11
What is wrong in this script?

 set s=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='iexplore.exe'"
set q=s.execquery(sQuery)
 
msgbox "Maintenance: Close Internet Explorer bla bla bla."
 
Do until q.count=0
    wscript.sleep 5000
    set q=s.execquery(sQuery)
    msgbox "still open please close..."
Loop
msgbox "Internet Explorer closed, thanks. Starting to update, have a nice day!"

Set WshShell = WScript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
end if

Open in new window


Thanks a lot
hopeleonie  error
0
Comment
Question by:*** Hopeleonie ***
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 2

Assisted Solution

by:michael_madsen
michael_madsen earned 25 total points
ID: 35180244
You don't need "end if" in line 17 since you don't have any if statement
0
 
LVL 10

Assisted Solution

by:gavsmith
gavsmith earned 25 total points
ID: 35180256
Is that the whole script? if so line '17: end if ' shouldn't be there, as there isn't any starting 'IF' statement.

Regards
Gav
0
 
LVL 2

Assisted Solution

by:ghemstrom
ghemstrom earned 75 total points
ID: 35180277
the line 17 includes two statements: end, that ends the script, and if, that assumes that you have a condition and at least one statement.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
Angelgeo earned 375 total points
ID: 35180351

set s=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='iexplore.exe'"
set q=s.execquery(sQuery)

If q.Count > 0 Then 
msgbox "Maintenance: Close Internet Explorer bla bla bla."
 
Do until q.count=0
    wscript.sleep 5000
    set q=s.execquery(sQuery)
    msgbox "still open please close..."
Loop
msgbox "Internet Explorer closed, thanks. Starting to update, have a nice day!"

Set WshShell = WScript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
end if

Open in new window

0
 
LVL 19

Author Comment

by:*** Hopeleonie ***
ID: 35183827
@michael_madsen, gavsmith and ghemstrom
yes this is the whole script. why does angelgeo's code working "with end if" ?

@Angelgeo
your solution worked
0
 
LVL 2

Assisted Solution

by:ghemstrom
ghemstrom earned 75 total points
ID: 35184363
Because he added the condition that q had to be greater than 0, which is really unnecessary becaus the do until takes care of that - just take away the concluding if and the script will work, won´t it?
0
 
LVL 19

Author Comment

by:*** Hopeleonie ***
ID: 35184384
Hi ghemstrom

How would the code looks then?
0
 
LVL 2

Assisted Solution

by:ghemstrom
ghemstrom earned 75 total points
ID: 35184433
You just drop the last if from your code
0
 
LVL 5

Expert Comment

by:Angelgeo
ID: 35186847
Hi hopeleonie

I Add "If q.Count > 0 Then " on Line 8
for check for check is running "Internet Explorer" or no.
befor say "Close Internet Explorer bla bla"

this script is more correct


set s=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='iexplore.exe'"
set q=s.execquery(sQuery)

If q.Count > 0 Then 
msgbox "Maintenance: Close Internet Explorer bla bla bla."
end if
 
Do until q.count=0
    wscript.sleep 5000
    set q=s.execquery(sQuery)
    msgbox "still open please close..."
Loop
msgbox "Internet Explorer closed, thanks. Starting to update, have a nice day!"

Set WshShell = WScript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Open in new window

0
 
LVL 5

Assisted Solution

by:Angelgeo
Angelgeo earned 375 total points
ID: 35186877
or you can delete the last line, as said : michael_madsen, hopeleonie

and change msgbox

set s=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='iexplore.exe'"
set q=s.execquery(sQuery)

Do until q.count=0
    wscript.sleep 5000
    set q=s.execquery(sQuery)
    msgbox "Internet Explorer is open please close..."
Loop
msgbox "Internet Explorer closed, thanks. Starting to update, have a nice day!"

Set WshShell = WScript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Open in new window

0
 
LVL 19

Author Closing Comment

by:*** Hopeleonie ***
ID: 35187563
Thank you to all!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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