简体   繁体   中英

How to run Command Prompt commands from VB.NET?

I have an application which build in vb.net.I never learn VB.I have worked on C#.net.when I run it's setup and execute it,I able to see command prompt.But when I using this application for scheduling task/creating task and scheduling, unable to see command prompt.

I am using following code that create process.

Dim Cw As New ProcessStartInfo(name, name & " " & name)
Cw.WindowStyle = ProcessWindowStyle.Maximized
Process.Start(Cw)

Is there is any other way to do this?Without making a process can I execute shell program?I am working on windows8 opeating system

You can use a simply Shell command, so:

Shell(path_to_your_exe, AppWinStyle.MaximizedFocus, true, 1000)

Be careful with path, if you have blanks escape they so

Shell(""d:\folder blank\my.exe"") 

MSDN: https://msdn.microsoft.com/es-es/library/microsoft.visualbasic.interaction.shell(v=vs.110).aspx

If I understood the question, you might be using a Windows Form Application and you want to see the command line info of your external application.

In that case, you can use this code:

Sub Main()

    Dim ProcessStartInfo = BuildProcessStartInfo("E:\path\to\your\exeFile.exe", "")
    Dim proc = Process.Start(ProcessStartInfo)

End Sub

Public Function BuildProcessStartInfo(exeFilePath As String, arguments As String) As ProcessStartInfo

    Dim startInfo = New ProcessStartInfo
    startInfo.FileName = exeFilePath
    startInfo.Arguments = arguments
    startInfo.CreateNoWindow = False
    startInfo.UseShellExecute = True
    startInfo.WindowStyle = ProcessWindowStyle.Maximized

    Return startInfo

End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM