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 08-08-2012, 07:52 AM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Windows 7 ActiveX Problem

I've been using SecureCRT for a couple of years on a dozen WinXP machines.
I Love it. I have a couple of dozen scripts that run our day to day business.

Our company is migrating to Windows 7. I had the IT guys load it on test
machine so I could load SecureCRT and the scripts and make sure everything
worked. I'm receiving this error:

Microsoft VBScript runtime error

Error: ActiveX component can't create object:
'UserAccounts.CommonDialog'
File: c:\usr\Scripts\TestScript.vbs
Line: 52

Here's line 52 in context:

44 ' Create an instance of the scripting filesystem runtime so we can
45 ' manipulate files.
46 Dim fso, filesys
47 Set fso = CreateObject("Scripting.FileSystemObject")
48 Set filesys = CreateObject("Scripting.FileSystemObject")
49
50 ' create an instance of the File Browser
51 Dim ObjFSO, InitFSO
52 Set ObjFSO = CreateObject("UserAccounts.CommonDialog")

I'm trying to let the user select a file.

We're running SecureCRT Version 7.0.0 (Build 326)

I've searched Microsoft and these forums and can't find anything that
seems to apply.

Any ideas?

Thanks - Rick
Reply With Quote
  #2  
Old 08-08-2012, 09:30 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Rick,

Thanks for the question. Some capabilities available on Windows XP are no longer available on Windows 7.

I would suggest that you use the SecureCRT FileOpenDialog method that has been included in the Dialog object to accomplish your goal since the UserAccounts.CommonDialog is no longer available on Windows 7.

Here is an example:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForWriting = 2
strFilename = _
	crt.Dialog.FileOpenDialog("Specify Filename to Save", "Save", _
		"filename.txt", "Text Files (*.txt)|*.txt||")

If strFilename <> "" Then
	Set objFile = fso.OpenTextFile(strFilename, ForWriting, True)
	objFile.Write strScreenData & vbcrlf
	objFile.Close
End If
Does this help you fix your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 08-08-2012 at 12:20 PM.
Reply With Quote
  #3  
Old 08-08-2012, 09:56 AM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Thanks for the quick response Todd. I think we're on the right track.

I'm actually showing the users a directory of folders (one for each state) for
them to drill down through to select a file to use to update a switch.

Perhaps a little more context will help:

69 Sub Main()
70
71 'setup the File Browser specifics
72 ObjFSO.Filter = "Today's Load|" & mmdd() & "|All loads|????|All Files|*.*"
73 ObjFSO.FilterIndex = 1
74 ObjFSO.InitialDir = LOADS
75
76 ' Show the file browser and return the selection (or lack of) to InitFSO
77 InitFSO = ObjFSO.ShowOpen
78 Set fso = CreateObject("Scripting.FileSystemObject")
79
80 If (ObjFSO.FileName <> "") Then
81 ' Make sure load file has some data in it.
82 If (CntLines(ObjFSO.FileName) = 0) Then
83 crt.Dialog.MessageBox "Load file is empty" & VbCr & VbCr & _
.
.
.

I hope that clarifies my problem.

Thanks - Rick
Reply With Quote
  #4  
Old 08-08-2012, 12:20 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Rick,

I am not sure what the current question is. Are you indicating that you do not know how to set the initial folder for the dialog created by the FileOpenDialog method?

If so, you set that using the defaultFilename parameter outlined in the help file. To clarify the information in the help file, the defaultFilename parameter can be a filename or an absolute path. The current working directory is used in the case of providing just a filename, and the parent directory of the filename is used when an absolute path is defined.

Here is a modified example:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForWriting = 2
strFilename = _
	crt.Dialog.FileOpenDialog("Specify Filename to Save", "Save", _
		"C:\Temp\filename.txt", "Text Files (*.txt)|*.txt||")

If strFilename <> "" Then
	Set objFile = fso.OpenTextFile(strFilename, ForWriting, True)
	objFile.Write strScreenData & vbcrlf
	objFile.Close
End If
Does this help?

If not, would you provide more data about your question?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 08-08-2012 at 01:43 PM.
Reply With Quote
  #5  
Old 08-08-2012, 12:56 PM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Thanks Todd.

That finally "clicked".

Thanks for all your help.

Rick
Reply With Quote
  #6  
Old 08-08-2012, 01:21 PM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
That did it Todd.

Thanks again for all your help.

Rick
Reply With Quote
  #7  
Old 08-08-2012, 02:07 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
You are welcome Rick. I am glad I could help.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #8  
Old 08-09-2012, 08:05 AM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Hi Todd -

A follow-up question, if I may.

In my original code, I'm setting a file filter with line 72, and the initial directory from which to select a file with line 74:

71 'setup the File Browser specifics
72 ObjFSO.Filter = "Today's Load|" & mmdd() & "|All loads|????|All Files|*.*"
73 ObjFSO.FilterIndex = 1
74 ObjFSO.InitialDir = LOADS

