Hi, I try to run Catia under the Licence server in an Web C#.Net application. For this I use following C# code:
public void StartCatia(bool bVisible)
{
Type oCat = Type.GetTypeFromProgID("Catia.Application");
try
{
aCatia = (INFITF.Application)Activator.CreateInstance(oCat);
//this.CloseLicences();
if (aCatia == null)
throw new Exception();
}
catch (Exception e)
{
WebMsgBox.Show(e.Message + e.InnerException + "Catia aplikacija neuspesno pokrenuta!");
}
finally
{
aCatia.Visible = bVisible;
}
}
For checking Licence I use following code:
public bool CheckDSLSLicense(string MyLicenseName)
{
/** query CATIA License server to know if license is available
MyLicenseName : ST1 , MD2 , DMO ...
CheckDSLSLicense = True : OK license is available , False , not available
run command DSCheckLS.exe -r ST1 and analyse return string,
"C:\Program Files\Dassault Systemes\catiav5\win_b64\code\bin\DSCheckLS.exe"
// Xavier KLEIN Staubli 2020-04-16
to use this script , you have to
1 update path for MyPathDSCheckLS = "C:\Program Files\Dassault Systemes\catiav5\win_b64\code\bin\DSCheckLS.exe"
2 uncomment line and add at begining of your VB Code
//Private Declare Sub Sleep Lib "kernel32"(ByVal dwMilliseconds As Long) // Sleep used for Tempo*/
bool checkLicense = false;
///1) Check path DSCheckLS.exe
///
string MyPathDSCheckLS;
FileSystem Fso = null; // File system objet : Manipulation des fichiers
/// indicate path where you catia code is located
/// KOD NAS JE: c:\Program Files\Dassault Systemes\B23\win_b64\code\bin\DSCheckLS.exe
MyPathDSCheckLS = "C:\\Program Files\\Dassault Systemes\\B23\\win_b64\\code\\bin\\DSCheckLS.exe";
if (Fso.FileExists(MyPathDSCheckLS))
{
// ok Go on
}
else
{
WebMsgBox.Show("DSCheckLS.exe not found: -(update your path " + MyPathDSCheckLS);
}
///2) run Command
/// "C:\Program Files\Dassault Systemes\catiav5\win_b64\code\bin\DSCheckLS.exe" -r ST1 | findstr "ST1" | findstr "successfully granted"
string MyCommandLine = null;
string MyCommandResult = null;
string MyCommandFile = null;
bool TaskId = false; // to run Shell
// use a Temp Directory : TEMP : C:\Users\xkle\AppData\Local\Temp
MyCommandResult = System.Environment.GetEnvironmentVariable("TEMP") + "\\DSCheckLS.txt";
MyCommandFile = System.Environment.GetEnvironmentVariable("TEMP") + "\\DSCheckLS.cmd";
// MyCommandLine = """" & MyPathDSCheckLS & """" & " -r " & MyLicenseName & " findstr " & """" & MyLicenseName & """" & " | findstr " & """" & "successfully granted" & """" & " > " & """" & MyCommandResult & """" & " ; pause "
MyCommandLine = """ + MyPathDSCheckLS + """ + " -r " + MyLicenseName + " > " + """ + MyCommandResult + """ + " ; exit ";
if (Fso.FileExists(MyCommandResult))
{
Fso.DeleteFile (MyCommandResult);
}
if (Fso.FileExists(MyCommandFile))
{
Fso.DeleteFile (MyCommandFile);
}
/**IOtvaranje MyCommandFile za upis i upis MyCommandLine u fajl i zatvaranje:
Open MyCommandFile For Output As #1
Print #1, MyCommandLine
Close #1
*/
FileStream fs = File.Open(MyCommandFile, FileMode.Open, FileAccess.Write, FileShare.None);
File.WriteAllText(MyCommandFile, MyCommandLine);
fs.Close();
/**Run exe fajl in Visual Basic!!!
TaskId = Shell(Environ("ComSpec") & " /C start " & MyCommandFile, vbNormalFocus)
TaskId = Microsoft.VisualBasic.Interaction.Shell(MyCommandFile, Microsoft.VisualBasic.Constants.vbMinimizedNoFocus);
*/
///Run exe fajl in C#
///
Process process = new Process();
process.StartInfo.FileName = MyCommandFile;
TaskId = process.Start();
///3) wait to get result file
///
int icount = 0; // timer to wait for command return
INFITF.File MyFileObject = null; // FileObject
for (icount = 1; icount <= 600; icount++) // wait 60 second
{
Thread.Sleep (100);
if (Fso.FileExists(MyCommandResult))
{
// check size > 0
MyFileObject = Fso.GetFile(MyCommandResult);
if (MyFileObject.Size > 0)
{
goto OkResultFound;
}
continue;
}
}
// no result file after 60 seconds, assume license not available
checkLicense = false;
return checkLicense;
///4) Read Result File
///
OkResultFound:
string Data = null;
fs = File.Open(MyCommandResult, FileMode.Open, FileAccess.Read, FileShare.None);
Data = File.ReadAllText(MyCommandResult);
fs.Close();
if (Data.IndexOf("successfully") + 1 > 0)
{
checkLicense = true; // OK License Is avaiable
}
else
{
checkLicense = false; // license not available
}
return checkLicense;
}
But when I run the application, I got the following error, as if Licence Addministration Tool is not runnning:
I ckecked Licence Administration Tool and it is still running.
Can you halp me, please?