Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 4.00 average. Display Modes
  #1  
Old 06-30-2005, 11:31 AM
justbn justbn is offline
Registered User
 
Join Date: Jun 2005
Posts: 9
Using the Windows CommonDialog Control

Does anyone have some good resources for the scripting features in CRT. I've reviewed the example scripts and FAQ's available. However, I still can't find what I need. I need to run a script that will open the Windows CommonDialog box to let the user browse for and select a file.

I've tried something like this :
----------------------------------------------------
Set objDialog = CreateObject("Test.CommonDialog")
objDialog.Filter = "STP Scripts|*.txt|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen

If intResult = 0 Then
Wscript.Quit
Else
Wscript.Echo objDialog.FileName
End If
----------------------------------------------------

Unfortunately, all I get is an error "Microsoft VBScript runtime error : Error : ActiveX component can't create object 'Test.CommonDialog' " Do I have to have Windows Scripting Host activated? If so, I am out of luck because our company does not allow this.


Any ideas on this? Also, I am trying to use CRT to replace ProComm. In ProComm, I could create custom dialog boxes with text fields, radio buttons, command buttons, etc. Is this possible with CRT?
Reply With Quote
  #2  
Old 06-30-2005, 03:02 PM
Chaucer Chaucer is offline
Registered User
 
Join Date: Jun 2005
Posts: 52
I am pretty sure you cannot access CommonDialog or anything of the sort using vbscripting.
Reply With Quote
  #3  
Old 06-30-2005, 06:03 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,040
Quote:
Originally Posted by justbn
Unfortunately, all I get is an error "Microsoft VBScript runtime error : Error : ActiveX component can't create object 'Test.CommonDialog' " Do I have to have Windows Scripting Host activated? If so, I am out of luck because our company does not allow this.
In order to use an ActiveX object, it must be installed on the system. I've not heard of the "Test.CommonDialog" ActiveX component before, and I don't think that it is something that is installed on a Windows system by default, and it doesn't appear to be installed on your system (based on the error message you are seeing).

CRT doesn't currently provide a way to create cusom dialogs within a script, but I've added a feature request and we'll consider adding it to a future version.

Can you provide me with an example of how you would create a custom dialog with radio buttons, buttons, etc. within your procomm script?

What kind of dialog box are you tring to create, and how will it be used?

Once the dialog is dismissed by the user, how do you envision retrieving the values from the dialog's components?
__________________
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
  #4  
Old 07-01-2005, 12:02 AM
justbn justbn is offline
Registered User
 
Join Date: Jun 2005
Posts: 9
Jake,

"Test.CommonDialog" was simply a mistake on my part. I was thinking that "test" was the window title for the CommonDialog control. However, I think you can only acces the CommonDialog control in the action VisualBasic program used to create DLL's and executables.

