VB.Net服务触发另一个应用程序 [英] VB.Net Service to fire another Application

查看:101
本文介绍了VB.Net服务触发另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我编写了一项服务,需要不时启动应用程序.
我在事件日志中没有收到错误,但是该应用程序也没有被触发.

以下是一些代码:

Hi,

I wrote a Service that needs to fire an app from time to time.
I do not get an error in the Eventlog, but neither is the app being fired.

Here are some code:

Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        
        Dim proc As New System.Diagnostics.Process()
        Dim iShell As Integer = 0

        Timer1.Enabled = False
        Timer1.Stop()

        Try

            WriteLogMessage("Gaan nou App launch", EventLogEntryType.Information)

            Dim myProcess As Process = New Process
            myProcess.StartInfo.FileName = "MMSServiceApp.exe"
            myProcess.StartInfo.Arguments = "1"
            myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            myProcess.StartInfo.CreateNoWindow = False
            myProcess.StartInfo.WorkingDirectory = "C:\"
            myProcess.Start()
            myProcess.WaitForExit(60000)
            If Not myProcess.HasExited Then
                WriteLogMessage("Gaan nou App Kill", EventLogEntryType.Information)
                myProcess.Kill()
            End If
            myProcess.Close()
            WriteLogMessage("Gaan nou Process Close", EventLogEntryType.Information)

            ''proc.StartInfo.WorkingDirectory = "C:\Jakes\"
            ''proc.StartInfo.FileName = "MMSServiceApp.exe;1"

            ''proc.Start()
            ''System.Diagnostics.Process.Start("C:\MMSServiceApp.exe", "")
            ''iShell = Shell("C:\MMSServiceApp.exe", AppWinStyle.NormalFocus, False, -1)
            
        Catch ex As Exception
            WriteLogMessage(ex.ToString, EventLogEntryType.Information)
            WriteLogMessage("Server = " & sServer & " Database = " & sDatabase, EventLogEntryType.Error)
        End Try



        Timer1.Enabled = True
        Timer1.Start()
    End Sub



有什么建议吗?
提前谢谢.



Any suggestions?
Thanks in advance.

推荐答案

好吧,如果应用程序.EXE在PATH中的某个位置,则它将启动.我强烈建议为您要启动的.EXE构建完全限定的路径名​​.

可能是,您的应用正在启动,但是显示在Windows服务桌面上,而不是用户看到的桌面上.您仍然可以查看它是否正在任务管理器中运行.

尝试在用户桌面上启动交互式应用程序是一个不好的主意.您可以在Windows XP和更低版本上使用它,但是在Vista和更高版本上,Microsoft不鼓励使用此行为.
Well, if the app .EXE is in the PATH somewhere, it''s being launched. I would HIGHLY recommend building fully qualified pathnames of the .EXE you want to launch though.

Chances are, your app IS being launched, but it''s showing on the windows services desktop and not the desktop the user sees. You can stil see if it''s running in Task Manager though.

Trying to launch an interactive app on the users desktop is a BAD IDEA. You can get away with in on Windows XP and below, but on Vista and above, this behavior is discouraged by Microsoft.


请尝试使用应用程序的完整路径,例如
Try using the full path of the applicatio, like this
myProcess.StartInfo.FileName = "C:\MyApp\MMSServiceApp.exe"


这篇关于VB.Net服务触发另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