早期在vb6常會利用"DosShell",類似呼叫Dos Command的方式來開啟外部程式
在VB.NET提供了更完整的呼叫外部程式的方式-Process
以下舉例呼叫ipconfig來release IP
Dim process As New System.Diagnostics.Process()
'呼叫的外部程式名稱
process.StartInfo.FileName = "ipconfig"
'外部程式所需之參數
process.StartInfo.Arguments = "/release"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardError = False
process.StartInfo.RedirectStandardInput = False
process.StartInfo.RedirectStandardOutput = True
process.Start()
process.WaitForExit()
If Not process.HasExited Then
process.Kill()
End If
process.Close()
或
'簡單的寫法
process.start("ipconfig","/release")
沒有留言:
張貼留言