Intégrer une variable à une commande windows en vb.net

Résolu
LaCigale Messages postés 5 Statut Membre -  
LaCigale Messages postés 5 Statut Membre -
Bonjour,

Sauriez-vous comment intégrer la variable TotalSec a la commande Shutdown ci dessous pour que la commande exécutée soit : shutdown -s -t (valeur de TotalSec) ?

Voila mon code:


    Dim TotalSec As Integer

 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        
        TotalSec = 50 'valeur de TotalSec
        Dim myProcess As New Process()
        myProcess.StartInfo.FileName = "cmd.exe"  
        myProcess.StartInfo.Arguments = "/c shutdown -s -t (TotalSec) " 'Commande a exécuter
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.Start()  'lance le process
        myProcess.WaitForExit()  'attend qu'il soit terminé avant d'aller plus loin
        myProcess.Close()  'ferme le process

    End Sub



D'avance merci pour toute aide!!

1 réponse

  1. lermite222 Messages postés 9042 Statut Contributeur 1 199
     
    Bonjour,
    Une variable ne doit pas être mise entre guillemets.
    Une piste ..
    "/c shutdown -s -t " & TotalSec

    A+
    0
    1. LaCigale Messages postés 5 Statut Membre
       
      Merci beaucoup, j'ai trouvé la solution :

      Public Sub Shutdown()
      
              Conversion()
              Dim myProcess As New Process()
              myProcess.StartInfo.FileName = "cmd.exe"  'l'application
              myProcess.StartInfo.Arguments = String.Format(" /c shutdown -s -t  {0}", TotalSec)
              myProcess.StartInfo.CreateNoWindow = True
              myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
              myProcess.Start()  'lance le process
              myProcess.WaitForExit()  'attend qu'il soit terminé avant d'aller plus loin
              myProcess.Close()  'ferme le process
              ResultLabel.Text = String.Format("Windows s'éteindra dans {0} heure(s) et {1} Minute(s).", NumericUpDownHeure.Value, NumericUpDownMinute.Value)
      
          End Sub


      A+
      0