vb6截取控制台命令执行结果的代码

Option Explicit
' Contants
Private Const STARTF_USESHOWWINDOW     As Long = &H1
Private Const STARTF_USESTDHANDLES     As Long = &H100
Private Const SW_HIDE                  As Integer = 0
' Types
Private Type SECURITY_ATTRIBUTES
    nLength                                As Long
    lpSecurityDescriptor                   As Long
    bInheritHandle                         As Long
End Type
Private Type STARTUPINFO
    cb                                     As Long
    lpReserved                             As String
    lpDesktop                              As String
    lpTitle                                As String
    dwX                                    As Long
    dwY                                    As Long
    dwXSize                                As Long
    dwYSize                                As Long
    dwXCountChars                          As Long
    dwYCountChars                          As Long
    dwFillAttribute                        As Long
    dwFlags                                As Long
    wShowWindow                            As Integer
    cbReserved2                            As Integer
    lpReserved2                            As Long
    hStdInput                              As Long
    hStdOutput                             As Long
    hStdError                              As Long
End Type
Private Type PROCESS_INFORMATION
    hProcess                               As Long
    hThread                                As Long
    dwProcessId                            As Long
    dwThreadId                             As Long
End Type
' Declares
Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, _
                                                    phWritePipe As Long, _
                                                    lpPipeAttributes As Any, _
                                                    ByVal nSize As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _
                                                  lpBuffer As Any, _
                                                  ByVal nNumberOfBytesToRead As Long, _
                                                  lpNumberOfBytesRead As Long, _
                                                  lpOverlapped As Any) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, _
                                                                              ByVal lpCommandLine As String, _
                                                                              lpProcessAttributes As Any, _
                                                                              lpThreadAttributes As Any, _
                                                                              ByVal bInheritHandles As Long, _
                                                                              ByVal dwCreationFlags As Long, _
                                                                              lpEnvironment As Any, _
                                                                              ByVal lpCurrentDriectory As String, _
                                                                              lpStartupInfo As STARTUPINFO, _
                                                                              lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'---------------------------------------------------
' Call this sub to execute and capture a console app.
' Ex: Call ExecAndCapture("ping localhost", Text1)
Public Function ExecAndCapture(ByVal sCommandLine As String, _
                          Optional ByVal sStartInFolder As String = vbNullString) As String

Const BUFSIZE         As Long = 1024 * 10
Dim hPipeRead         As Long
Dim hPipeWrite        As Long
Dim sa                As SECURITY_ATTRIBUTES
Dim si                As STARTUPINFO
Dim pi                As PROCESS_INFORMATION
Dim baOutput(BUFSIZE) As Byte
Dim sOutput           As String
Dim lBytesRead        As Long
    With sa
        .nLength = Len(sa)
        .bInheritHandle = 1    ' get inheritable pipe handles
    End With 'SA
    If CreatePipe(hPipeRead, hPipeWrite, sa, 0) = 0 Then
        Exit Function
    End If

    With si
        .cb = Len(si)
        .dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
        .wShowWindow = SW_HIDE          ' hide the window
        .hStdOutput = hPipeWrite
        .hStdError = hPipeWrite
    End With 'SI
    If CreateProcess(vbNullString, sCommandLine, ByVal 0&, ByVal 0&, 1, 0&, ByVal 0&, sStartInFolder, si, pi) Then
        Call CloseHandle(hPipeWrite)
        Call CloseHandle(pi.hThread)
        hPipeWrite = 0
        Do
            'DoEvents
            If ReadFile(hPipeRead, baOutput(0), BUFSIZE, lBytesRead, ByVal 0&) = 0 Then
                Exit Do
            End If
            sOutput = sOutput & Left$(StrConv(baOutput(), vbUnicode), lBytesRead)
            'cTextBox.SelText = sOutput
        Loop
        Call CloseHandle(pi.hProcess)
    End If
    ' To make sure...
    Call CloseHandle(hPipeRead)
    Call CloseHandle(hPipeWrite)
    ExecAndCapture = sOutput
End Function

时间: 2024-11-05 19:34:45

vb6截取控制台命令执行结果的代码的相关文章

神漏洞!macOS也能弹计算器,一行JS代码远程命令执行

本文讲的是神漏洞!macOS也能弹计算器,一行JS代码远程命令执行,最近,Google Project Zero公开披露了一个macOS系统的神漏洞,一行JS代码便可以让Mac电脑弹计算器. 这个神漏洞真的特别有趣,研究员发现macOS的内置应用HelpViewer有一个内部协议调用,可以打开本机上的任何文件,这个协议调用的路径检查有点缺陷,使用某些特定语法可以绕过,去打开攻击者指定的文件. 以上只能做到本地命令执行,研究员想了个法子,用JS代码去调用HelpViewer打开文件,间接做到远程执

