Précédent   Forum du club des développeurs et IT Pro > Autres langages > Général Visual Basic 6 et VBScript > VBScript
VBScript Le forum d'entraide sur VBScript. Avant de poster -> La FAQ VBScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 28/12/2012, 23h27   #1
hackoofr
Expert Confirmé
 
Avatar de hackoofr
 
Homme Mehdi Tounisiano
Enseignant
Inscription : juin 2009
Messages : 1 631
Détails du profil
Informations personnelles :
Nom : Homme Mehdi Tounisiano
Âge : 38
Localisation : Tunisie

Informations professionnelles :
Activité : Enseignant

Informations forums :
Inscription : juin 2009
Messages : 1 631
Points : 3 692
Points : 3 692
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 :
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 :
Citation:
Ligne:91
Caract:12
Erreur : Objet requis: 'c:\icon.ico'
Code :800A01A8
Source :Erreur d'exécution Microsoft VBScript
DotNetWrapper.vbs :
Code :
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
hackoofr est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/12/2012, 15h40   #2
Daynvheur
Nouveau Membre du Club
 
Technicien Help Desk
Inscription : 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
En extrayant juste la partie sur l'inclusion d'icône, ça donne une erreur à la ligne du corps ici :
Code :
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 :
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 ?
Daynvheur est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/01/2013, 14h44   #3
hackoofr
Expert Confirmé
 
Avatar de hackoofr
 
Homme Mehdi Tounisiano
Enseignant
Inscription : juin 2009
Messages : 1 631
Détails du profil
Informations personnelles :
Nom : Homme Mehdi Tounisiano
Âge : 38
Localisation : Tunisie

Informations professionnelles :
Activité : Enseignant

Informations forums :
Inscription : juin 2009
Messages : 1 631
Points : 3 692
Points : 3 692
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 :
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 :
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
Citation:
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.
hackoofr est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/01/2013, 09h57   #4
Daynvheur
Nouveau Membre du Club
 
Technicien Help Desk
Inscription : 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
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 ?
Daynvheur est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/01/2013, 09h29   #5
derick
Invité de passage
 
Homme
Inscription : 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 :
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
derick est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/01/2013, 13h28   #6
hackoofr
Expert Confirmé
 
Avatar de hackoofr
 
Homme Mehdi Tounisiano
Enseignant
Inscription : juin 2009
Messages : 1 631
Détails du profil
Informations personnelles :
Nom : Homme Mehdi Tounisiano
Âge : 38
Localisation : Tunisie

Informations professionnelles :
Activité : Enseignant

Informations forums :
Inscription : juin 2009
Messages : 1 631
Points : 3 692
Points : 3 692
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 :
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 :
Citation:
Erreur : Argument ou appel de procédure incorrect
Ligne : 85
Cararct: 7
hackoofr est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 19h41.


 
 
 
 
Partenaires

Hébergement Web