?
Solved

VBS TO CLOSE APPS AND THEN OPEN IMAGE

Posted on 2014-08-15
4
Medium Priority
?
294 Views
Last Modified: 2014-08-21
Trying to get this vbs to close all apps, but then open an image at end.   Everything closes just fine, except it doesn't open the image

Any idea how to work around it?

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim xComputer, xProcessKill, xProcessKill2, xProcessKill3, xProcessKill4, xProcessKill5, xProcessKill6, xProcessKill7, xProcessKill8, xProcessKill9, xProcessKill10
xComputer = "."
xProcessKill = "'excel.exe'"
xProcessKill2 = "'outlook.exe'"
xProcessKill3 = "'winword.exe'"
xProcessKill4 = "'powerpnt.exe'"
xProcessKill5 = "'onenote.exe'"
xProcessKill6 = "'iexplore.exe'"
xProcessKill7 = "'notepad.exe'"
xProcessKill8 = "'wordpad.exe'"
xProcessKill9 = "'mstsc.exe'"
xProcessKill10 = "'wfica32.exe'"

 
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& xComputer & "\root\cimv2") 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill2)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next 
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill3)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill4)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill5)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill6)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill7)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next
 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill8)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill9)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & xProcessKill10)
On Error Resume Next
For Each objProcess in colProcess
objProcess.Terminate()
Next

--- OPEN IMAGE HERE
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
    .Navigate "about:blank"
    .Visible = 1
    .Document.Title = "Show Image"
    .Toolbar=False
    .Statusbar=False
    .Top=1400
    .Left=1400
    .Height=900
    .Width=700
    .Document.Body.InnerHTML = "<img src='\\EPICAZO\PersonalWork\DOWNTIME FLYER 08182014 V1_SM.png'>"
End With

OR

CreateObject("WScript.Shell").Run "\\EPICAZO\PersonalWork\DOWNTIME FLYER 08182014 V1_SM.png"

Open in new window

0
Comment
Question by:epicazo
  • 2
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 1500 total points
ID: 40263930
The path contains spaces. To use the Run method, you need to enclose the path in double quotes:  
CreateObject("WScript.Shell").Run """\\EPICAZO\PersonalWork\DOWNTIME FLYER 08182014 V1_SM.png"""

Open in new window

For the HTML, you need to encode spaces with %20:
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
    .Navigate "about:blank"
    .Visible = 1
    .Document.Title = "Show Image"
    .Toolbar=False
    .Statusbar=False
    .Top=1400
    .Left=1400
    .Height=900
    .Width=700
    .Document.Body.InnerHTML = "<img src='\\EPICAZO\PersonalWork\DOWNTIME%20FLYER%2008182014%20V1_SM.png'>"
End With

Open in new window

0
 

Author Comment

by:epicazo
ID: 40264060
oBdA, it doesn't open the image
0
 
LVL 85

Expert Comment

by:oBdA
ID: 40264267
What happens when you open a command prompt and enter
start "" "\\EPICAZO\PersonalWork\DOWNTIME FLYER 08182014 V1_SM.png"

Open in new window

If this doesn't show the picture, then either the path is incorrect, or .png is not associated with a program.
0
 

Author Closing Comment

by:epicazo
ID: 40277118
thank you and sorry for the delay.   I was pulled into another project.    The CreateObject("WScript.Shell").Run """\\EPICAZO\PersonalWork\DOWNTIME FLYER 08182014 V1_SM.png""" work fine, what doesn't work is the one to open in IE.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

862 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