UncleT
asked on
Shelling from a "Window Service"
Hello,
I wrote a "Windows Service" that has a timer in it. At the top of every hour I want it to shell out to a .exe file which will process some information. The service seems to be working fine but when it hits the shell command it doesn't seem to do anything. The service was written using "VB 2005". The .exe file I am wanting to shell out to has a parameter to pass to it. I can get to work using a windows app just not the service. Here is what I am using to shell.
Shell("D:\program files\SearchEngineStudio\S earchEngin eStudio.ex e " + Chr(34) + "c:\Search Engine\Policy Manual.ses" + Chr(34) + " /d /r", AppWinStyle.NormalFocus)
Any help would be greatly appreciated.
I wrote a "Windows Service" that has a timer in it. At the top of every hour I want it to shell out to a .exe file which will process some information. The service seems to be working fine but when it hits the shell command it doesn't seem to do anything. The service was written using "VB 2005". The .exe file I am wanting to shell out to has a parameter to pass to it. I can get to work using a windows app just not the service. Here is what I am using to shell.
Shell("D:\program files\SearchEngineStudio\S
Any help would be greatly appreciated.
Private Sub OnTimedEvent(ByVal state As Object)
Dim Hold_Date As Date
oTimer.Dispose()
' Check if the the Event Log Exists
If Not MyLog.SourceExists("SES_Service") Then
MyLog.CreateEventSource("SES_Service", "SES_Service Log") ' Create Log
End If
MyLog.Source = "SES_Service"
Hold_Date = Now
If DatePart(DateInterval.Hour, Hold_Date) <> int_Previous_Hour Then
int_Previous_Hour = DatePart(DateInterval.Hour, Hold_Date)
Shell("D:\program files\SearchEngineStudio\SearchEngineStudio.exe " + Chr(34) + "c:\Search Engine\Policy Manual.ses" + Chr(34) + " /d /r", AppWinStyle.NormalFocus)
' Write to the Log
MyLog.WriteEntry("SES_Service Log", "Search Engine Indexed " & CStr(TimeOfDay), EventLogEntryType.Information)
End If
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
oTimer = New System.Threading.Timer(oCallback, Nothing, 10000, 10000)
End Sub
ASKER
I've already tried that. Currently I've got the service logging on as a domain admin account to see if it is any type of security issues. Also in my service, i just placed a shell command in the timer event to shell out to Notepad. That is not working either. I put log entries before and after the shell command and I am getting both entries in the event viewer but nothing is happening with the shell. Do you or anyone have any more suggestions. This is about to drive me CRAZY!!!!
If you've already tried "Local System account" + "Allow Service to interact with Desktop", then maybe your timer is not firing, for some reason?
Try to shell out to Notepad after sleeping a few seconds, instead of using a timer.
Try to shell out to Notepad after sleeping a few seconds, instead of using a timer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi
there is a fault
the process you can start ProcessASUser.Launch(Progr ammnae,arg uments)
there is a fault
the process you can start ProcessASUser.Launch(Progr
ASKER
Thanks for all the responses but none are working. I even switched the "SearchEngineStudo.exe" with "C:\windows\system32\notep ad.exe" and it still isn't working. I put an event viewer log entry right after I try to open up Notepad and it is getting written to the event viewer. The Notepad should pop up, RIGHT!!!. I attached the timer event code. Any more help would be greatly appreciated.
Private Sub OnTimedEvent(ByVal state As Object)
Dim Hold_Date As Date
oTimer.Dispose()
' Check if the the Event Log Exists
If Not MyLog.SourceExists("SES_Service") Then
MyLog.CreateEventSource("SES_Service", "SES_Service Log") ' Create Log
End If
MyLog.Source = "SES_Service"
Hold_Date = Now
If DatePart(DateInterval.Hour, Hold_Date) <> int_Previous_Hour Then
int_Previous_Hour = DatePart(DateInterval.Hour, Hold_Date)
ProcessAsUser.Launch("C:\windows\system32\notepad.exe", "")
' Write to the Log
''''' THIS IS GETTING WRITTEN TO THE LOG ''''''
MyLog.WriteEntry("SES_Service Log", "Search Engine Indexed " & CStr(TimeOfDay), EventLogEntryType.Information)
End If
Dim oCallback As New TimerCallback(AddressOf OnTimedEvent)
oTimer = New System.Threading.Timer(oCallback, Nothing, 10000, 10000)
End Sub
hmm
when the notpad not popup^s then you have mybe another default desktop
it has two things first the explorer musst run and the desktop musst be the rigth
in the function
Private Shared Function LaunchProcessAsUser .......
change this lines
from
'si.lpDesktop = "WinSta0\Default"
si.lpDesktop = Nothing
to
si.lpDesktop = "WinSta0\Default"
' si.lpDesktop = Nothing
when the notpad not popup^s then you have mybe another default desktop
it has two things first the explorer musst run and the desktop musst be the rigth
in the function
Private Shared Function LaunchProcessAsUser .......
change this lines
from
'si.lpDesktop = "WinSta0\Default"
si.lpDesktop = Nothing
to
si.lpDesktop = "WinSta0\Default"
' si.lpDesktop = Nothing
ASKER
That still didn't work. I want to run a few things by you. You seem to know a lot about this.
1) I am running this on a Virtual Server.
2) When testing it I am using remote desktop to the server.
Does this help? Am I not seeing it come up because of one of these?
Also though. I tried it on my local machine and it didn't work either
1) I am running this on a Virtual Server.
2) When testing it I am using remote desktop to the server.
Does this help? Am I not seeing it come up because of one of these?
Also though. I tried it on my local machine and it didn't work either
ASKER
OK. I changed the line of code back to what you had.
change this lines
TO
'si.lpDesktop = "WinSta0\Default"
si.lpDesktop = Nothing
It worked on my local machine. It is still not working on the Virtual Machine remoted in via Remote Desktop.
Any Suggestions there???
change this lines
TO
'si.lpDesktop = "WinSta0\Default"
si.lpDesktop = Nothing
It worked on my local machine. It is still not working on the Virtual Machine remoted in via Remote Desktop.
Any Suggestions there???
i have tested on VMware and on Windows XP by me it runs
-what os you have local
-can you debug and see the error?
-what os you have local
-can you debug and see the error?
ASKER
Local Machine is Windows XP SP2
VM Machine is Windows Server 2003 SP2
I'm new to .net programming. How do I go about debugging to find the error.
Sorry for the problems but I really appreciate your help.
VM Machine is Windows Server 2003 SP2
I'm new to .net programming. How do I go about debugging to find the error.
Sorry for the problems but I really appreciate your help.
ok
On your Local XP it works
i have tested on a real Windows Server 2003 SP2
it works
no Idee
mybe is a problem with the station/desktop from the virtual Server
i think the forum from Sysinternals can better help you than me
look at this post it is a example
http://forum.sysinternals.com/forum_posts.asp?TID=16714&PN=2
maybe you can post your Problem there
On your Local XP it works
i have tested on a real Windows Server 2003 SP2
it works
no Idee
mybe is a problem with the station/desktop from the virtual Server
i think the forum from Sysinternals can better help you than me
look at this post it is a example
http://forum.sysinternals.com/forum_posts.asp?TID=16714&PN=2
maybe you can post your Problem there
ASKER
OK. I went to VMWare and noticed that the virtual server was already logged on. It was logged on as the same account that I was logged on as "Remote Desktop". When I unlocked the server from VMWARE, I had about 75 Notepads opened up on that server. I did all of my testing using the "Remote Desktop" but the documents were opening up on the VMWARE desktop. Not sure about this one. Anyway, after rebooting the server and bringing it back up everything works like a champ. I split the points between bhagwantsingh and Wegelin because both of your solutions worked. I tested both. I really appreciate your help and being patient. Thanks again. Tim Morrow AKA UncleT.
If this executable is interactive, please check if your service is allowed to interact with the Desktop.
This is done by setting a checkbox in the Services applet screen.
Regards