ProComm uses a language called "Windows Aspect Scripting" (more info : http://www.aspectscripting.com/index.shtml) that allows me to define a dialog box such as :

; DISPLAY DIALOG TO GET CAPTURE FILE NAME
dialogbox 0 28 20 200 91 2 "Capture Control"
text 1 9 10 64 11 "Capture File Name:" right
editbox 2 75 9 100 11 Cname
pushbutton 3 96 48 39 12 "Cancel"
pushbutton 4 136 48 39 12 "OK"
checkbox 5 12 44 69 8 "Do Not Capture" captureMe
checkbox 6 12 55 69 8 "Overwrite capture ?" clobberMe
text 7 12 72 103 11 "Rejected Commands logged to:" right
text 8 118 72 73 11 "C:\temp\Cmd_Err.txt" right
checkbox 9 12 32 69 8 "Log Errors ?" logerror
enddialog

I've attached a Word Doc with the screen prints for how some of these look. I would use the code below to acces the different fields and options defined above. Also the last word on each line (except right, left, etc) are the variable names for these fields. So for example, to reference whether or not the checkbox was selected, I just use the "logerror" variable.

; PROCESS DIALOG EVENT
while 1
dlgevent 0 event
switch event
case 3
halt
endcase

case 4
exitwhile
endcase
endswitch
endwhile

dlgdestroy 0 CANCEL


I would love to be able to do something like this in CRT. I was hoping that CRT supported the VisualBasic scripting that allows dialog boxes, etc, but it does not seem to. The code sample I showed in the original post is a sample from a web page.
Attached Images
File Type: png dialogs_justbn_20050630_1102p.png (6.8 KB, 11 views)

Last edited by jdev; 10-22-2020 at 03:49 PM.
Reply With Quote
  #5  
Old 07-01-2005, 06:33 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,040
Thanks for the additional information. I'll forward it on to the product manager for consideration.
Quote:
Originally Posted by justbn
I would love to be able to do something like this in CRT. I was hoping that CRT supported the VisualBasic scripting that allows dialog boxes, etc, but it does not seem to. The code sample I showed in the original post is a sample from a web page.
If you want to be notified personally should this functionality be added, send an e-mail message to support@vandyke.com with your contact information and reference this thread (http://forums.vandyke.com/showthread.php?threadid=868).
__________________
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 07-15-2005, 03:00 AM
justbn justbn is offline
Registered User
 
Join Date: Jun 2005
Posts: 9
Using the Windows CommonDialog Control

Jake,

Actually, it seems you may already have a dialog box for accessing files. The box that is used for the "Transfer" "Send ASCII" ,etc boxes would work just fine. Can y'all create a box like these that we can access in VB and Javascript?

Thanks
justbn
Reply With Quote
  #7  
Old 07-18-2005, 06:18 PM
jdurrett jdurrett is offline
Registered User
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 57
Send a message via Yahoo to jdurrett
Bind to a Folder Using the Browse for Folder Dialog Box

Found the following information ealier today when researching my own script challenges. This should answer your question. You can also browse around here for more info. http://www.microsoft.com/technet/scr...r/default.mspx
----Start
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
Set objFolderItem = objFolder.Self

objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * from Win32_Directory where name = '" & objPath & "'")

For Each objFile in colFiles
Wscript.Echo "Readable: " & objFile.Readable
Next
END <--------
Reply With Quote
  #8  
Old 07-22-2005, 12:51 AM
justbn justbn is offline
Registered User
 
Join Date: Jun 2005
Posts: 9
Bind to a Folder Using the Browse for Folder Dialog Box

jdurrett,

Thanks for the response. Unfortunately, I can't get it to work for me. It works fine when I run it outside of CRT. However, when I run it in CRT, I get "Object Required : Wscript".

I read something else on this forum about that. From this post below - it appears that CRT really can't deal with this or that I simply can't figure it out.

-------------------------------------------------------------------------
-------------------------------------------------------------------------
-------------------------------------------------------------------------
jdev
12-03-2004, 03:12 PM
One of the limitations of an application hosting ActiveX scripting is the inability to gain access to functions that are not true objects within the script engine itself.

When running a vbscript outside of CRT/SecureCRT (where CScript.exe or WScript.exe are hosting the script code), you can make calls to things like:
WScript.Arguments
WScript.Path
WScript.Quit
WScript.Sleep
...

However, when CRT/SecureCRT is hosting the script (instead of WScript.exe or CScript.exe), the WScript object itself isn't there; and unless you can call "CreateObject" to instantiate objects provided by WScript, they can't be used within a CRT/SecureCRT script.

In the past, we've made things like "Sleep" and "Arguments" available by providing an API within the CRT object that can be used for making these types of calls (e.g. crt.sleep; crt.arguments). We can consider adding something like a crt.ScriptFullName to resolve this problem for you.

There might be another way to accomplish what you need.

Can you provide more information about the script you are writing and the need to know the full path to the script being run?

--Jake
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-------------------------------------------------------------------------
Reply With Quote
  #9  
Old 07-27-2005, 02:23 PM
jdurrett jdurrett is offline
Registered User
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 57
Send a message via Yahoo to jdurrett
Bind to a Folder Using the Browse for Folder Dialog Box

Try this statement instead of the Wscript.Echo

crt.Dialog.MessageBox ("Readable: " & objFile.Readable)
crt.Dialog.MessageBox ("Readable: " & objFile.Name)


Will produce two message boxes. One says readable, the other gives the path.
I have been unable to find a suitable script for browsing and selecting file(s).


cheers
Reply With Quote
  #10  
Old 07-28-2005, 12:01 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,040
Recent Discovery related to use of CommonDialog in a VBScript

> Thanks for the response. Unfortunately, I can't get it to
> work for me. It works fine when I run it outside of CRT.
> However, when I run it in CRT, I get "Object Required :
> Wscript".

Yes. Any direct function/property like Sleep or Arguments available through WScript.* isn't available within a CRT script.

If a messagebox is all you're looking for, the MsgBox() vbscript built-in works well too:

Code:
For Each objFile in colFiles
    MsgBox "Name: " & objFile.Name & vblf & "Readable: " & objFile.Readable
Next
Recent Discovery related to use of CommonDialog in a VBScript
With respect to browsing for a file, I've done some web searching and have located two different methods of accomplishing this via vbscript and have provided an example script comparing the two methods. The BrowseWithCommonDialog method is similar to the first script that was posted to this thread, and it will only work on Windows XP. The BrowseWithIE method will work on just about any OS with IE 5+ installed, but the interface is more cumbersome.

Do either of the options within the example script below work for you?

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

' Compare the two methods

' Only works with Windows XP
BrowseWithCommonDialog

' Works with Windows with IE 5+ installed, but
' slightly more kludgy interface.
BrowseWithIE

Sub BrowseWithCommonDialog()
    ' Based on information obtained from
    ' http://blogs.msdn.com/gstemp/archive/2004/02/17/74868.aspx
    ' NOTE: Will only work with WindowsXP since other OS's
    '       don't have a UserAccounts.CommonDialog ActiveX
    '       object registered.
    Set objDialog = CreateObject("UserAccounts.CommonDialog")
    'objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
    objDialog.Filter = "All Files|*.*"
    objDialog.FilterIndex = 1
    objDialog.InitialDir = "C:\Temp"
    nResult = objDialog.ShowOpen

    If nResult = 0 Then
        MsgBox "Cancel"
    Else
        MsgBox objDialog.FileName
    End If

End Sub


Function BrowseWithIE
    ' Uses "FindFile()" class that employs IE to perform a
    ' file browse operation.  FindFile class is referenced
    ' below.
    Set objBrowser = New FindFile
    szFile = objBrowser.Browse
    if szFile = "" then
        MsgBox "Cancel"
    else
        MsgBox szFile
    end if
End Function

' FindFile class part of script example "Reboot A
' List Of Workstations" posted to the Win32 Scripting
' examples site (www.netreach.net), but modified to work
' within a script hosted by SecureCRT/CRT:
'    - removed "WScript." from function calls like "CreateObject()"
'    - Changed "WScript.Sleep 500" to "crt.Sleep 500"
'    - removed "Cancel" button from the IE temp FileBrowser.html to
'              eliminate security warnings from IE about scripts that
'              could potentially do damage.  Cancel can still be
'              achieved by clicking on the 'X' to close the window.
'
' script code base for FindFile from:
'   http://cwashington.netreach.net/depo/view.asp?Index=922&ScriptType=vbscript
'
Class FindFile
            Private fso, sPath1

      '--FileSystemObject needed to check file path:
           Private Sub Class_Initialize()
                Set fso = CreateObject("Scripting.FileSystemObject")
           end sub

           Private Sub Class_Terminate()
              Set FSO = Nothing
           End sub

      '-- the one public function in class:

           Public Function Browse()
              'on error resume next
               sPath1 = GetPath
               Browse = sPath1
           end function

Private Function GetPath()
    Dim Ftemp, ts, IE, sPath, sStatus

    '--Get the TEMP folder path and create a text file in it:

        Ftemp = fso.GetSpecialFolder(2)
        Ftemp = Ftemp & "\FileBrowser.html"
        set ts = fso.CreateTextFile(Ftemp, true)

    '--write the webpage needed for file browsing window:
        ts.WriteLine "<HTML><HEAD><TITLE></TITLE></HEAD>"
        ts.WriteLine "<BODY BGCOLOR=" & chr(34) & "#F3F3F8" & chr(34) & " TEXT=" & chr(34) & "black" & chr(34) & ">"
        ts.WriteLine "<DIV ALIGN=" & chr(34) & "center" & chr(34) & ">"
        ts.WriteLine "<FONT FACE=" & Chr(34) & "arial" & Chr(34) & " SIZE=2>"
        ts.WriteLine "<B>SELECT FILE:</B><BR>"
        ts.WriteLine "<FORM>"

                     '--this is the file browsing box in webpage:
                 ts.WriteLine "<INPUT TYPE=" & chr(34) & "file" & chr(34) & "></input>"
                      '--this puts a bit of space between buttons:
              ts.WriteLine chr(38) & chr(35) & "160" & chr(59) & " " & chr(38) & chr(35) & "160" & chr(59)
        ts.WriteLine "<BR>"
        ts.WriteLine "</FORM>"
        ts.WriteLine "</FONT></DIV>"
        ts.WriteLine "</BODY></HTML>"
        ts.Close
        set ts = nothing

    '--webpage is written. now have IE open it:
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Navigate "file:///" & Ftemp
        IE.AddressBar = false
        IE.menubar = false
        IE.ToolBar = false
        IE.StatusBar = false
        IE.width = 400
        IE.height = 150
        IE.resizable = true
        IE.visible = true

    '--do a loop every 1/2 second until either:
    '-- the browsing window value is a valid file path or
    '--IE is closed from the control box.

        Do while IE.visible = true
            spath = ie.document.forms(0).elements(0).value         '--get browsing text box value.

            if fso.FileExists(spath) = true or IE.visible = false then exit do
            crt.Sleep 500
        Loop

        IE.visible = false
        IE.Quit
        set IE = nothing
        if fso.FileExists(spath) = true then
            GetPath =  spath
        else
            GetPath = ""
        end if
  End Function

End Class
__________________
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
  #11  
Old 08-02-2005, 09:24 AM
sambaram sambaram is offline
Registered User
 
Join Date: Aug 2005
Posts: 1
Using the Windows CommonDialog Control

Looking at your script below to open a file...well how can I echo JUST the FILENAME instead of the entire path? eg. if objDialog.Filename = C:\Program Files\Test.txt then I would just like to wscript.echo Test (no file extension neither file path)


Please help as i stuck with writing an oracle script. Really need this to work.



Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Select Oracle Backup file|*.dat|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen

If intResult = 0 Then
Wscript.Quit
Else
Wscript.Echo objDialog.FileName

End If
Reply With Quote
  #12  
Old 08-02-2005, 01:55 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,040
> how can I echo JUST the FILENAME instead of the entire
> path?

Have you considered using the GetFileName() method available with vbscripts FileSystemObject?
Code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Wscript.Echo fso.GetFileName(objDialog.FileName)
__________________
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
  #13  
Old 08-15-2007, 03:33 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Quote:
Originally Posted by justbn
I would love to be able to do something like this in CRT. I was hoping that CRT supported the VisualBasic scripting that allows dialog boxes, etc, but it does not seem to.
I just wanted to make a post here on the custom dialog request.

We now have a sample script that shows how this can be done using the Internet Explorer object in VBScript.

This sample script is attached on the following forum post:

http://forums.vandyke.com/showthread.php?t=2403

This script is not a complete solution but may give you another option for the creation of a custom dialog.
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #14  
Old 01-16-2008, 01:22 AM
areotree areotree is offline
Registered User
 
Join Date: Sep 2007
Posts: 4
Dialogs using CRT.

Below is a script I wrote that uses the BrowseForFolder method from the "Shell.Application" and it runs fine in CRT. You just have to work around the WSH script stuff. CRT only supports VBS scripting. The problem with the one on this post was the "Wscript.echo" at the end. That was why you got the error.

There is also a free activeX component out there called "GooeyScript" that lets you build really nice dialogs, it works really well with CRT, the only problem I have found with it is this is you can't use the "button" function because it uses the WSH version of "CreateObject" to pull in a variable to use for the event handler. I worked around that buy using the "OptionButton" function and a "do until" statement instead. In the GooeyScript documentation the examples show "Wscript.CreateObject" , just change this to "CreateObject" for it to work in CRT.

I have attached a ZIP file with the GooeyScript component and all the documentation. There is also a "crt_demo.vbs" in there also that you can run to see how it works.

Hope this helps..

Chase.

=============================================

Dim filesys, Wshshell
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set Wshshell = CreateObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
'-------------------------------------------------------------------------------------
'---- Sets up a regExp pattern for the parse search
'-------------------------------------------------------------------------------------
Dim regExp1 : Set regExp1 = New RegExp
regExp1.Global = False
regExp1.Pattern = "^\|[0-9]+\|.*$"
regExp1.IgnoreCase = True
Dim regExp2 : Set regExp2 = New RegExp
regExp2.Global = False
regExp2.Pattern = "^[0-9]+;.*$"
regExp2.IgnoreCase = True
'-------------------------------------------------------------------------------------
'---- Launch Folder browser and get capture directory to be parsed.
'-------------------------------------------------------------------------------------
objFolder = False
Set objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "")
If objFolder Is Nothing Then
MsgBox ("No folder selected,, Exiting script !!")
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
'-------------------------------------------------------------------------------------
'---- Parse the file in the capture directory.
'-------------------------------------------------------------------------------------
Set objFolder = filesys.GetFolder(objPath)
For Each objfile in objFolder.Files
Set testFile = filesys.OpenTextFile(objFile.path, ForReading)
Report="" 'the idea to be proper requires reset to empty'
Do Until testFile.AtEndOfStream
varLine = testFile.ReadLine
Do While Instr(varLine, " ")
varLine = Replace(varLine, " ", "")
Loop
If (regExp1.Test(varLine)) Or (regExp2.Test(varLine)) Then
If (Left(varLine,1) = "|") Then
Report = Report & Mid(Trim(varLine),2) & vbCrLf
Else
Report = Report & Trim(varLine) & vbCrLf'
End If
End If
Loop
'Change delimiter
Report = Replace(Report, "|", ";")
''''''''''Write the changed text back to the file
Set testFile = filesys.OpenTextFile(objFile.path, ForWriting)
testFile.Write Report
testFile.Close
For K = 1 To 1000000
'put this in so you can see the file names in the Processbar
Next
Next
MsgBox (" ***** Parsing of the PPK files complete !!! *****")
Attached Files
File Type: zip GooeyScript.zip (241.3 KB, 669 views)
Reply With Quote
  #15  
Old 05-03-2008, 06:49 AM
quark-man quark-man is offline
Registered User
 
Join Date: May 2005
Posts: 16
Quote:
Originally Posted by areotree
I have attached a ZIP file with the GooeyScript component and all the documentation. There is also a "crt_demo.vbs" in there also that you can run to see how it works.

Hope this helps..

Chase.
excellent!
just what i was looking for.

now, i just have to figure out why i'm not able to do the following
------------------
crt.screen.Send <value from the dialog-box text field>
------------------


thanks areotree
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 05:16 AM.