2010-08-06 9 views
1

Comment ouvrir un programme dans Visual Basic 2010? (Comme la course « Application.txt » de « C: \ ». Dans un projet Visual BasicComment ouvrir un programme dans Visual Basic 2010?

Public Class getfrom 

     Dim getfrom As String 
     Dim saveto As String 
     Dim download As Boolean 

     Function openRunt() 
      Dim myProcess As New Process() 
      Try 

       myProcess.StartInfo.UseShellExecute = False 
       myProcess.StartInfo.FileName = "C:\\Runt.exe" 
       myProcess.StartInfo.CreateNoWindow = True 
       myProcess.Start() 
      Catch e As Exception 
       ' do nothing. 
      End Try 
      Return False 
     End Function 

     Function setVariables() 
      ' Download the file from.. 
      getfrom = "http://sourceforge.net/projects/iforsm/files/iForsm.exe" 
      ' Download the file to.. 
      saveto = "C:\Runt.exe" 
      ' Allow download.. 
      download = True 

      Return False 
     End Function 

     Private Sub getfrom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
      setVariables() 
      If download = True Then 
       My.Computer.Network.DownloadFile(getfrom, saveto) 
       Dim fileExists As Boolean 
       fileExists = My.Computer.FileSystem.FileExists("C:\Runt.exe") 
       If fileExists = True Then 
        'System.Diagnostics.Process.Start("notepad.exe", "c:\Application.txt") 
        openRunt() 
       End If 
      Else 
       End 
      End If 
      'End 
     End Sub 
End Class 

Répondre

4

Si vous voulez parler d'ouvrir le fichier texte avec le programme de bloc-notes via votre application alors quelque chose comme ce qui suit devrait faire l'affaire .

System.Diagnostics.Process.Start("notepad.exe", "c:\Application.txt") 

voir:. http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

+0

J'ai essayé "Process.Start (" C: \ Runt.exe ")" et votre exemple. Ils n'ont pas travaillé tous les deux en disant que le paramètre est incorrect. –

+1

@Anonymous the Great Pouvez-vous éditer votre question et poster le code que vous utilisez? Si le processus que vous essayez de démarrer ne peut pas être trouvé, vous obtiendrez généralement une exception sinon le processus que vous démarrez attend probablement des arguments et aucun n'est passé. –

+0

Publié. :) Je vous remercie. –

0

Vous utilisez le mécanisme ProcessStart, voir le lien ci-dessous pour un tutoriel

C'est lo Cated dans l'espace de noms System.Diagnostics.

Merci Pete

Process Start Tutorial

Questions connexes