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 :

DotNetWrapper.vbs pour convertir ".vbs" et ".hta" en ".exe"


Sujet :

VBScript

  1. #1
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut DotNetWrapper.vbs pour convertir ".vbs" et ".hta" en ".exe"

    Voici un script nommé DotNetWrapper.vbs pour convertir ".vbs" et ".hta" en ".exe"
    Ce script a quatre arguments à passer en ligne de commande plus un argument qui est optionnel (ajouter une icône au .exe).
    ce qui m’intéresse c'est l'ajout du l’icône qui ne marche pas
    j'ai fait un petit batch pour lancer la conversion :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @echo off
    DotNetWrapper.vbs "C:\test.vbs" ".vbs" "wscript.exe" "c:\test.exe" "c:\icon.ico"
    alors je récupère comme erreur :
    Ligne:91
    Caract:12
    Erreur : Objet requis: 'c:\icon.ico'
    Code :800A01A8
    Source :Erreur d'exécution Microsoft VBScript
    DotNetWrapper.vbs :
    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    Option Explicit
     Dim dotNetVersion, ScriptFile, ScriptType, LaunchWith, EXEFile, icofile
     Dim fso, WshShell, sysroot, ScriptSource, ScriptContent, workingdir, vbfile, vbsource
     Dim vbcPath, vbcArgs, strCMDLine, debugger, objArgs
     dotNetVersion = "v1.1.4322"
     Set objArgs = WScript.Arguments
     If objArgs.Count < 4 Then
          MsgBox "Missing one or more arguments..." & vbCrLf & _
               "Correct Usage: dotNetWrapper [Script File] [Script Type] [Script Engine] [Output File] [opt - Icon File]" & vbcrlf & vbcrlf & _
               "Script File (ex: C:\Scripts\myscript.vbs)" & vbcrlf & _
               "Script Type (ex: .vbs)" & vbcrlf & _
               "Script Engine (ex: cscript.exe)" & vbcrlf & _
               "Output File (ex: C:\Programs\myscript.exe)" & vbcrlf & _
               "Icon File --optional (ex. C:\Icons\mypicture.ico)"
          WScript.Quit
     End If
     ScriptFile = objArgs(0)
     ScriptType = objArgs(1)
     LaunchWith = objArgs(2)
     EXEFile = objArgs(3)
     If objArgs(4) <> "" Then
          icofile = objArgs(4)
     End If
     Set fso = CreateObject ("Scripting.FileSystemObject")
     Set WshShell = CreateObject("WScript.Shell")
     Set sysroot = fso.GetSpecialFolder(0)
     If Not(fso.FileExists("C:\" & sysroot.name & "\Microsoft.Net\Framework\" & dotNetVersion & "\vbc.exe")) Then
          MsgBox "Unable to locate vbc.exe compiler. Confirm your version of .NET", 16, "ERROR"
          WScript.Quit
     End If
     Set ScriptSource = fso.OpenTextFile(ScriptFile, 1)
     ScriptContent = ""
     Do While Not ScriptSource.AtEndOfStream
               ScriptContent = ScriptContent & CHR(34) & Replace(EncodeScript(ScriptSource.readline), CHR(34), CHR(34) & " & CHR(34) & " & CHR(34)) & CHR(34) & " & vbcrlf & _" & vbcrlf
     Loop
     ScriptContent = ScriptContent & CHR(34) & CHR(34)
     ScriptContent = "ScriptContent = " & CHR(34) & CHR(34) & " & _" & vbcrlf & ScriptContent 
     Set workingdir = fso.GetFile(ScriptFile)
     
     vbfile = "Module Module1" & vbcrlf & _
          "Sub Main()" & vbcrlf & _
          "On Error Resume Next" & vbcrlf & _
          "Dim sPath As String" & vbcrlf & _
          "sPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)" & vbcrlf & _
          "Dim ScriptContent As String" & vbcrlf & _
          ScriptContent & vbcrlf & _
          "Dim oFile As System.IO.File" & vbcrlf & _
          "Dim oWrite As System.IO.StreamWriter" & vbcrlf & _
          "oWrite = oFile.CreateText(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "If Err.Number <> 0 Then" & vbcrlf & _
          "MsgBox(""Unable to open Program. Please make sure you are running this locally."", MsgBoxStyle.Critical, ""Error"")" & vbcrlf & _
          "Exit Sub" & vbcrlf & _
          "End If" & vbcrlf & _
          "oWrite.WriteLine(EncodeScript(ScriptContent))" & vbcrlf & _
          "oWrite.Flush()" & vbcrlf & _
          "oWrite.Close()" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "Shell(""" & LaunchWith & " "" & Chr(34) & sPath & ""\compiledScript" & ScriptType & """ & Chr(34), AppWinStyle.NormalFocus, False)" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "oFile.Delete(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "End Sub" & vbcrlf & _
          "Function EncodeScript(ByVal stringinfo As String)" & vbcrlf & _
          "Dim i As Int16" & vbcrlf & _
          "Dim newstr As String" & vbcrlf & _
          "Dim curchar As Int16" & vbcrlf & _
          "For i = 1 to len(stringinfo)" & vbcrlf & _
          "curchar = asc(mid(stringinfo,i,1))" & vbcrlf & _
          "If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then" & vbcrlf & _
          "If curchar >= 66 and curchar <= 122 Then" & vbcrlf & _
          "newstr = newstr & chr(curchar+128)" & vbcrlf & _
          "else " & vbcrlf & _
          "newstr = newstr & chr(curchar-128)" & vbcrlf & _
          "End If" & vbcrlf & _
          "Else" & vbcrlf & _
          "newstr = newstr & chr(curchar)" & vbcrlf & _
          "end if" & vbcrlf & _
          "next" & vbcrlf & _
          "EncodeScript = newstr" & vbcrlf & _
          "End Function" & vbcrlf & _
          "End Module" & vbcrlf
          Set vbsource = fso.OpenTextFile(workingdir.ParentFolder & "\compiledscript.vb", 2, True)
          vbsource.Write vbfile
          Set vbsource = Nothing
          vbcPath = "C:\" & sysroot.name & "\Microsoft.NET\Framework\" & dotNetVersion & "\vbc.exe"
          vbcArgs = " /out:" & CHR(34) & exefile & CHR(34) & _
          " /nowarn /nologo /quiet /debug- /optimize+ /optionstrict- /optionexplicit- " & _
          "/imports:Microsoft.VisualBasic,System /t:winexe " & _
          CHR(34) & workingdir.ParentFolder & "\compiledscript.vb" & CHR(34) & " > " & _
          CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34)
          If icofile <> "" Then
               vbcargs = " /win32icon:" & CHR(34) & icofile.Value & CHR(34) & vbcArgs & CHR(34)
          End If
          strCMDLine = vbcPath & vbcArgs
          debugger = WshShell.Run("cmd /c " & strCmdLine, 1, True)
          If debugger <> 0 Then
               WshShell.Run CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34), 1, True
          Else
               MsgBox ".EXE Created Successfully!", 64, "Complete"
          End If
          fso.DeleteFile workingdir.ParentFolder & "\debug.txt"
          fso.DeleteFile workingdir.ParentFolder & "\compiledscript.vb"
     
     Function EncodeScript(stringinfo)
          Dim i, curchar, newstr
          for i = 1 to len(stringinfo)
               curchar = asc(mid(stringinfo,i,1))
               If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then
                    If curchar >= 66 and curchar <= 122 Then
                         newstr = newstr & chr(curchar+128)
                    else 
                         newstr = newstr & chr(curchar-128)
                    End If
               Else
                    newstr = newstr & chr(curchar)
               End If
          Next
          EncodeScript = newstr
     End Function

  2. #2
    Nouveau membre du Club
    Profil pro
    Technicien Help Desk
    Inscrit en
    Décembre 2012
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Décembre 2012
    Messages : 23
    Points : 29
    Points
    29
    Par défaut
    En extrayant juste la partie sur l'inclusion d'icône, ça donne une erreur à la ligne du corps ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    If objArgs(4) <> "" Then
         icofile = objArgs(4)
    End If
    [...]
         If icofile <> "" Then
              vbcargs = " /win32icon:" & CHR(34) & icofile.Value & CHR(34) & vbcArgs & CHR(34)
         End If
    En se référant à une autre variable passée en argument (EXEFile), son utilisation est celle-ci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    EXEFile = objArgs(3)
    [...]
         vbcArgs = " /out:" & CHR(34) & exefile & CHR(34) & _
    [...]
    En partant du principe que exefile et EXEFile font référence à la même variable, est-ce que la modification de la ligne 91 en vbcargs = " /win32icon:" & CHR(34) & icofile & CHR(34) & vbcArgs & CHR(34) résout ton soucis ?

  3. #3
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par Daynvheur Voir le message
    En extrayant juste la partie sur l'inclusion d'icône, ça donne une erreur à la ligne du corps ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    If objArgs(4) <> "" Then
         icofile = objArgs(4)
    End If
    [...]
         If icofile <> "" Then
              vbcargs = " /win32icon:" & CHR(34) & icofile.Value & CHR(34) & vbcArgs & CHR(34)
         End If
    En se référant à une autre variable passée en argument (EXEFile), son utilisation est celle-ci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    EXEFile = objArgs(3)
    [...]
         vbcArgs = " /out:" & CHR(34) & exefile & CHR(34) & _
    [...]
    En partant du principe que exefile et EXEFile font référence à la même variable, est-ce que la modification de la ligne 91 en vbcargs = " /win32icon:" & CHR(34) & icofile & CHR(34) & vbcArgs & CHR(34) résout ton soucis ?
    et pour votre réponse
    Oui, malheureusement, j'ai encore une erreur qui se trouve dans le fichier debug.txt
    vbc : error BC30136: Error creating Win32 resources: Erreur lors de la lecture de l'icône '"icon.ico"' -- La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.

  4. #4
    Nouveau membre du Club
    Profil pro
    Technicien Help Desk
    Inscrit en
    Décembre 2012
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Technicien Help Desk

    Informations forums :
    Inscription : Décembre 2012
    Messages : 23
    Points : 29
    Points
    29
    Par défaut
    Est-ce que l'icône C:\icon.ico existe ?
    Sinon, la ligne entière m'étonne :
    vbcargs = " /win32icon:" & CHR(34) & icofile & CHR(34) & vbcArgs & CHR(34),
    vbcargs prend la valeur /win32icon:"c:\icon.ico"[vbcArgs]".
    N'y aurait-il pas une inversion dans l'ordre des affectations des paramètres de cette ligne, ainsi qu'un CHR(34) en trop ?

  5. #5
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Octobre 2006
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2006
    Messages : 2
    Points : 2
    Points
    2
    Par défaut DotNetWrapper.vbs - la suite
    Voici une version adaptée du script DotNetWrapper.vbs, qui permet le lancement du .hta/.vbs compilé là où il se trouve (à place d'un dossier temporaire, prévu par le code d'origine).

    Pourquoi cette version ? Car dans un projet perso (en HTA), j'ai besoin d'aller récupérer des fichiers qui se trouvent au même endroit que le fichier compilé, bref là où est installée l'application.

    Par la même occasion, j'ai corrigé la mini-faute sur l'utilisation de l'icône.
    • Si vous voulez une icône, il faut passer les paramètres suivants dans le cas d'un hta compilé :

      "test.hta" ".hta" "mshta.exe" "test.exe" "test.ico"

    • Si vous ne voulez pas d'icône, il faut passer les paramètres suivants dans le cas d'un hta compilé :

      "test.hta" ".hta" "mshta.exe" "test.exe" ""


    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
     
    Option Explicit
     Dim dotNetVersion, ScriptFile, ScriptType, LaunchWith, EXEFile, icofile
     Dim fso, WshShell, sysroot, ScriptSource, ScriptContent, workingdir, vbfile, vbsource
     Dim vbcPath, vbcArgs, strCMDLine, debugger, objArgs, mydir
     dotNetVersion = "v1.1.4322"
     Set objArgs = WScript.Arguments
     If objArgs.Count < 4 Then
          MsgBox "Missing one or more arguments..." & vbCrLf & _
               "Correct Usage: dotNetWrapper [Script File] [Script Type] [Script Engine] [Output File] [opt - Icon File]" & vbcrlf & vbcrlf & _
               "Script File (ex: C:\Scripts\myscript.vbs)" & vbcrlf & _
               "Script Type (ex: .vbs)" & vbcrlf & _
               "Script Engine (ex: cscript.exe)" & vbcrlf & _
               "Output File (ex: C:\Programs\myscript.exe)" & vbcrlf & _
               "Icon File --optional (ex. C:\Icons\mypicture.ico)"
          WScript.Quit
     End If
     ScriptFile = objArgs(0)
     ScriptType = objArgs(1)
     LaunchWith = objArgs(2)
     EXEFile = objArgs(3)
     If objArgs(4) <> "" Then
          icofile = objArgs(4)
     End If
     Set fso = CreateObject ("Scripting.FileSystemObject")
     Set WshShell = CreateObject("WScript.Shell")
     Set sysroot = fso.GetSpecialFolder(0)
     If Not(fso.FileExists("C:\" & sysroot.name & "\Microsoft.Net\Framework\" & dotNetVersion & "\vbc.exe")) Then
          MsgBox "Unable to locate vbc.exe compiler. Confirm your version of .NET", 16, "ERROR"
          WScript.Quit
     End If
     Set ScriptSource = fso.OpenTextFile(ScriptFile, 1)
     ScriptContent = ""
     Do While Not ScriptSource.AtEndOfStream
               ScriptContent = ScriptContent & CHR(34) & Replace(EncodeScript(ScriptSource.readline), CHR(34), CHR(34) & " & CHR(34) & " & CHR(34)) & CHR(34) & " & vbcrlf & _" & vbcrlf
     Loop
     ScriptContent = ScriptContent & CHR(34) & CHR(34)
     ScriptContent = "ScriptContent = " & CHR(34) & CHR(34) & " & _" & vbcrlf & ScriptContent 
     Set workingdir = fso.GetFile(ScriptFile)
     
     mydir =  fso.GetParentFolderName(workingdir)
     
     vbfile = "Module Module1" & vbcrlf & _
          "Sub Main()" & vbcrlf & _
          "On Error Resume Next" & vbcrlf & _
          "Dim sPath As String" & vbcrlf & _
          "sPath = " & Chr(34) & mydir & Chr(34) & vbcrlf & _
          "Dim ScriptContent As String" & vbcrlf & _
          ScriptContent & vbcrlf & _
          "Dim oFile As System.IO.File" & vbcrlf & _
          "Dim oWrite As System.IO.StreamWriter" & vbcrlf & _
          "oWrite = oFile.CreateText(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "If Err.Number <> 0 Then" & vbcrlf & _
          "MsgBox(""Unable to open Program. Please make sure you are running this locally."", MsgBoxStyle.Critical, ""Error"")" & vbcrlf & _
          "Exit Sub" & vbcrlf & _
          "End If" & vbcrlf & _
          "oWrite.WriteLine(EncodeScript(ScriptContent))" & vbcrlf & _
          "oWrite.Flush()" & vbcrlf & _
          "oWrite.Close()" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "Shell(""" & LaunchWith & " "" & Chr(34) & sPath & ""\compiledScript" & ScriptType & """ & Chr(34), AppWinStyle.NormalFocus, False)" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "oFile.Delete(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "End Sub" & vbcrlf & _
          "Function EncodeScript(ByVal stringinfo As String)" & vbcrlf & _
          "Dim i As Int16" & vbcrlf & _
          "Dim newstr As String" & vbcrlf & _
          "Dim curchar As Int16" & vbcrlf & _
          "For i = 1 to len(stringinfo)" & vbcrlf & _
          "curchar = asc(mid(stringinfo,i,1))" & vbcrlf & _
          "If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then" & vbcrlf & _
          "If curchar >= 66 and curchar <= 122 Then" & vbcrlf & _
          "newstr = newstr & chr(curchar+128)" & vbcrlf & _
          "else " & vbcrlf & _
          "newstr = newstr & chr(curchar-128)" & vbcrlf & _
          "End If" & vbcrlf & _
          "Else" & vbcrlf & _
          "newstr = newstr & chr(curchar)" & vbcrlf & _
          "end if" & vbcrlf & _
          "next" & vbcrlf & _
          "EncodeScript = newstr" & vbcrlf & _
          "End Function" & vbcrlf & _
          "End Module" & vbcrlf
          Set vbsource = fso.OpenTextFile(workingdir.ParentFolder & "\compiledscript.vb", 2, True)
          vbsource.Write vbfile
          Set vbsource = Nothing
          vbcPath = "C:\" & sysroot.name & "\Microsoft.NET\Framework\" & dotNetVersion & "\vbc.exe"
          vbcArgs = " /out:" & CHR(34) & exefile & CHR(34) & _
          " /nowarn /nologo /quiet /debug- /optimize+ /optionstrict- /optionexplicit- " & _
          "/imports:Microsoft.VisualBasic,System /t:winexe " & _
          CHR(34) & workingdir.ParentFolder & "\compiledscript.vb" & CHR(34) & " > " & _
          CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34)
          If icofile <> "" Then
               vbcargs = " /win32icon:" & CHR(34) & icofile & CHR(34) & vbcArgs & CHR(34)
          End If
          strCMDLine = vbcPath & vbcArgs
          debugger = WshShell.Run("cmd /c " & strCmdLine, 1, True)
          If debugger <> 0 Then
               WshShell.Run CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34), 1, True
          Else
               MsgBox ".EXE Created Successfully!", 64, "Complete"
          End If
          fso.DeleteFile workingdir.ParentFolder & "\debug.txt"
          fso.DeleteFile workingdir.ParentFolder & "\compiledscript.vb"
     
     Function EncodeScript(stringinfo)
          Dim i, curchar, newstr
          for i = 1 to len(stringinfo)
               curchar = asc(mid(stringinfo,i,1))
               If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then
                    If curchar >= 66 and curchar <= 122 Then
                         newstr = newstr & chr(curchar+128)
                    else 
                         newstr = newstr & chr(curchar-128)
                    End If
               Else
                    newstr = newstr & chr(curchar)
               End If
          Next
          EncodeScript = newstr
     End Function

  6. #6
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par derick Voir le message
    Voici une version adaptée du script DotNetWrapper.vbs, qui permet le lancement du .hta/.vbs compilé là où il se trouve (à place d'un dossier temporaire, prévu par le code d'origine).

    Pourquoi cette version ? Car dans un projet perso (en HTA), j'ai besoin d'aller récupérer des fichiers qui se trouvent au même endroit que le fichier compilé, bref là où est installée l'application.

    Par la même occasion, j'ai corrigé la mini-faute sur l'utilisation de l'icône.
    • Si vous voulez une icône, il faut passer les paramètres suivants dans le cas d'un hta compilé :

      "test.hta" ".hta" "mshta.exe" "test.exe" "test.ico"


    • Si vous ne voulez pas d'icône, il faut passer les paramètres suivants dans le cas d'un hta compilé :

      "test.hta" ".hta" "mshta.exe" "test.exe" ""


    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
     
    Option Explicit
     Dim dotNetVersion, ScriptFile, ScriptType, LaunchWith, EXEFile, icofile
     Dim fso, WshShell, sysroot, ScriptSource, ScriptContent, workingdir, vbfile, vbsource
     Dim vbcPath, vbcArgs, strCMDLine, debugger, objArgs, mydir
     dotNetVersion = "v1.1.4322"
     Set objArgs = WScript.Arguments
     If objArgs.Count < 4 Then
          MsgBox "Missing one or more arguments..." & vbCrLf & _
               "Correct Usage: dotNetWrapper [Script File] [Script Type] [Script Engine] [Output File] [opt - Icon File]" & vbcrlf & vbcrlf & _
               "Script File (ex: C:\Scripts\myscript.vbs)" & vbcrlf & _
               "Script Type (ex: .vbs)" & vbcrlf & _
               "Script Engine (ex: cscript.exe)" & vbcrlf & _
               "Output File (ex: C:\Programs\myscript.exe)" & vbcrlf & _
               "Icon File --optional (ex. C:\Icons\mypicture.ico)"
          WScript.Quit
     End If
     ScriptFile = objArgs(0)
     ScriptType = objArgs(1)
     LaunchWith = objArgs(2)
     EXEFile = objArgs(3)
     If objArgs(4) <> "" Then
          icofile = objArgs(4)
     End If
     Set fso = CreateObject ("Scripting.FileSystemObject")
     Set WshShell = CreateObject("WScript.Shell")
     Set sysroot = fso.GetSpecialFolder(0)
     If Not(fso.FileExists("C:\" & sysroot.name & "\Microsoft.Net\Framework\" & dotNetVersion & "\vbc.exe")) Then
          MsgBox "Unable to locate vbc.exe compiler. Confirm your version of .NET", 16, "ERROR"
          WScript.Quit
     End If
     Set ScriptSource = fso.OpenTextFile(ScriptFile, 1)
     ScriptContent = ""
     Do While Not ScriptSource.AtEndOfStream
               ScriptContent = ScriptContent & CHR(34) & Replace(EncodeScript(ScriptSource.readline), CHR(34), CHR(34) & " & CHR(34) & " & CHR(34)) & CHR(34) & " & vbcrlf & _" & vbcrlf
     Loop
     ScriptContent = ScriptContent & CHR(34) & CHR(34)
     ScriptContent = "ScriptContent = " & CHR(34) & CHR(34) & " & _" & vbcrlf & ScriptContent 
     Set workingdir = fso.GetFile(ScriptFile)
     
     mydir =  fso.GetParentFolderName(workingdir)
     
     vbfile = "Module Module1" & vbcrlf & _
          "Sub Main()" & vbcrlf & _
          "On Error Resume Next" & vbcrlf & _
          "Dim sPath As String" & vbcrlf & _
          "sPath = " & Chr(34) & mydir & Chr(34) & vbcrlf & _
          "Dim ScriptContent As String" & vbcrlf & _
          ScriptContent & vbcrlf & _
          "Dim oFile As System.IO.File" & vbcrlf & _
          "Dim oWrite As System.IO.StreamWriter" & vbcrlf & _
          "oWrite = oFile.CreateText(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "If Err.Number <> 0 Then" & vbcrlf & _
          "MsgBox(""Unable to open Program. Please make sure you are running this locally."", MsgBoxStyle.Critical, ""Error"")" & vbcrlf & _
          "Exit Sub" & vbcrlf & _
          "End If" & vbcrlf & _
          "oWrite.WriteLine(EncodeScript(ScriptContent))" & vbcrlf & _
          "oWrite.Flush()" & vbcrlf & _
          "oWrite.Close()" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "Shell(""" & LaunchWith & " "" & Chr(34) & sPath & ""\compiledScript" & ScriptType & """ & Chr(34), AppWinStyle.NormalFocus, False)" & vbcrlf & _
          "System.Threading.Thread.Sleep(1000)" & vbcrlf & _
          "oFile.Delete(sPath & ""\compiledScript" & ScriptType & """)" & vbcrlf & _
          "End Sub" & vbcrlf & _
          "Function EncodeScript(ByVal stringinfo As String)" & vbcrlf & _
          "Dim i As Int16" & vbcrlf & _
          "Dim newstr As String" & vbcrlf & _
          "Dim curchar As Int16" & vbcrlf & _
          "For i = 1 to len(stringinfo)" & vbcrlf & _
          "curchar = asc(mid(stringinfo,i,1))" & vbcrlf & _
          "If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then" & vbcrlf & _
          "If curchar >= 66 and curchar <= 122 Then" & vbcrlf & _
          "newstr = newstr & chr(curchar+128)" & vbcrlf & _
          "else " & vbcrlf & _
          "newstr = newstr & chr(curchar-128)" & vbcrlf & _
          "End If" & vbcrlf & _
          "Else" & vbcrlf & _
          "newstr = newstr & chr(curchar)" & vbcrlf & _
          "end if" & vbcrlf & _
          "next" & vbcrlf & _
          "EncodeScript = newstr" & vbcrlf & _
          "End Function" & vbcrlf & _
          "End Module" & vbcrlf
          Set vbsource = fso.OpenTextFile(workingdir.ParentFolder & "\compiledscript.vb", 2, True)
          vbsource.Write vbfile
          Set vbsource = Nothing
          vbcPath = "C:\" & sysroot.name & "\Microsoft.NET\Framework\" & dotNetVersion & "\vbc.exe"
          vbcArgs = " /out:" & CHR(34) & exefile & CHR(34) & _
          " /nowarn /nologo /quiet /debug- /optimize+ /optionstrict- /optionexplicit- " & _
          "/imports:Microsoft.VisualBasic,System /t:winexe " & _
          CHR(34) & workingdir.ParentFolder & "\compiledscript.vb" & CHR(34) & " > " & _
          CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34)
          If icofile <> "" Then
               vbcargs = " /win32icon:" & CHR(34) & icofile & CHR(34) & vbcArgs & CHR(34)
          End If
          strCMDLine = vbcPath & vbcArgs
          debugger = WshShell.Run("cmd /c " & strCmdLine, 1, True)
          If debugger <> 0 Then
               WshShell.Run CHR(34) & workingdir.ParentFolder & "\debug.txt" & CHR(34), 1, True
          Else
               MsgBox ".EXE Created Successfully!", 64, "Complete"
          End If
          fso.DeleteFile workingdir.ParentFolder & "\debug.txt"
          fso.DeleteFile workingdir.ParentFolder & "\compiledscript.vb"
     
     Function EncodeScript(stringinfo)
          Dim i, curchar, newstr
          for i = 1 to len(stringinfo)
               curchar = asc(mid(stringinfo,i,1))
               If (curchar >= 66 and curchar <= 122) or (curchar >=194 and curchar <= 250) then
                    If curchar >= 66 and curchar <= 122 Then
                         newstr = newstr & chr(curchar+128)
                    else 
                         newstr = newstr & chr(curchar-128)
                    End If
               Else
                    newstr = newstr & chr(curchar)
               End If
          Next
          EncodeScript = newstr
     End Function

    Merci de votre réponse mais hélas j'ai une erreur de type :
    Erreur : Argument ou appel de procédure incorrect
    Ligne : 85
    Cararct: 7

Discussions similaires

  1. Réponses: 3
    Dernier message: 03/04/2008, 17h04
  2. VBS pour fichier texte
    Par varan dans le forum VBScript
    Réponses: 4
    Dernier message: 09/01/2008, 22h56
  3. Client : Script vbs pour taches périodiques
    Par bris dans le forum VBScript
    Réponses: 1
    Dernier message: 20/03/2007, 09h42
  4. Script VBS pour copier "Mes documents"
    Par DiabloZizi dans le forum Windows
    Réponses: 1
    Dernier message: 06/03/2006, 22h49
  5. Script VBS pour connaitre taille d'une image
    Par fredoh dans le forum Windows
    Réponses: 2
    Dernier message: 24/02/2006, 14h27

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