java方法执行控制台命令工具类

package com.yanek.util; import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; public class Tool { /** * @param args */ public static void main(String[] args) { System.out.println(executeCommond("ipconfig"

ssh批量登录并执行命令的python实现代码_python

局域网内有一百多台电脑,全部都是linux操作系统,所有电脑配置相同,系统完全相同(包括用户名和密码),ip地址是自动分配的.现在有个任务是在这些电脑上执行某些命令,者说进行某些操作,比如安装某些软件,拷贝某些文件,批量关机等.如果一台一台得手工去操作,费时又费力,如果要进行多个操作就更麻烦啦. 或许你会想到网络同传, 网络同传是什么?就是在一台电脑上把电脑装好,配置好,然后利用某些软件,如"联想网络同传"把系统原样拷贝过去,在装系统时很有用,只要在一台电脑上装好,同传以后所有的电脑都

【MongoDB】6.关于MongoDB存储文件的 命令执行+代码执行

参考:http://www.runoob.com/mongodb/mongodb-gridfs.html 1.命令执行 MongoDB GridFS GridFS 用于存储和恢复那些超过16M(BSON文件限制)的文件(如:图片.音频.视频等). GridFS 也是文件存储的一种方式,但是它是存储在MonoDB的集合中. GridFS 可以更好的存储大于16M的文件. GridFS 会将大文件对象分割成多个小的chunk(文件片段),一般为256k/个,每个chunk将作为MongoDB的一个文

QCMS V2.0命令执行与暴绝对路径漏洞

QCMS是 一款小型的网站管理系统.拥有多种结构类型,包括:ASP+ACCESS.ASP+SQL.PHP+MYSQL.今天叫兄弟们一起挖掘QCMS的漏洞,与大家分享挖洞的全过程.498)this.width=498;' onmousewheel = 'javascript:return big(this)' style="width: 498px; height: 208px" border="0" alt="QCMS V2.0命令执行与暴绝对路径漏洞&q

NSA泄密事件之SMB系列远程命令执行漏洞及Doublepulsar后门全球数据分析

本文讲的是NSA泄密事件之SMB系列远程命令执行漏洞及Doublepulsar后门全球数据分析, 1.   概述 2017 年 4 月 14 日,黑客组织Shadow Brokers 公布了一批新的NSA(美国国家安全局)黑客工具.这批黑客工具中含有可以配合使用的一个攻击框架和多个攻击漏洞.这次的工具主要面向的是Windows系统,攻击框架非常易用,漏洞也大都是核弹级别的RCE(远程命令执行),配合框架和漏洞,可以非常容易地在存在漏洞的 Windows 主机上执行命令.植入后门.一时间,各路选手

又被野外利用了!新曝光Office产品多个远程命令执行漏洞分析

本文讲的是又被野外利用了!新曝光Office产品多个远程命令执行漏洞分析, 早在2015年,FireEye曾发布过两次关于Office的Encapsulated PostScript (EPS)图形文件的漏洞攻击的研究分析,其中一次属于零日漏洞攻击. 今年3月开始,FireEye再一次在微软Office产品中陆续发现三个新的零日漏洞,发现时这些漏洞已被野外利用. 第一个漏洞出现在今年的3月下旬,CVE-2017-0261中描述了Office远程代码执行漏洞(RCE)漏洞,FireEye认为该漏洞

java调用控制台命令进行文件转码问题

问题描述 java调用控制台命令进行文件转码问题 public static String mxf2ts(File fileString fileName){ String mxfFilePath = """"""+file.getPath()+"""""";// mxf文件 String tsFilePath = """"""

惠普打印机爆远程命令执行漏洞,黑客可任意操纵你的打印机

本文讲的是惠普打印机爆远程命令执行漏洞,黑客可任意操纵你的打印机,在各类企业.单位甚至是学校,无论你身处在哪里,打印机都会作为必需品存在.也许你体验到的是其便捷的一面,但你是否了解其作为联网设备的危害在哪里呢?仔细回想一下,你上一次更新它的固件是什么时候?你是否了解过打印机所存在的那些漏洞? 出于对打印机安全性的好奇,我们购买了几台打印机(HP OfficeJet Pro 8210).事实上,在买的时候我们一直祈祷其那些易受攻击的固件仍然存在,否则你肯定无法想象你需要多少时间来进行回溯.幸运的是