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

Résolu/Fermé
LaCigale Messages postés 5 Date d'inscription samedi 17 novembre 2012 Statut Membre Dernière intervention 24 novembre 2012 - 17 nov. 2012 à 06:00
LaCigale Messages postés 5 Date d'inscription samedi 17 novembre 2012 Statut Membre Dernière intervention 24 novembre 2012 - 24 nov. 2012 à 03:51
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!!
A voir également:

1 réponse

lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 1 190
23 nov. 2012 à 15:02
Bonjour,
Une variable ne doit pas être mise entre guillemets.
Une piste ..
"/c shutdown -s -t " & TotalSec

A+
0
LaCigale Messages postés 5 Date d'inscription samedi 17 novembre 2012 Statut Membre Dernière intervention 24 novembre 2012
24 nov. 2012 à 03:51
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