Solved

Open Special Browser Window with VBScript from Desktop Shortcut

Posted on 2008-10-13
9
1,628 Views
Last Modified: 2013-12-04
I know nothing about VBScript, so please show me in detail.  

For an online application, I'm trying to use the VBScript found in http:Q_23223204.html to open a special browser window (without scroll bars, address bar, menu bar, etc.) of Internet Explorer -- and I'm trying to run the VBscript from a desktop shortcut icon.

I only got as far as trying to test the script from the Win Run command using   Run:   wscript c:\scripts\openIE.vbs .
In doing so, I found the script itself has an "unspecified error."

Besides fixing that error, I also need to know how to run the script from a desktop shortcut icon.
Option Explicit
Dim oIE
Dim cURL
Const cHost = "http://www.example.com"
Const cPath = "/index.html"
Const cParms = "?wwidth=780&wheight=580"
 
cURL = cHost & cPath & cParms
Set oIE = CreateObject("internetexplorer.application")
oIE.Height = 241
oIE.Width = 400
oIE.Top = 222
oIE.Left = 250
oIE.MenuBar = False
oIE.ToolBar = False
oIE.StatusBar= True
oIE.Resizable = False
oIE.AddressBar= False
oIE.Navigate2 cURL
oIE.Document.Body.Scroll = "no"
oIE.Visible = True

Open in new window

0
Comment
Question by:FrankTech
[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
  • 5
  • 2
  • 2
9 Comments
 
LVL 3

Accepted Solution

by:
drbayer earned 200 total points
ID: 22704657
I don't know how to suppress the scroll bar, but I can fix the error you're getting.  Add the following code immediately after the Navigate command - it will force the script to wait until IE can accept more commands before continuing.

Also - to launch this from a desktop shortcut, create a shortcut pointing to the following:
wscript c:\path\to\script\myscript.vbs

If there are spaces in the path name, you may need to quote the path.
While Not oIE.ReadyState = 4
  Wscript.Sleep 100
Wend

Open in new window

0
 

Author Comment

by:FrankTech
ID: 22704779
drbayer,
   That's great!  But the IE window is not coming into focus. The desktop remains in view, while the IE window is just minimal (minimized) in the taskbar. How can the script be modified to make the IE window open maximized in focus?
0
 
LVL 50

Assisted Solution

by:Dave Brett
Dave Brett earned 200 total points
ID: 22705449
you can use the availheight propert, see below

This code creates a shortcut called myvbs on your desktop if it doesn't already exist. It points to the script being saved as "c:\myvbs.vbs" so you will need to adapt for you use

Cheers

Dave
Dim oIE, oShellLink, StrMyDesktop
 
Dim cURL, WshShell, Fso
Const cHost = "http://www.example.com"
 
cURL = cHost
Set oIE = CreateObject("internetexplorer.application")
With oIE
    .MenuBar = False
    .Toolbar = False
    .StatusBar = True
    .AddressBar = False
    .Navigate cURL
    While Not oIE.ReadyState = 4
        Wscript.Sleep 100
    Wend
    .document.Body.Scroll = "no"
    .Width = .document.parentwindow.screen.availWidth
    .Height = .document.parentwindow.screen.availHeight
    .Visible = True
End With
 
Set WshShell = Wscript.CreateObject("Wscript.Shell")
StrMyDesktop = WshShell.SpecialFolders("Desktop")
Set Fso = CreateObject("scripting.filesystemobject")
If Fso.fileexists(StrMyDesktop & "\" & "myvbs.lnk") = False Then
    Set oShellLink = WshShell.CreateShortcut(StrMyDesktop & "\myvbs.lnk")
    oShellLink.TargetPath = "C:\myvbs.vbs"
    oShellLink.IconLocation = "notepad.exe, 0"
    oShellLink.Description = "Shortcut to this script"
    oShellLink.Save
    Set oShellLink = Nothing
End If
Set Fso = Nothing
Set WshShell = Nothing

Open in new window

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 3

Assisted Solution

by:drbayer
drbayer earned 200 total points
ID: 22705458
To bring the IE window to the front - add the following to the end of the script:
Dim oDoc, oShell
Set oDoc = oIE.Document
Set oShell = CreateObject("Wscript.Shell")
oShell.AppActivate oDoc.Title

Open in new window

0
 

Author Comment

by:FrankTech
ID: 22705569
drbayer,
   Thanks!   I changed   oIE.Document  to ie.Document  in the second line because it threw an error about the oIE.
   With that change, it does open in focus sometimes, but not always.  For example:

Scenario 1
   a) if some other window or other application has focus
   b) then I go to the desktop and click the shortcut,
   c) it only "opens" minimized (flashing in the taskbar)

However, if I do this:
  Scenario 2
    a) open the page from the desktop shortcut
    b) close the page
    c) open it from the shortcut again
    d) then it opens in view with the focus

How can we make it open up, visibly and in focus, all the time even in Scenario 1 above?
0
 

Author Comment

by:FrankTech
ID: 22705690
brettdj,
   Thanks for the code to fill the screen.  However, it does not make the window receive focus.  It opens minimized in the taskbar.  
    drbayer gave me some code to activate the window (see above); maybe you could comment on how to incorporate that idea into your script and how to fix the issue that I mentioned above (it receives focus only sometimes with that method).
0
 
LVL 50

Assisted Solution

by:Dave Brett
Dave Brett earned 200 total points
ID: 22705864
hmmm .. my machine is setting focus.

I did find this on the focus issue, worth looking at
http://www.tek-tips.com/viewthread.cfm?qid=950036&page=6

You may need to reset the left and top properties as well, if so see below

Cheers

Dave

.
'in place of 
document.Body.Scroll = "no"
    .Width = .document.parentwindow.screen.availWidth
    .Height = .document.parentwindow.screen.availHeight
    .Visible = True
 
'try
document.Body.Scroll = "no"
    .Left=0
    .Top=0
    .Width = .document.parentwindow.screen.availWidth
    .Height = .document.parentwindow.screen.availHeight
    .Visible = True

Open in new window

0
 

Author Comment

by:FrankTech
ID: 22705987
brettdj,
   Thanks for the left and top settings.  
   With the focus issue, what's happening is: clicking the shortcut pops up the browser with focus IF that window is the most-recently viewed (but then closed) window.
   But if some other application or window was viewed more recently, then clicking the shortcut does not pop up the browser with focus; it only flashes in the taskbar.
    I read the article you linked, and apparently it's an XP problem and the suggested fix would not actually solve it. I guess there is no solution.
   But I'll hold the question open for a while in case someone else might have some ideas.
0
 

Author Comment

by:FrankTech
ID: 22707394
I'm going to increase and split the points between the two experts here, since they both answered my original question (although the follow-up about focusing the new window, may not have any possible solution).  Thanks, drbayer and brettdj.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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