Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-20-2017, 02:13 PM
pfletch pfletch is offline
Registered User
 
Join Date: Nov 2013
Posts: 12
Windows 10 IE custom dialog

Hi, we have several VBScripts that use the IE object to create custom dialogs, after a recent upgrade to Windows 10 the IE dialog does not open to the foreground, its always behind the SecureCRT window.

Here is the example script from the scripting essentials pdf that has the same issue in Windows 10

Code:
'# $language = "VBScript"
' $interface = "1.0"

szHTMLBody = "<font color='red'><b>Specify username and password:</b></font>" & _
    "<hr>" & _
    "<b><u>U</u>sername:</b>" & _
    "<input name='Username' size='40' maxlength='512' AccessKey='u'>" & _
    "<br>" & _
    "<b><u>P</u>assword:</b>" & _
    "<input type=password name='Password' size='40' maxlength='512' " & _
        "AccessKey='p'>" & _
    "<hr>" & _
    "<button name='OK' AccessKey='O' " & _
        "Onclick=document.all('ButtonHandler').value='OK';>" & _
        "<u>O</u>K</button>" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;" & _
    "<button name='Cancel' AccessKey='c' " & _
        "Onclick=document.all('ButtonHandler').value='Cancel';>" & _
        "<u>C</u>ancel</button>"& _
    "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>"


Dim g_objIE

' First step, set up the dialog (InternetExplorer)
Set g_objIE = CreateObject("InternetExplorer.Application")
g_objIE.Offline = True
g_objIE.navigate "about:blank"

' This loop is required to allow the IE object to finish loading...
Do
    crt.Sleep 100
Loop While g_objIE.Busy

' Make the custom dialog font to look more like standard Windows dialogs
g_objIE.Document.body.Style.FontFamily = "Sans-Serif"

' Here's where we "create" the elements of our dialog box. We basically
' throw HTML into the document, and IE loads it in real-time for us.
' 
' The hidden "ButtonHandler" input is used to tie IE and
' SecureCRT together such that SecureCRT can know when a
' button is pressed, etc.
g_objIE.Document.Body.innerHTML = szHTMLBody

' Prevent the MenuBar, StatusBar, AddressBar, and Toolbar from being
' displayed as part of the IE window
g_objIE.MenuBar = False
g_objIE.StatusBar = False
g_objIE.AddressBar = False
g_objIE.Toolbar = False

' Set the initial size of the IE Window
g_objIE.height = 200
g_objIE.width = 450

g_objIE.document.Title = "Authentication Credentials Prompt"
g_objIE.Visible = True

' This loop is required to allow the IE window to fully display.
Do
    crt.Sleep 100

Loop While g_objIE.Busy

' This code brings the IE window to the foreground.
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate g_objIE.document.Title

' Once the dialog is displayed and has been brought to the foreground, 
' set focus on the control of our choice...
g_objIE.Document.All("Username").Focus

Do
    ' If the user closes the IE window by Alt+F4 or clicking on the 'X'
    ' button, we'll detect that here, and exit the script if necessary.
    On Error Resume Next
        Err.Clear
        szNothing = g_objIE.Document.All("ButtonHandler").Value
        if Err.Number <> 0 then exit do
    On Error Goto 0
    
    ' Check to see which buttons have been clicked, and address each one
    ' as it's clicked.
    Select Case g_objIE.Document.All("ButtonHandler").Value
        Case "Cancel"
            ' The user clicked Cancel. Exit the dialog...
            g_objIE.quit
            Exit Do
            
        Case "OK"
            ' The user clicked OK. Act on the information in the
            ' Username and Password fields
            ' Capture data from each field in the dialog...
            szUsername = g_objIE.Document.All("Username").Value
            szPassword = g_objIE.Document.All("Password").Value
            g_objIE.quit
            
            ' Now that we have closed the IE dialog, we can act on our data
            MsgBox "Here is the information you entered..." & vbcrlf & vbtab & _
                "Username: " & szUsername & vbcrlf & vbtab & _
                "Password: " & szPassword
            Exit Do
    End Select

    ' Wait for user interaction with the dialog...
    crt.Sleep 200
Loop

Last edited by pfletch; 10-20-2017 at 02:31 PM.
Reply With Quote
  #2  
Old 10-20-2017, 02:59 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 990
I'm not able to replicate the problem you're describing, but I'm not sure it's anything that SecureCRT could solve for you given the features currently available.

The technique described uses the best effort approach: calling on VBScript's WScript.Shell object to activate the window by title. If that fails, it's unfortunately outside of SecureCRT's scripting capabilities to force an external window to the foreground.

I wish there was an easy solution for you, but I don't know of any easy way to force the window to be on top.

If SecureCRT scripting API is ever enhanced to provide for customized UI directly (without having to drive an IE interface), we'll be sure to let you know.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 10-23-2017 at 10:22 AM.
Reply With Quote
  #3  
Old 10-21-2017, 10:20 AM
GJB56 GJB56 is offline
Registered User
 
Join Date: Nov 2011
Posts: 22
Quote:
Originally Posted by jdev View Post

If SecureCRT scripting API is ever enhanced to provide for customized UI directly (without having to drive an IE interface), we'll be sure to let you know.

--Jake
If SecureCRT were to develop it's own UI, I would gladly repurchase the product. Or just develop and add-on API for purchase.

Last edited by jdev; 10-23-2017 at 10:23 AM.
Reply With Quote
  #4  
Old 10-23-2017, 01:15 PM
pfletch pfletch is offline
Registered User
 
Join Date: Nov 2013
Posts: 12
jdev, when you run the above script from a Windows 10 machine the IE dialog pops to the foreground for you?
Reply With Quote
  #5  
Old 10-23-2017, 03:09 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 990
Quote:
Originally Posted by GJB56 View Post
If SecureCRT were to develop it's own UI, I would gladly repurchase the product. Or just develop and add-on API for purchase.
We'll certainly post here if a future version of SecureCRT is ever able to provide you with custom UI creation natively.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #6  
Old 10-23-2017, 03:10 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 990
Quote:
Originally Posted by pfletch View Post
jdev, when you run the above script from a Windows 10 machine the IE dialog pops to the foreground for you?
Yes, and I'm also on Windows 10. When I run the script code (after correcting syntax error on line 2 where "#" is missing), the window pops up in the foreground.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #7  
Old 10-25-2017, 12:24 PM
pfletch pfletch is offline
Registered User
 
Join Date: Nov 2013
Posts: 12
Ok, thanks. Maybe is an IE version issue, what version of IE are you using?
Reply With Quote
  #8  
Old 10-25-2017, 02:08 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 990
Quote:
Originally Posted by pfletch View Post
Ok, thanks. Maybe is an IE version issue, what version of IE are you using?
I tested with two different machines, each running Windows 10. One machine had IE version 11.0.10240.17133 and the other had 11.674.15063.0. Both worked w/o issue.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:23 PM.