IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Comment exécuter un programme ou un fichier depuis un fichier .hta


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2013
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Février 2013
    Messages : 1
    Par défaut Comment exécuter un programme ou un fichier depuis un fichier .hta
    Bonjour,

    Je suis novice sur ce type de développement.

    Y a t il quelqu'un de généreux qui pourrait m'aider à exécuter un programme ou un fichier .hta dans une page web (les chemins de mes programmes ou fichiers persos sont saisie sur un .xml) ?
    Je coche le programme ou mon fichier que je veux (après avoir ajouter dans le .xml) et valider par OK, celui-ci doit se lancer.

    Voici le code dont je dois modifier.

    liste_programme_perso.hta
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    <html>
    <head>
    <title>LAncement des programmes</title>
    <HTA:APPLICATION
      APPLICATIONNAME="JAVARUNNER"
      ID="JAVARUNNER"
      BORDER="dialog"
      INNERBORDER="no"
      MAXIMIZEBUTTON="no"
      SCROLL="no"
      VERSION="1.0"/>
    </head>
     
    <script language="VBScript">
     
    Sub Window_OnLoad
                    Dim width,height
                    width=500
                    height=300
                    self.ResizeTo width,height
                    self.MoveTo (screen.AvailWidth-width)/2,(screen.AvailHeight-height)/2
      'This method will be called when the application loads
      'Add your code here
    End Sub
     
    Function CreateProcess(cmd)
    '               Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    '               Set objStartup = objWMIService.Get("Win32_ProcessStartup")
    '               Set objConfig = objStartup.SpawnInstance_
    '               objConfig.ShowWindow = 1 'SHOW_WINDOW
    '               Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    '               CreateProcess = objProcess.Create(cmd, dir, objConfig, intProcessID)
                    oWScriptShell.Run cmd
    End Function
     
    Sub OnClickButtonOK()
            For Each button in myradio
                If button.Checked Then 
                    value = button.value
                    exit For
                end If
            Next
            'msgbox value
            CreateProcess value 
                   'window.Close
    End Sub
     
     
    Sub OnClickButtonCancel()
      'This method will be called when Cancel is clicked
      'Add your code here
      window.Close
    End Sub
     
    </script>
     
    <body bgcolor="#B0C4DE">
     
     
    <script language="VBScript">
     
    Set oWScriptShell = CreateObject("WScript.Shell")
    Set oFileSystem = CreateObject("Scripting.FileSystemObject")
    USERPROFILE = oWScriptShell.ExpandEnvironmentStrings("%USERPROFILE%")
    XMLFILE = USERPROFILE & "\\Documents\\VIRTUAL_USER_APPLI\\User_Appli.xml"
     
    'MsgBox XMLFILE
     
      Set objXMLDoc = CreateObject("Microsoft.XMLDOM")  
         objXMLDoc.async = False  
     
         objXMLDoc.load(XMLFILE)
     
    document.write("<table border=0 width=100% height=100%>               ")
    document.write("<tr><td height=100% width=100% valign=top align=left>")
    document.write("<!--Add your controls here-->")
     
    'New
    set root = objXMLDoc.documentElement
    set objProfileList = root.getElementsByTagName("Profile")
    for each prof in objProfileList
    set attribs = prof.attributes
    nom = attribs.getNamedItem("nom").nodeValue
     
      set profileNodeList = prof.childNodes
      for each child in profileNodeList
        if child.hasChildNodes Then
         document.write( "<input type=""radio"" name=""myradio"" value=""" & child.firstChild.nodeValue & """>" & nom & "<BR>")
        else
          MsgBox child.nodeName      
        end if
      next
        ' blank line
    next
     
                    document.write("<!--{{InsertControlsHere}}-Do not remove this line-->")
                    document.write("</td></tr>")
                    document.write("<tr><td align=right>")
                    document.write("<input type=""button"" style=""width: 80px"" name=""OK"" id=""OK"" value=""OK"" onclick=""OnClickButtonOK"">&nbsp;")
                    document.write("<input type=""button"" style=""width: 80px"" name=""Cancel"" id=""Cancel"" value=""Annuler"" onclick=""OnClickButtonCancel"">")
                    document.write("</td></tr>")
                    document.write("</table>")
     
     
    </script>
     
    </body>
    </html>
    Le fichier USER_Appli.xml ressemble à ca :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <List Created="03/03/2013" By="IT RES">
        <Profiles>
    	<Profile nom="Commande DOS">
    		<AppliPath>cmd</AppliPath>
    	</Profile>
    	<Profile nom="Explorer">
    		<AppliPath>Explorer</AppliPath>
    	</Profile>
    	<Profile nom="CALculatrice">
    		<AppliPath>calc</AppliPath>
    	</Profile>
    	<Profile nom="Mon text">
    		<AppliPath>"\\USERPROFILE\\DESKTOP\mon text.txt"</AppliPath>
    	</Profile>
         </Profiles>
    </List>

    Sauf que le programme cmd et explorer ainsi que je la calculatrice fonctionnent (va chercher dans le dossier %windir%\System32).
    Mais dès lors que je rajoute des fichiers persos supplémentaires, il ne va pas le chercher.



    Merci à vos suggestions, remarques et surtout vos solutions.

  2. #2
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 420
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 420
    Par défaut
    La différence c'est que les chemins de Calc, Explorer et Cmd se trouvent dans la variable d'environnement PATH.
    Si tu ajoutes le chemin du fichier à lancer dans la variable d'environnement "PATH", le code saura le trouver ou tout simplement, tu le mets en dur dans le fichier XML sous la forme nom="......\UnDossier\Mon Text.txt"
    Ne pas oublier le tag si satisfait.
    Voter pour toute réponse satisfaisante avec pour encourager les intervenants.
    Balises CODE indispensables. Regardez ICI
    Toujours utiliser la clause Option Explicit(VBx, VBS ou VBA) et Ne jamais typer variables et/ou fonctions en VBS.
    Vous pouvez consulter mes contributions
    Ne pas oublier de consulter les différentes FAQs et les Cours/Tutoriels VB6/VBScript
    Ne pas oublier L'Aide VBScript et MSDN VB6 Fr

Discussions similaires

  1. Comment exécuter un programme java en dehors d'eclipse
    Par padraig29 dans le forum Eclipse Java
    Réponses: 8
    Dernier message: 06/03/2007, 17h36
  2. [Fortran 95] Comment exécuter mon programme ?
    Par silver2 dans le forum Fortran
    Réponses: 1
    Dernier message: 15/01/2007, 16h15
  3. [UBUNTU] Comment exécuter le programme Latex ?
    Par Keuf95 dans le forum Ubuntu
    Réponses: 1
    Dernier message: 11/08/2006, 17h54
  4. Comment exécuter un programm
    Par Murieyaya dans le forum Langage
    Réponses: 2
    Dernier message: 13/12/2005, 10h50
  5. Comment exécuter un programme externe ?
    Par spikto dans le forum Langage
    Réponses: 12
    Dernier message: 27/06/2005, 16h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo