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

huangapple go评论92阅读模式
英文:

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. This is because wsl.exe is not included in the command prompt called by shell or WScript.Shell.

英文:

I'd like to update the command prompt called from VBA shell or WScript.Shell command and start wsl.exe.
This is because wsl.exe is not included in the command prompt called by shell or WScript.Shell.

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

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

答案1

得分: 1

Here's the translated content from the provided code:

' 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 Get the execution environment as an argument
echo Argument: %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

Please note that I've translated the code portions and removed the untranslated parts and comments as per your request.

英文:
' 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

huangapple
  • 本文由 发表于 2020年1月6日 21:45:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613237.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定