Solved

What is wrong in this script?

Posted on 2011-03-21
11
400 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
  • 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
 
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 18

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 18

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 18

Author Closing Comment

by:hopeleonie
ID: 35187563
Thank you to all!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

18 Experts available now in Live!

Get 1:1 Help Now