Lancement d'un .bat et d'un vbscript dans un service

Résolu
terminathan Messages postés 7 Date d'inscription lundi 9 mars 2009 Statut Membre Dernière intervention 3 septembre 2009 - 14 mai 2009 à 11:43
terminathan Messages postés 7 Date d'inscription lundi 9 mars 2009 Statut Membre Dernière intervention 3 septembre 2009 - 14 mai 2009 à 12:13
Bonjour à tous!

J'ai un problème pour le développement d'un service sur visual studio 2008...
J'ai réussi à créer l'exe pour l'installation du service, celui-ci se lance.

J'ai ensuite créé un bat de test juste pour lancer un bat depuis mon service: ça marche.
Enfin, on m'a confié les deux fichier sur lequel ce service windows doit travailler. L'un des deux est un .bat, et l'autre un .vbs.
J'ai essayé au hasard d'utiliser la même commande d'appel, mais lors du débogage, un message d'erreur s'affiche:

Voici les détails de l'erreur si ça peut être utile:

"L'exception System.Reflection.TargetInvocationException n'a pas été gérée
  Message="Une exception a été levée par la cible d'un appel."
  Source="mscorlib"
  StackTrace:
       à System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       à System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       à System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       à System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
       à System.ServiceProcess.ServiceBase.LateBoundMessageBoxShow(String message, String title)
       à System.ServiceProcess.ServiceBase.Run(ServiceBase[] services)
       à ScriptLauncher.ServiceScriptLauncher.Main() dans D:\ICOF\Programmation\C\ScriptLauncher\ServiceScriptLauncher.Designer.vb:ligne 33
       à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.FileNotFoundException
       Message="Fichier introuvable."
       Source="Microsoft.VisualBasic"
       StackTrace:
            à Microsoft.VisualBasic.Interaction.Shell(String PathName, AppWinStyle Style, Boolean Wait, Int32 Timeout)
            à ScriptLauncher.ServiceScriptLauncher.Timer_Tick(Object sender, EventArgs e) dans D:\ICOF\Programmation\C\ScriptLauncher\ServiceScriptLauncher.vb:ligne 6
            à System.Windows.Forms.Timer.OnTick(EventArgs e)
            à System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
            à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
            à System.Windows.Forms.SafeNativeMethods.MessageBox(HandleRef hWnd, String text, String caption, Int32 type)
            à System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp)
            à System.Windows.Forms.MessageBox.Show(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
       InnerException: "

Ce service a pour but de lancer toute les 2 minutes les deux fichier afin de vérifier une base de donnée (étant en stage de première année outre-manche, je n'ai malheureusement pas saisis tous les détails du truc...

Et voici le code de mon service:

Public Class ServiceScriptLauncher
    Protected Overrides Sub OnStart(ByVal args() As String)
        Timer.Enabled = True
    End Sub
    Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
        Call Shell("c:\scriptintermediaire.bat)")
        Call Shell("c:\permissions.bat,1")
    End Sub
    Protected Overrides Sub OnStop()
        Timer.Enabled = False
    End Sub
End Class

Voilà, si quelqu'un peu éclairer ma lanterne que je comprenne un peu ce qui se passe ça serai sympa!
Merci d'avance,
Jonathan

PS: j'espère être dans la bonne section?

3 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
14 mai 2009 à 11:57
Call Shell("c:\scriptintermediaire.bat)")

tu bosses pas en VB6, toi ?

oublie ces commandes de compatibilité.

utilises Process.Start
3
terminathan Messages postés 7 Date d'inscription lundi 9 mars 2009 Statut Membre Dernière intervention 3 septembre 2009
14 mai 2009 à 11:53
et zut je me suis planté,
dans cette version de mon code, j'essayais d'appeler le vbs via un batch intermédiaire... Mais ça ne marche pas non plus, mon code étais donc:
Public Class ServiceScriptLauncher
    Protected Overrides Sub OnStart(ByVal args() As String)
        Timer.Enabled = True
    End Sub
    Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
        Call Shell("c:\new.vbs)")
        Call Shell("c:\permissions.bat,1")
    End Sub
    Protected Overrides Sub OnStop()
        Timer.Enabled = False
    End Sub
End Class

PS: Il n'y a pas moyen d'éditer ses précédents messages?
0
terminathan Messages postés 7 Date d'inscription lundi 9 mars 2009 Statut Membre Dernière intervention 3 septembre 2009
14 mai 2009 à 12:13
Ok! Ça à l'air de marcher!
Bon déjà grâce à toi j'ai pu voir que je m'étais planté sur une parenthèse déjà,
Et puis concernant les commandes, c'était la première fois que je devais lancer des scripts depuis du vb... Du coup je me suis servi de google pour trouver un peu comment faire, et faut dire que des fois on tombe sur des réponses qui datent un peu!
Process.start fonctionne bien, je n'ai plus de message d'erreur!

Merci Renfield !
0
Rejoignez-nous