Solved

VBS Script Modification Pt5

Posted on 2012-03-11
10
556 Views
Last Modified: 2012-06-27
Hello Experts,

The following script fails when it gets to the line 'crt.session.log True'. Its being used with an application called SecureCRT and its run on a number of tabs. Basically, the script will work fine on the first tab, but when it gets to another tab I get the error message CRT Scripting Runtime error, and then it says Logging already enabled.

I think its because script doesn't recognise that it should start afresh on a new tab.

I wonder if you could assist?

# $language = "VBScript"
# $interface = "1.0"
' SendToAll.vbs

Sub Main()
   
    if Not crt.Session.Connected then
        szSession = crt.Dialog.Prompt("Enter session:", "", "", False)
        if szSession = "" then exit sub
   
        crt.Session.ConnectInTab("/S " & szSession)
        crt.Session.ConnectInTab("/S " & szSession)
        crt.Session.ConnectInTab("/S " & szSession)
    end if
   
    arrCommands = Array("end", "term len 0")

    ' Send commands to all tabs
    ' Connect to each tab in order from left to right, issue all commands, and
    ' then disconnect...
    For nIndex = 1 to crt.GetTabCount
        Set objCurrentTab = crt.GetTab(nIndex)
        objCurrentTab.Activate
     
           
        If objCurrentTab.Session.Connected = True Then
            crt.Session.Log True
            For Each strCommand In arrCommands
                crt.Sleep 500
                objCurrentTab.Screen.Send strCommand & vbcr
           
                crt.Sleep 1000
            Next
        End If
    Next
End Sub
                                           

Cheers

Carlton
scripterror.jpg
0
Comment
Question by:cpatte7372
[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
  • 6
  • 4
10 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 37712462
Not sure, but if logging *is* already started, you might be able to change this:
crt.Session.Log True

to this
If crt.Session.Log = False Then crt.Session.Log True

Rob.
0
 

Author Comment

by:cpatte7372
ID: 37712514
Rob, thanks for responding, going to check it out now...
0
 

Author Comment

by:cpatte7372
ID: 37712524
Rob,

Getting the follow error message...
error3.jpg
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 37712627
OK, so according to here:
http://forums.vandyke.com/archive/index.php/t-1118.html

it doesn't look like you can check the logging state, but the code there just ignores errors and checks the error code when executing the crt.session.log True line.

Replace this:
            crt.Session.Log True

with something like
On Error Resume Next
Err.Clear
crt.Session.Log True
If Err.Number <> 0 Then
	If Err.Number = -2147155969 Then
		' Logging was already enabled
	Else
		' Some other error occurred while enabling logging
	End If
End If
Err.Clear
On Error GoTo 0

Open in new window

0
 

Author Comment

by:cpatte7372
ID: 37713480
Hi Rob,

Thanks again for responding. I will check it out shortly and let you know.

Cheers

Carlton
0
 

Author Comment

by:cpatte7372
ID: 37713944
Hi Rob,

Unfortunately, the script now only works on the firs tab, or should I say, 'it only works once', but doesn't work on other tabs. However, at least its not crashing this time.

I think we could be nearly there.....
0
 

Author Closing Comment

by:cpatte7372
ID: 37715874
Got it working cheers...
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37717394
Thanks for the grade.  Would you mind explaining what you did to get it working?

Thanks,

Rob.
0
 

Author Comment

by:cpatte7372
ID: 37717570
Hi Rob,

If it's ok I will show you tomorrow - about to hit the sack.

Cheers
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37717583
Yeah, no problem. No rush.  It just helps others that may be having the same problem.

Rob.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

762 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