Solved
Run Creo Parametric as scheduled task
Hi all,
I would like to create a program that automatically starts Creo Parametric and do a set of operations. To start I created a basic program that only starts Creo and connects to Windchill. Here I already run into some problem where the program runs fine when started normally. However when i start it from Windows Task Scheduler it only runs when the user is logged on. If I select "Run wether the user is logged on or not", Creo fails to start and returns a general error. The user account and machine are the same in all situations. Anyone have an idea how to run Creo as scheduled task? I am using Creo Parametric version 10.0.4.0 and Windows Server 2019.
---------- VB.net code ----------
Imports System.IO
Imports pfcls
Module Module1
Const creoOptions As String = "-g:no_graphics -i:rpc_input"
Const creoStartup As String = "C:\PTC\Creo_10\Creo 10.0.4.0\Parametric\bin\parametric.exe"
Const logFilePath As String = "D:\_TaskScheduler\DXFWorker\CreoAsyncConnect.log"
Const proCommMsg As String = "C:\PTC\Creo_10\CREO10~1.0\COMMON~1\X86E_W~1\obj\pro_comm_msg.exe"
Const ptcWfCache As String = "D:\_TaskScheduler\DXFWorker\work\.cache"
Const ptcWfRoot As String = "D:\_TaskScheduler\DXFWorker\work\.wf"
Const ptcWldRoot As String = "D:\_TaskScheduler\DXFWorker\work\.wld"
Const windchillLogin As String = "********"
Const windchillPassword As String = "********"
Sub Main()
Using sw As New StreamWriter(logFilePath)
Environment.SetEnvironmentVariable("PRO_COMM_MSG_EXE", proCommMsg, EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("PTC_WF_CACHE", ptcWfCache, EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("PTC_WF_ROOT", ptcWfRoot, EnvironmentVariableTarget.Process)
Environment.SetEnvironmentVariable("PTC_WLD_ROOT", ptcWldRoot, EnvironmentVariableTarget.Process)
Dim asyncConnection As IpfcAsyncConnection = Nothing
Try
sw.WriteLine("Start Creo")
Dim cAC As New CCpfcAsyncConnection
asyncConnection = cAC.Start(Chr(34) & creoStartup & Chr(34) & " " & creoOptions, Nothing)
Dim session As IpfcBaseSession = CType(asyncConnection.Session, IpfcBaseSession)
sw.WriteLine("Creo started")
sw.WriteLine("Connect Creo to Windchill")
session.AuthenticateBrowser(windchillLogin, windchillPassword)
Dim serverLocation As IpfcServerLocation = session.GetServerLocation(windchillServer)
sw.WriteLine("Creo connected to Windchill")
Catch ex As Exception
sw.WriteLine(ex.Message & vbCrLf & ex.StackTrace)
Finally
sw.WriteLine("Close Creo")
If Not IsNothing(asyncConnection) Then
asyncConnection.End()
End If
sw.WriteLine("Creo closed")
End Try
End Using
End Sub
End Module
---------- Script output ----------
Start Creo
pfcExceptions::XToolkitGeneralError
at pfcls.ICpfcAsyncConnection.Start(String _CmdLine, Object _TextPath)
at CreoAsyncConnect.Module1.Main()
Close Creo
Creo closed
pfcExceptions::XToolkitGeneralError
at pfcls.ICpfcAsyncConnection.Start(String _CmdLine, Object _TextPath)
at CreoAsyncConnect.Module1.Main()
Close Creo
Creo closed

