传递多个参数cmd vb.net

时间:2015-06-29 12:42:42

标签: vb.net

我搜索了谷歌和stackoverflow很多,但没有解决方案

我试图在cmd中传递多个参数 他们就像这样

Dim argu1 As String = "netsh wlan set hostednetwork mode = allow  ssid=" + TextBox1.Text + " key=" + TextBox2.Text
    Dim argu2 As String = "netsh wlan start hostednetwork"
    Dim process As System.Diagnostics.Process = Nothing
    Dim processStartInfo As System.Diagnostics.ProcessStartInfo
    processStartInfo = New System.Diagnostics.ProcessStartInfo
    processStartInfo.FileName = "cmd.exe"
    processStartInfo.Verb = "runas"

以这种方式写论据

    processStartInfo.Arguments = argu1 & argu2
    processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
    processStartInfo.UseShellExecute = True
    Try
        process = System.Diagnostics.Process.Start(processStartInfo)
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Unknown Error !", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        If Not (process Is Nothing) Then
            process.Dispose()
        End If
    End Try

但没有发生任何事情

所以请告诉我如何传递多个参数

1 个答案:

答案 0 :(得分:3)

您期望发生什么?你正在执行

cmd.exe netsh wlan set hostednetwork mode = allow  ssid=... key=...netsh wlan start hostednetwork

只是启动cmd.exe的新实例,忽略所有netsh ...内容。

have a look at the documentation of cmd.exe。特别是,我怀疑/c命令行开关可能正是您要找的。也就是说,您可能需要考虑直接调用netsh.exe或者(甚至更好)搜索使用Windows API或.NET库实现的方法。

相关问题