gopalhazel
asked on
To invoke vb.net exe from windows service in vb.net
Hello,
I have a VB.net exe which I want to invoke or run from a windows service implemented in VB.NET.
When timer fires, at that time i want to invoke vb.net exe.
I tried the normal way of invoking applications thruough the process command but it doesn't seem to work in case of Windows services in VB.NET. Please help me out...this is urgent,
code for the above is as:
Public Sub TimerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
Try
Dim psList() As Process
Dim str_Proc As String
psList = Process.GetProcesses
For Each p As Process In psList
str_Proc = p.ProcessName
If str_Proc.Contains("AutoBac kup-Icon") Then p.Kill()
Next p
mf_ChkIconExe()
str_IconExePath="C:\Hazel Infotech\AutoBackup Utility\AutoBackup-Icon.ex e"
Process.Start(str_IconExeP ath, "Start")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, str_MsgTitle)
End Try
End Sub
but, AutoBackup-Icon.exe doesn't get start..
please help me out, its very urgent......
I have a VB.net exe which I want to invoke or run from a windows service implemented in VB.NET.
When timer fires, at that time i want to invoke vb.net exe.
I tried the normal way of invoking applications thruough the process command but it doesn't seem to work in case of Windows services in VB.NET. Please help me out...this is urgent,
code for the above is as:
Public Sub TimerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
Try
Dim psList() As Process
Dim str_Proc As String
psList = Process.GetProcesses
For Each p As Process In psList
str_Proc = p.ProcessName
If str_Proc.Contains("AutoBac
Next p
mf_ChkIconExe()
str_IconExePath="C:\Hazel Infotech\AutoBackup Utility\AutoBackup-Icon.ex
Process.Start(str_IconExeP
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, str_MsgTitle)
End Try
End Sub
but, AutoBackup-Icon.exe doesn't get start..
please help me out, its very urgent......
Is the program you're trying to start a GUI program?
>but, AutoBackup-Icon.exe doesn't get start..
You mean it does not show up in the Processes list or you are unable to see the interface? You would not be able to see its interface because the services, and the processes started by services are run in a separate environment than the current user's desktop.
You mean it does not show up in the Processes list or you are unable to see the interface? You would not be able to see its interface because the services, and the processes started by services are run in a separate environment than the current user's desktop.
<< but, AutoBackup-Icon.exe doesn't get start.. >>
So are you using the NotifyIcon control? Your service is running under the services session *NOT the desktop session. If your application needs to interacts with the user then you have to open the executable in the desktop session. There is no managed counterpart yet so you will have to use P/Invoke. If your service is running as LocalSystem then use WTSGetActiveConsoleSession Id, WTSQueryUserToken and CreateProcessAsUser. It's also important to create the environment block if the application references special location or uses common dialogs.
Example
http:Q_26273307.html
So are you using the NotifyIcon control? Your service is running under the services session *NOT the desktop session. If your application needs to interacts with the user then you have to open the executable in the desktop session. There is no managed counterpart yet so you will have to use P/Invoke. If your service is running as LocalSystem then use WTSGetActiveConsoleSession
Example
http:Q_26273307.html
ASKER
yes, I m using notify control in AutoBackup-Icon.exe and form size for this exe is of 0 size. so only icon gets displayed in system tray on running AutoBackup-Icon.exe .
so can anybody give me the sample code to start this exe.
so can anybody give me the sample code to start this exe.
Did you try the link posted by eql1044?
There is an example @ http:Q_26273307.html on how to accomplish opening a process from LocalSystem service onto the current desktop session. Just noticed the example is classic VB6 so it has to be converted.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
egl1044,
Thanks a lot..above example helped me a lot..It worked.
But, I have more query, I want start exe alongwith parameters, how do i start that using ServiceShell.Start
for e.g.
"C:\Hazel Infotech\AutoBackup Utility\AutoBackup-Icon.ex e Start" where "start" is parameter.
Thanks a lot..above example helped me a lot..It worked.
But, I have more query, I want start exe alongwith parameters, how do i start that using ServiceShell.Start
for e.g.
"C:\Hazel Infotech\AutoBackup Utility\AutoBackup-Icon.ex
Try using second parameter.
ServiceShell.Start("C:\Hazel Infotech\AutoBackup Utility\AutoBackup-Icon.exe", " Start", Nothing)
ASKER
egl1044,
I tried the way you said, but it is not accepting parameter as "Start" instead it takes as blank parameter only..
any idea..what else we can do????
I tried the way you said, but it is not accepting parameter as "Start" instead it takes as blank parameter only..
any idea..what else we can do????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
egl1044,
thanks a lot.it worked...
thanks a lot.it worked...