SoFunction
Updated on 2025-03-10

Common operations between bat files and Vbs files (get user input and execute VBS files)

bat file

set /P StrInput="Input number:"
echo The entered number is%StrInput%
set /P Flg="Whether to execute(y/n):"
IF "%Flg%" equ "y" (
  echo Execute the command
  cscript  "%StrInput%"
)

Notice:

There cannot be spaces between equal signs (=), otherwise an error will occur.

It is best to use equ or something to determine the size of the value.

There are spaces in the brackets after the conditional judgment.

VBS file

Get external parameters

Write a file

WebAPI Operations

Date and TimeStamp Transformation

Dim WshShell
Dim CurDir
Dim oParam

'Take parameters
Set oParam = 

if >0 Then

Else
    
End if

'Get the current path
Set WshShell = ("")
CurDir = 

'Write file operation
Function OutputData(filename)
    Dim objFSOW
    Dim objFileW

    Set objFSOW = ("")
    Set objFileW = (filename,2,True)
    
    (filename)
    (vbCrLf)
    (vbTab)

    Set objFileW = Nothing
    Set objFSOW =Nothing

End Function

'WebAPI Operations
 'params = "{""method"":""get"",""ID"":""12""}"
Function RequestAPI(url,params)
    Dim oHttp
    
    Set oHttp = CreateObject("")
    on error resume next
    
     "POST",url,False
   
    If Err Then
        RequestAPI = 
    End If
    On Error Goto 0

     "Content-Type","application/json"
     params

    If <>4 Then
       (10)
    End If

    RequestAPI = 

    Set oHttp = Nothing

End Function

'TimeStamp -> Date
Function FormatDate(timestamp)
   FormatDate = DateAdd("s",CLng(timestamp),"01/01/1970 00:00:00")
End Function

'Date ->TimeStamp
Function DateToTimeStamp(dateValue)
   DateToTimeStamp = DateDiff("s","01/01/1970 00:00:00",dateValue)
End Function

vbs server bat file, batch operation under window: call vbs in bat file

@echo "kill CRT process"
taskkill /F /IM 
::ping 127.0.0.1 -n 30
echo "start vos through CRT"
echo off
d:
cd D:\tools\SecureCRT_x86
start  /SCRIPT D:\Secure_vos\Start_vos.vbs
echo "start vos through CRT end"
ping 127.0.0.1 -n 4
pause

The above code means: Execute Start_vos.vbs file in the .bat file

First, you need to download the file before executing the file.

The content of Start_vos.vbs file is as follows:

On Error Resume Next
Dim result
If  Then 
' connected to the '172.21.1.114'
Set objtab = ("/SSH2 /PASSWORD root [email protected]",True)
' Capture error code and description (if any)
nError = 
strErr = 
' Now, tell the script host that it should handle errors as usual now:
On Error Goto 0
' change tab name
 = "Gdb_vos"
' enter the folder
 "cd /home/test" & chr(13)
 chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "
End Sub

The above code mainly uses VBS scripts to automate the manual input process.
First: Set objtab = ("/SSH2 /PASSWORD root123 [email protected]",True)
Connect to the linux IP address 172.21.1.114 using SSH2, the password is root123, and the user name is = "Start_vos"
Rename the current connection page to Start_voscrt. "cd /home/test" & chr(13) Enter cd /home/test and press Enter
chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "The content of the next line of the waiting page is chr(27) & "[32m(none) /home/test" & chr(27) & "[m # "

This is the article about the common operations between bat files and Vbs files (get user input, execute VBS files). For more related bats to obtain user input, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!