英文:
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.
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论