Solved

What is wrong in this script?

Posted on 2011-03-21
11
408 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

19 Experts available now in Live!

Get 1:1 Help Now