Jump to content

Why isn't my script executing as a rec. svc task?


Recommended Posts

Hello, I have a problem with recording service's tasks. I have made some vbscript code which I compile to exe with vbstoexe. It executes perfectly when run manually. But when I set it as recording service task it does not execute. I have run it as both .exe and through a dos bat file with cscript.exe but neither one works fully.

 

Here is a small piece of test code that gave me a clue of what might be wrong:

 

Set oFSO = CreateObject("Scripting.FileSystemObject") ' this part works
Set File = oFSO.OpenTextFile("test.txt", 8, True)
File.WriteLine("testing")
File.Close

set oDVBV=getobject(,"dvbviewerserver.DVBViewer") ' this part doesn't work
oDVBV.OSD.ShowInfo "TESTTEST","TEST!","",10,"Cancel"

 

Writing to the test file works but OSD message part does not execute. If I change the order of the code so that the OSD part is first and file writing last then neither one executes. Running that code manually works either way. So it seems that there is something that I am not getting about tasks and COM. When this piece of script is run manually everything in it works. And so does my main script too but just not as a recording service task :angry:

 

Anyone have any idea what is wrong with the piece of code above? And yes, I have DVBViewer running when the task executes and there are no error messages.

 

thanks :bye:

 

patti

Edited by patti
Link to comment

Tried running both service and DVBViewer with SYSTEM account. Didn't work either. Or did you mean something else with "account" than SYSTEM account? Is it possible to run a service task that interacts with DVBViewer COM?

 

thanks,

 

patti

Link to comment

After testing some more I have found out that it does not depend on the user account that the processes run under. I have run both service and DVBViewer with SYSTEM and my tv user account and neither one works. Is it so, that because DVBViewer is started under explorer.exe and service under services.exe they work in a different "sandbox" although they are run with same user privileges?

 

edit:

I just found out that my task executes perfectly if I start dvbservice.exe under explorer.exe so it is a parent process sandbox problem.

 

Now I just need to find out how to run DVBViewer under services.exe when started from explorer.exe :bye:

/edit

 

patti

Edited by patti
Link to comment

If someone knows how to make service see DVBViewer COM interface when service is run under services.exe and DVBViewer under explorer.exe then please, let me know. Thank you :bye:

 

patti

Link to comment

Search on Remote Scripting! Its a technology which allows scripts and programs that are running inside a browser to exchange information with a server. The local scripts can invoke scripts on the remote side and process the returned information.

Link to comment

Thanks, this sounds interesting and I already found some good info on this one. Will let everyone know how it works once I get more into this. Right now I am too busy but later...

 

Thanks,

 

patti

Link to comment

After looking at remote skripting I noticed that WSH also allows running scripts remotely. I wonder if it is possible to run a "remote" script in the local machine with different credentials and thus access DVBViewer COM from recording service. I'll check it out when I have more time.

 

patti

Link to comment

I use a remotescript from the application Object Dock contacting the server on Homeseer and when the connection is done i can control every z-wave and IR-device in my house from Object Dock. Normally this is done from inside of Homeseer. So executing scripts from RS in order to control parts in DVBViewer through COM should be possible. Hard part is only to figure out how to make the remote connection.

My Object Dock - Homeseer remote vbs script looks like this anyhow...maybe it can be helpful in some way. You will at least see the method in how the remote connection is done in the second and third part of the script.

 

' first part starts HomeSeer2 in case of it is not already running
On Error Resume Next
strComputer = "."
arrTargetProcs = Array("HomeSeer.exe")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each strTargetProc In arrTargetProcs
Set colProcesses = objWMIService.ExecQuery _
  ("SELECT * FROM Win32_Process WHERE Name='" & strTargetProc & "'")
If colProcesses.Count = 0 Then
	Set WshShell = WScript.CreateObject("WScript.Shell")
	Return = WshShell.Run("""E:\HomeSeer HS2 Startscript.exe""", 1, true)
	Set WshShell = Nothing
End If
Next
'****************************************************************************
*****
' this is the Device Status INI script
' it retrives Status on Devices in HomeSeer and writes it to an INI file
' it will work only if runned outside of HomeSeer
Dim hsi	 'connection object to homeseer
Dim hs	  'hs object
connect_to_hs()
hs.PollDevice "Q3" 'Setup Poll Status Values for Q3 (PERSIENN_VARDAGSRUM)
WScript.Sleep(100)
Q3Status = hs.DeviceStatus("Q3")
If Q3Status = 2 Then
	Q3StatusText = "ON"
	hs.SaveINISetting "PERSIENN_VARDAGSRUM","key",Q3StatusText,"my_device_status.ini"
End If
If Q3Status = 3 Then
	Q3StatusText = "OFF"
	hs.SaveINISetting "PERSIENN_VARDAGSRUM","key",Q3StatusText,"my_device_status.ini"
End If
set wshshell = nothing
set hs = Nothing
set hsi = Nothing
'===================
Sub connect_to_hs()
', hs As Object
	set hsi = CreateObject("HomeSeer2.application")
	If hsi Is Nothing Then
		MsgBox("Couldn't get hsi object")
	End If
	hsi.SetHost("localhost")
	rval = hsi.Connect("user", "password")
	If rval <> "" Then
		MsgBox("hsi rval: " & rval)
		exit sub
	End If
	  'hsi.speak("Connected")
	set hs = hsi.GetHSRef
	'hs.speak("Processing")
End Sub

Edited by majstang
Link to comment
  • 4 weeks later...

Thanks Majstang, I haven't had time to check out remote scripting because of other duties. I did find out why recording service and DVBViewer won't interact even when started with same credentials (=SYSTEM). Services in Win7 (ans Vista) are run on session 0 and user programs in session 1. These are isolated from each other because of potential security risks. Read more here: http://windowsteamblog.com/windows/b/devel...-isolation.aspx

 

patti

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...