LOADS is a defined constant.

I currently am trying to do the same with:

FileName = crt.Dialog.FileOpenDialog("Select a load file", "Open", LOADS, _
"Today's Load|" & mmdd() & "|All loads|????|All Files|*.*")

That worked fine the first time a ran the script, but subsequent runs put me in the subfolder I visited last instead of LOADS.

The filter works fine.

What am I missing here?

Thanks,
Rick
Reply With Quote
  #9  
Old 08-09-2012, 12:09 PM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Question moved to new thread.
Reply With Quote
  #10  
Old 08-09-2012, 12:56 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Rick,

I have responded to your new thread.

I apologize for the delay. I just overlooked your question.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #11  
Old 08-10-2012, 08:24 AM
rcomito rcomito is offline
Registered User
 
Join Date: Jul 2010
Posts: 15
Quote:
Originally Posted by rtb View Post
Hi Rick,

I have responded to your new thread.

I apologize for the delay. I just overlooked your question.
No problem Todd. It belongs in a thread of it's own.

Thanks,

Rick
Reply With Quote
  #12  
Old 02-24-2014, 07:34 PM
birdboyee birdboyee is offline
Registered User
 
Join Date: Feb 2014
Posts: 3
Smile login into multiple boxes to execute commands

We use a SecureCRT .vbs script for logging into multiple boxes, and executing a few commands, however, I too am getting "UserAccounts.CommonDialog"error message, can I get help with the following script? The script looks at a file which contains a list of IP's, it then executes the following for each IP within the file.


Quote:
# $language = "VBScript"
# $interface = "1.0"
Sub Main
'------------------------------------------------------------
Dim ObjFSO, InitFSO, Wscript
sDir = "D:\Documents and Settings\script"
Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "Text Files|*.txt|All Files|*.*"
ObjFSO.FilterIndex = 1
ObjFSO.InitialDir = sDir
InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then
Exit Sub
End If
'-----------------------------------------------------------
Const ForReading = 1

Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(ObjFSO.FileName, ForReading, False)

crt.Screen.Synchronous = True
crt.Screen.Send "gui_prompt" & vbCr
crt.Screen.WaitForString "Enter Form Name (or ?): "
crt.Screen.Send "masterlist" & vbCr
crt.Sleep 1000
'-----------------------------------------------------------
Do While file.AtEndOfStream <> True
str = file.Readline

crt.Screen.WaitForString "Enter Command I=Insert R=Review U=Update D=Delete: ", 60
crt.Sleep 1000
crt.Screen.Send "u" & vbCr
crt.Screen.WaitForString ">"
crt.Sleep 1000
crt.Screen.Send "rtr=" & str & vbCr
crt.Screen.WaitForString ">"
crt.Sleep 1000
crt.Screen.Send "bkup=" & vbCr
crt.Screen.WaitForString ">"
crt.Sleep 1000
crt.Screen.Send "u" & vbCr

Loop
'----------------------------------------------------------
crt.Screen.WaitForString "Enter Command I=Insert R=Review U=Update D=Delete: ", 60
crt.Sleep 1000
crt.Screen.Send "<" & vbCr
crt.Screen.WaitForString "Enter Form Name (or ?): ", 60
crt.Sleep 1000
crt.Screen.Send "<" & vbCr
'----------------------------------------------------------
crt.Screen.Synchronous = False
'----------------------------------------------------------
End Sub
Reply With Quote
  #13  
Old 02-25-2014, 08:31 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi birdboyee,

Thanks for the post. My guess is that you moved from Windows XP to Windows 7, and you are now seeing the error.

The UserAccounts.CommonDialog object is no longer available on Windows 7. If you want to open a file, you can use the SecureCRT scripting API Dialog object. There is a method called FileOpenDialog which allows a script to have a user select a file for use in a script.

Usage of the FileOpenDialog method is explained in the Scripting / Script Objects Reference / Dialog chapter of the help file.

Does this help you resolve the problem you are seeing in your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #14  
Old 02-26-2014, 02:37 AM
birdboyee birdboyee is offline
Registered User
 
Join Date: Feb 2014
Posts: 3
Hello rtb! I get prompted for file, but now it complains about the following line:

Set file = fso.OpenTextFile(ObjFSO.FileName, ForReading, False)


Error: Object required: 'ObjFSO'
Reply With Quote
  #15  
Old 02-26-2014, 09:36 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi birdboyee,

You would need to comment out most of the lines related to the object that is no longer available.

When using the FileOpenDialog, you would assign the results (the file selected) to a variable.

On line 21 of the script you posted, the FileSystemObject is used to open a file. Rather than using the object that is no longer valid (ObjFSO), you would open the filename contained in the variable.

For example:
Code:
strFilePath = crt.Dialog.FileOpenDialog("Please select a file")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile(strFilePath, ForReading, False)
Does this help you move forward?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply

Tags
activex , win7 , windows 7


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 06:07 AM.