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

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

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中进行更新?

  1. Sub Sample1()
  2. Dim WSH, wExec, sCmd, Result As String
  3. Set WSH = CreateObject("WScript.Shell")
  4. sCmd = "dir c:\Windows\System32\ws*.exe"
  5. Set wExec = WSH.Exec("%ComSpec% /c " & sCmd)
  6. Do While wExec.Status = 0
  7. DoEvents
  8. Loop
  9. Result = wExec.StdOut.ReadAll
  10. MsgBox Result
  11. Set wExec = Nothing
  12. Set WSH = Nothing
  13. End Sub

答案1

得分: 1

Here's the translated content from the provided code:

  1. ' VBA
  2. Private Sub RunBatShell(ByVal strPath As String)
  3. Dim dProcessId As Double
  4. BAT_FILE = strPath + "vuln.bat"
  5. dProcessId = Shell("cmd.exe /c;" & " " & BAT_FILE & " " & strPath, vbNormalFocus)
  6. If dProcessId = 0 Then
  7. MsgBox "Failed"
  8. End If
  9. ' MsgBox "Done"
  10. End Sub
  1. @echo off
  2. REM Vuln.bat
  3. REM Get the execution environment as an argument
  4. echo Argument: %1
  5. REM echo > cd %1
  6. cd %1
  7. set PARAM=C:\Windows\Sysnative\wsl.exe ./vuln.sh
  8. REM echo %PARAM%
  9. cmd /c %PARAM%
  10. REM echo Done
  11. REM pause

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

英文:
  1. ' VBA
  2. Private Sub RunBatShell(ByVal strPath As String)
  3. Dim dProcessId As Double
  4. BAT_FILE = strPath + "vuln.bat"
  5. dProcessId = Shell("cmd.exe /c;" & " " & BAT_FILE & " " & strPath, vbNormalFocus)
  6. If dProcessId = 0 Then
  7. MsgBox "Failed"
  8. End If
  9. ' MsgBox "Done"
  10. End Sub
  11. @echo off
  12. REM Vuln.bat
  13. REM 実行環境を引数でもらう
  14. echo 引数: %1
  15. REM echo > cd %1
  16. cd %1
  17. set PARAM=C:\Windows\Sysnative\wsl.exe ./vuln.sh
  18. REM echo %PARAM%
  19. cmd /c %PARAM%
  20. REM echo Done
  21. 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:

确定