0

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)???

  • Have you tried configuring your Windows Service as the user that installed the "Teststand" software (who can run the GUI)? – CoreTech Oct 30 '17 at 22:44
  • I thought windows services ran as SYSTEM. How do I run it as a particular user? – Corey Pullium Oct 31 '17 at 16:07
  • Use [services.msc](https://www.coretechnologies.com/blog/windows-services/essential-tools-windows-services-msc/) to change the properties of your service. Specify a username & password on the service's "Log On" tab. – CoreTech Nov 01 '17 at 11:22

1 Answers1

0

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.

adambro
  • 310
  • 4
  • 16