Is there a way I can see a error for my script file? - vbscript

I'm trying to figure out why my script isn't running It don't show no error code nor does my script work. Is there a way I can see what the issue is?
Set WshShell = Server.CreateObject("WScript.Shell")
Dim ExecOperation, ExCode, StdOut
python_program = "c:/python37-32/python.exe "
py_file = "C:/inetpub/webroot/hcoutreach.com/PythonScripts/PrintQrCodeConverter.py"
cmdLine = python_program & " " & py_file & " " & intFam_Id
Set ExecOperation = WshShell.Exec(cmdLine)
' ' Check the operation's status
While (ExecOperation.Status = 0)
WaitForMilliseconds(100)
WEnd
' ' Get the operation's exit code
ExCode = ExecOperation.ExitCode
' ' Get the application's StdOut stream
Set StdOut = ExecOperation.StdOut
value = StdOut.ReadAll

Related

SecureCRT: VBScript printing output to console

I have written script to connect from my local machine to Jump server using secure crt. i was able to execute the script and capture the output into Msgbox, But unable to print it to console.
Below is the code which i have written.
#$language = "VBScript"
#$interface = "1.0"
Set objTab = crt.GetScriptTab
Set g_shell = CreateObject("WScript.Shell")
Public szData
crt.Sleep 6000
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
crt.Screen.Synchronous = True
Dim pran
Sub Main
strVal = crt.Arguments(0)
crt.Screen.Send "pwd" & chr(13)
crt.Screen.WaitForString "[xyz#xlpv0002 ~]$"
crt.Screen.Send "sh test.sh" & chr(9) & chr(13)
**szData = CaptureOutputOfCommand("sh test.sh", "[xyz#xlpv0002 ~]") & vbCr**
'MsgBox(szData)
pran = szData
crt.Clipboard.Format = "CF_TEXT"
crt.Clipboard.Text = pran
crt.Dialog.MessageBox("Text is now in the clipboard: \n\n" + crt.Clipboard.Text)
'MessageBox.Show(szData)
If Not SendExpect("exit", "[xyz#xlpv0002 ~]") then exit sub
g_shell.Run "%comspec% /c taskkill /IM SecureCRT.exe /F"
End Sub
'=======================================================================
Function CaptureOutputOfCommand(szCommand, szPrompt)
if crt.Session.Connected <> True then
CaptureOutputOfCommand = "[ERROR: Not Connected.]"
exit function
end if
objTab.Screen.Send szCommand & vbcr
objTab.Screen.WaitForString vbcr
CaptureOutputOfCommand = objTab.Screen.ReadString(szPrompt)
End Function
'======================================================================
Function SendExpect(szSend, szExpect)
if objTab.Session.Connected <> True then exit function
objTab.Screen.Send szSend & vbcr
objTab.Screen.WaitForString szExpect
SendExpect = True
End Function
'========================================
I am capturing the script output into szData variable. Is there a way to print the same in the console?
You are already using the command
crt.Screen.Send
You just need to pass a valid command that will output to the console, if doing this on a Windows Server you should be able to use the Command Line program ECHO to output to the console.
crt.Screen.Send "echo Display in console!!!"
Output (untested, but should produce)
Display in console!!!
So you should just be able to do
crt.Screen.Send "echo " & szData
Useful Links
Scripting Essentials:
A Guide to Using
VBScript in SecureCRT (official documentation)

Trying to create a grads script and getting error " Expected end of statement " how can I solve it?

