How do I launch a non-interactive GUI from a windows 10 service written in python?

683 Views Asked by At

I am trying to automate running "Teststand" scripts from a Windows service. So far I've accomplished the automation by calling the following from the command prompt:

C:\Program Files (x86)\National Instruments\TestStand 2013\Bin> 
SeqEdit.exe /runEntryPoint "Single Pass" "c:\Users\pathtofile\MyTests.seq" /quit

I'm using Python, so I make this happen using the subprocess module. It opens, runs, saves results, and closes on its own. Perfect!!! However, because it launches the Teststand GUI, it won't work in a Windows service. I don't even need the GUI (because I don't touch it, and results stored in a folder), but I can't seem to run Teststand without it.

I've messed around with CreateProcessAsUser() using win32 but I can't seem to get anything to work. Can anyone offer a solution in Python that uses the command above to run a Teststand sequence from a Windows service (windows 10)???

1

There are 1 best solutions below

0
adambro On

On option could be to use the TestStand API to run the sequence using the engine directly. Here is an example from the NI Knowledge Base:

import win32com.client
tsEngine = win32com.client.Dispatch('TestStand.Engine.1')
print('TestStand %s.%s ready' % (tsEngine.MajorVersion, tsEngine.MinorVersion))
sequencePath = 'C:\\Users\\Desktop\\Sequence File 1.seq'
seqFile = tsEngine.GetSequenceFileEx(sequencePath)
execution = tsEngine.NewExecution(seqFile, "MainSequence", None, False, 0)
execution.WaitForEndEx(60000)
print(execution.ResultStatus)
tsEngine.ReleaseSequenceFileEx(seqFile, 0x4)

I have found from using this that for it to close cleanly I had to use del to clear up the references to execution and seqFile and also to handle UIMessages to ensure there are none outstanding at the end of the execution.