vba 如何在 VB6 中不打开 CMD 窗口的情况下运行 shell 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8735463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:22:25  来源:igfitidea点击:

How to run a shell command without opening a CMD window in VB6

windowsvbavb6batch-file

提问by Ashkan Mobayen Khiabani

the following code is part from my VB6 program

以下代码是我的 VB6 程序的一部分

I used shell command in the VB in order to execute the pscp.exe with the flags and arguments

我在 VB 中使用了 shell 命令来执行带有标志和参数的 pscp.exe

my problem is , when VB run the line:

我的问题是,当 VB 运行该行时:

      Shell strCommand, 1  

its also open the CMD window for 2-4 seconds (CMD popup window)

它还会打开 CMD 窗口 2-4 秒(CMD 弹出窗口)

my question - is it possible to run the "Shell strCommand, 1" in way that CMD window will not opened?

我的问题 - 是否可以以不打开 CMD 窗口的方式运行“Shell strCommand, 1”?

I mean - I not want to see any CMD popup window when I run VB application

我的意思是 - 当我运行 VB 应用程序时,我不想看到任何 CMD 弹出窗口

  Const cstrSftp As String = "D:\pscp.exe"
  Dim strCommand As String
  Dim pUser As String
  Dim pPass As String
  Dim pHost As String
  Dim pFile As String
  Dim pRemotePath As String
  pUser = "root"
  pPass = "pass123"
  pHost = "110.218.201.15"
  pFile = """D:\scan_ip.ksh""" 
  pRemotePath = "/var/tmp"

  strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & " " & pHost & ":" & pRemotePath & " " & pFile


  Shell strCommand, 1  

回答by Ashkan Mobayen Khiabani

You can use hidden focus:

您可以使用隐藏焦点:

Shell strCommand, vbHide

or

或者

Shell strCommand, 0

For other focus types look Hereor http://msdn.microsoft.com/en-us/library/aa242087%28v=VS.60%29.aspx(thanks to MarkJ for the link)

对于其他焦点类型,请查看此处http://msdn.microsoft.com/en-us/library/aa242087%28v=VS.60%29.aspx(感谢 MarkJ 提供链接)