This is a screenshot of what I'm getting the error:
The file name of the script it's coming with the grads program.
gradsgui.vbs
The content of the file the script:
' Lightweight script to call actual executables down bellow. Eventually it
' could include the same functionality of the Perl version. Now it seats in
' the very top, above Contents/
Dim objFileSystem, objFILE
' Find out where we actually are
' ------------------------------
ScriptPath = Left(WScript.ScriptFullName, _
Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
' Get the current version from file
' ---------------------------------
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objFILE = objFileSystem.OpenTextFile(ScriptPath & "Contents\Cygwin\Versions\Current#", 1)
Versions = Split(objFILE.ReadAll, vbCrLf)
Version = Left(Versions(0),Len(Versions(0))-1)
objFile.Close
Set objFileSystem = Nothing
' Actual executable path
' ----------------------
ActualPath = ScriptPath & "Contents\Cygwin\Versions\" & Version & "\i686\"
ExecutableName = Left(WScript.ScriptName,Len(WScript.ScriptName)-4) & ".exe"
ExecutableFullName = ActualPath & ExecutableName
' WScript.echo "Running <" & ExecutableFullName & ">"
' Command line arguments
' ----------------------
Set ArgObj = WScript.Arguments
sArgCount = ArgObj.Count
args = " "
For x = 0 To sArgCount - 1
args = args & " " & ArgObj(x)
Next
Set ArgObj = Nothing
Set xsize = 650 500
'Start actual application down below
'-----------------------------------
Set objShell = CreateObject("WScript.Shell")
'objShell.Run "%COMSPEC% /k" & ExecutableFullName & args
objShell.Run ExecutableFullName & args
Set objShell = Nothing
The line that I added that give the error is:
set xsize = 650 500
If I type this command in the console window when running the grads.exe it will work fine. But using the script it's giving me this error.
What i did is adding to the end of the file script two lines:
'Start actual application down below
'-----------------------------------
Set objShell = CreateObject("WScript.Shell")
Set env = objShell.Environment("PROCESS")
env("xsize") = "650 500"
' objShell.Run "%COMSPEC% /k" & ExecutableFullName & args
objShell.Run ExecutableFullName & args
Set objShell = Nothing
The lines i added are:
Set env = objShell.Environment("PROCESS")
env("xsize") = "650 500"
But they are not doing anything. It's not opening the new window in this size.
Looks like you're mixing VBScript and CMD commands here. You probably mean to set xsize=650 500 as an environment variable, but in VBScript the Set keyword is used for assigning objects to variables, not for defining variables in general like in CMD.
Try defining the variable in the process environment, so that it's inherited by the child process you're starting:
Set objShell = CreateObject("WScript.Shell")
Set env = objShell.Environment("PROCESS")
env("xsize") = "650 500"
objShell.Run ExecutableFullName & args

vbscript+function calling function - return value

I have a vbscript that calls a second vbscript and runs a function. This second function returns a value. But I can't figure out how to get this value, as the result of the first function returns the status code.
original call: fileCASTRING(12345678)
vbscript 1
function fileCASTRING(varRAW)
lresult = CreateObject("WScript.Shell").Run ("c:\windows\syswow64\cscript.exe C:\ERMXData\Config\query-castring.vbs " & varRAW,0,true)
fileCASTRING=1
end function
query-castring.vbs
doctype=WScript.Arguments.Item(0)
Dim strCon
strCon = "DSN=*****; " & _
"uid=*****;pwd=*****;"
Dim oCon: Set oCon = WScript.CreateObject("ADODB.Connection")
Dim oRs: Set oRs = WScript.CreateObject("ADODB.Recordset")
oCon.Open strCon
Set oRs = oCon.Execute("select ESBLINK_ADMR_CODE from ESBLINK where ESBLINK_DTYP_CODE like '%" + doctype + "%'"")
queryB=oRs.Fields(0).Value
oCon.Close
Set oRs = Nothing
Set oCon = Nothing
I have to do it like this because the program that runs vbscript 1 runs in 64 bit mode and the code in query-castring.vbs needs to run in 32bit mode in order for it to work. How can I get the queryB value back to the original caller? I am trying to not have to write the value to a file.
The only easy way to communicate between two command line processes is via StdOut.
(Be aware the code is not tested but should get you into the right direction.)
VBScript 1
Option Explicit
' ...
Function fileCASTRING(varRAW)
Dim program, script, cmdline, output
program = "c:\windows\syswow64\cscript.exe /nologo"
script = "C:\ERMXData\Config\query-castring.vbs"
cmdLine = program & " " script & " """ & varRAW & """"
output = ""
With CreateObject("WScript.Shell").Exec(cmdLine)
While Not .StdOut.AtEndOfStream
output = output & .StdOut.ReadAll
Wend
End With
fileCASTRING = output
End Function
see the documentation of the WshScriptExec object
query-castring.vbs
Option Explicit
Dim doctype: doctype = WScript.Arguments.Item(0)
Dim strCon: strCon = "DSN=*****;uid=*****;pwd=*****;"
Dim strSql: "select ESBLINK_ADMR_CODE from ESBLINK where ESBLINK_DTYP_CODE like '%' + ? + '%'"
Dim oCon: Set oCon = WScript.CreateObject("ADODB.Connection")
Dim oCmd: Set oCmd = WScript.CreateObject("ADODB.Command")
oCon.Open strCon
With WScript.CreateObject("ADODB.Command")
Set .ActiveConnection = oCon
.CommandText = strSql
.Parameters.Add(.CreateParameter)
.Parameters(0).Value = doctype
With .Execute
If Not .EOF Then
WScript.Echo .Fields("ESBLINK_ADMR_CODE").Value
End If
End With
End With
oCon.Close
See the documentation of the ADODB Command and Parameter objects. Don't build SQL from strings.
Also, look into "integrated security" connection strings - do not store plain text passwords in in code files. ADODB can easily use the security context of the account that runs the script, if you tell it to.
VBScript 1
Function getADMRCODE(varRAW)
Dim program, script, cmdline, output
program = "c:\windows\syswow64\cscript.exe /nologo"
script = "C:\ERMXData\Config\common_app\queries\admrcode.vbs"
cmdLine = program & " " & script & " """ & varRAW & """"
output = ""
With CreateObject("WScript.Shell").Exec(cmdLine)
While Not .StdOut.AtEndOfStream
output = output & .StdOut.ReadAll
Wend
End With
getADMRCODE = output
End Function
query-castring.vbs
Dim doctype: doctype = WScript.Arguments.Item(0)
Dim strCon
strCon = "DSN=*****; " & _
"uid=*****;pwd=*****;"
Dim oCon: Set oCon = WScript.CreateObject("ADODB.Connection")
Dim oRs: Set oRs = WScript.CreateObject("ADODB.Recordset")
oCon.Open strCon
Set oRs = oCon.Execute("select ESBLINK_ADMR_CODE from ESBLINK where ESBLINK_DTYP_CODE LIKE '%" + doctype + "%'")
WScript.Echo oRs.Fields(0).Value
oCon.Close
Set oRs = Nothing
Set oCon = Nothing

How do I reset the stream of StdOut in VBScript

I want to use a VB script (full script in the Pastebin) to check that certain servers are up (responding to pings) every time I log in to my work computer.
However, it seems that as I am grabbing the full results of the output...
strPingResultsFull = LCase(WshExec.StdOut.ReadAll)
...before I loop through the individual lines...
Do Until WshExec.StdOut.AtEndOfStream
...that WshExec.StdOut is already AtEndOfStream, so I'm never getting any results.
The first part of my questing - is this theory correct (or likely to be correct)? The second part - How do I sort this out (i.e. reset the stream so that I can check every line individually)? Thanks.
' Set the targets to ping
strTarget(0) = "192.168.1.6" ' TTSA
strTarget(1) = "192.168.1.7" ' TTSB
strTarget(2) = "192.168.1.14" ' TTSC
strTarget(3) = "192.168.1.12" ' TTSD
Set WshShell = WScript.CreateObject("WScript.Shell")
' Loop through all of the targets to ping
For i = 0 To UBound(strTarget)
' Ping the target
Set WshExec = WshShell.Exec("ping -n 2 -w 500 " & strTarget(i)) ' Send 2 echo requests, waiting 0.5 seconds maximum
' Grab the full results of the ping
strPingResultsFull = LCase(WshExec.StdOut.ReadAll)
' Set 'strPingResultsPart' to an empty string
strPingResultsPart = ""
' Grab the results of the ping
Do Until WshExec.StdOut.AtEndOfStream
strSingleLine = WshExec.StdOut.ReadLine()
If Instr(strSingleLine, "Ping statistics for") <> 0 Or Instr(strSingleLine, "Packets:") <> 0 Then
strPingResultsPart = strPingResultsPart & strSingleLine
End If
Loop
' Check that there is something to output (there should be, even if the pings all fail)
If strPingResultsPart <> "" Then
Msgbox "Not empty - " & strPingResultsPart
' Add the ping results to the correct results strings
If InStr(strPingResultsFull, "reply from") Then
strOutputSuccess = strOutputSuccess & strPingResultsPart & VBCrLf
Else
strOutputFailure = strOutputFailure & strPingResultsPart & VBCrLf
End If
End If
Set WshExec = Nothing
Next
After first call WshExec.StdOut.ReadAll you're already at AtEndOfStream therefore...
Do Until WshExec.StdOut.AtEndOfStream
...will do nothing. You can't seek back StdOut to read from it multiple times.

VB script to run a Query

I am trying to connect command prompt through VB script and further its connecting with Oracle enviroment to execute some reports of Oracle discoverer.
But the problem is with this VB script only.
line 2: for establishing the connection.
line 7:fetching the current REQUEST_ID.
line 16:XXDIS_EXPORT_CMD_V is a view and cmd is a column.which select a value like this for corresponding REQUEST_ID.
/CONNECT DISCADMIN:"FAI Financials Intelligence"/discbi#deverp /OPENDB "1 Scheduling" /SHEET "Sheet_1" /EXPORT HTML o27673334.out /LOGFILE l27673334.log /BATCH
In the end i want to execute this cmd using VBScript.
Error coming :
"In line 32 tkgoShell was not
recognized"
This is My code:
' Process job
Set objADO =CreateObject("ADODB.Connection")
objADO.Open "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=deverp; UID=apps; PWD=apps11i;"
MsgBox "Connection Established to Server.", vbExclamation + vbOKOnly, "System"
Do While True
' Check if there is a job to process
Set moRS=objADO.execute("SELECT apps.xxdis_schedule_pkg.start_job REQUEST_ID FROM dual")
moRS.MoveFirst
msRequest = moRS("REQUEST_ID")
'MsgBox msRequest,msRequest
' If no jobs then exit
' If msRequest = "0" Then
Exit Do
' End If
loop
Set moRS=objADO.execute("SELECT cmd EXPORT_CMD FROM apps.xxdis_export_cmd_v " & _
"WHERE request_id = " & msRequest)
MsgBox msRequest,msRequest
moRS.MoveFirst
msExpCmd = moRS("EXPORT_CMD")
' write command into a temporary file
msCmdFile = "r" & msRequest & ".cmd"
dim moOutputStream,filesys,msCommand
Set filesys = CreateObject("Scripting.FileSystemObject")
Set moOutputStream = filesys.CreateTextFile(msCmdFile, True)
' Substitute $SAMBA$ and $TNS$ locally configured variables
moOutputStream.Write Replace(Replace(msCmd, "$SAMBA$", gsOutDir),_
"$TNS$", gsInstance) & vbCRLF
moOutputStream.Close
' Call Discoverer to process the command
msCommand = gsBinDir & gsDiscoExe & " /EUL " & gsEUL & " /CMDFILE " & msCmdFile
Call tkgoShell.Run (msCommand, 1, true)
If I understand your code correctly I can't see anywhere where you're actually creating the tkgoShell.
Try inserting the following 2 rows before your last line:
Dim tkgoShell
Set tkgoShell = WScript.CreateObject ("WScript.Shell")
See here for more information about Shell.Run.

Resources