Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

What is wrong in this script?

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
*** Hopeleonie ***
Asked:
*** Hopeleonie ***
  • 3
  • 3
  • 3
  • +2
7 Solutions
 
michael_madsenCommented:
You don't need "end if" in line 17 since you don't have any if statement
0
 
gavsmithCommented:
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
 
ghemstromCommented:
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
AngelgeoCommented:

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
 
*** Hopeleonie ***IT ManagerAuthor Commented:
@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
 
ghemstromCommented:
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
 
*** Hopeleonie ***IT ManagerAuthor Commented:
Hi ghemstrom

How would the code looks then?
0
 
ghemstromCommented:
You just drop the last if from your code
0
 
AngelgeoCommented:
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
 
AngelgeoCommented:
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
 
*** Hopeleonie ***IT ManagerAuthor Commented:
Thank you to all!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now