简体   繁体   English

如何更新从 VBA Shell 或 WScript.Shell 调用的 cmd.exe?

[英]How do I update cmd.exe called from VBA Shell or WScript.Shell?

I'd like to update the command prompt called from VBA shell or WScript.Shell command and start wsl.exe.我想更新从 VBA shell 或 WScript.Shell 命令调用的命令提示符并启动 wsl.exe。 This is because wsl.exe is not included in the command prompt called by shell or WScript.Shell.这是因为 wsl.exe 不包含在 shell 或 WScript.Shell 调用的命令提示符中。

在此处输入图片说明

Sub Sample1()
    Dim WSH, wExec, sCmd, Result As String

    Set WSH = CreateObject("WScript.Shell")
    sCmd = "dir c:\Windows\System32\ws*.exe"
    Set wExec = WSH.Exec("%ComSpec% /c " & sCmd)

    Do While wExec.Status = 0
        DoEvents
    Loop

    Result = wExec.StdOut.ReadAll

    MsgBox Result

    Set wExec = Nothing
    Set WSH = Nothing
End Sub
' VBA
Private Sub RunBatShell(ByVal strPath As String)
    Dim dProcessId As Double

    BAT_FILE = strPath + "vuln.bat"

    dProcessId = Shell("cmd.exe /c;" & " " & BAT_FILE & " " & strPath, vbNormalFocus)

    If dProcessId = 0 Then
        MsgBox "Failed"
    End If

    ' MsgBox "Done"
End Sub



@echo off
REM Vuln.bat
REM 実行環境を引数でもらう
echo 引数: %1

REM echo > cd %1
cd %1

set PARAM=C:\Windows\Sysnative\wsl.exe ./vuln.sh
REM echo %PARAM%
cmd /c %PARAM%

REM echo Done
REM pause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM