Код: Выделить всё
Set Connect_Manager = CreateObject("pcomm.autECLConnMgr")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set ObjEmulator = CreateObject("pcomm.auteclsession")
autECLConnList.Refresh
Num = autECLConnList.Count
PrevNum = Num
If Num = 0 Then
MsgBox "You must have at least two PCOMM sessions open to use this tool." & vbnewline & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "No Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
End If
strSession = autECLConnList(Num).Name
Connect_Manager.autECLConnList.Refresh
ObjEmulator.SetConnectionByName (strSession)
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle
If InStr(Window_Title, "HOSTORS") 0 Or strSession = "A" Or InStr(Window_Title, "NDB") 0 Then
Set ObjEmulator = Nothing
Loop_Count = 1
Do
ResEmulator = "No"
PrevNum = PrevNum - 1
If PrevNum = 0 Then
MsgBox "You need to have more than one session open." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "One Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Else
strSession = autECLConnList(PrevNum).Name
If strSession = "A" Then
MsgBox "You cannot use your production (A) session." & vbnewline & "Please open another session." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Exit Do
Else
Set ObjEmulator = CreateObject("pcomm.auteclsession")
Connect_Manager.autECLConnList.Refresh
ObjEmulator.SetConnectionByName (strSession)
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle
If InStr(Window_Title, "NDB") 0 Or InStr(Window_Title, "HOSTORS") 0 Then
Set ObjEmulator = Nothing
Else
ResEmulator = "Yes"
End If
End If
End If
Loop_Count = Loop_Count + 1
If Loop_Count = 10 Then
MsgBox "Unable to connect to a session." & vbnewline & "Please make sure you have working sessions." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Exit Do
End If
Loop Until ResEmulator = "Yes"
End If
Код: Выделить всё
AutConnList autECLConnList = new AutConnList();
AutConnMgr Connect_Manager = new AutConnMgr();
AutSess ObjEmulator = new AutSess();
autECLConnList.Refresh();
int Num = autECLConnList.Count;
int PrevNum = Num;
if (Num == 0)
{
MessageBox.Show("You must have at least two PCOMM sessions open to use this tool." + Environment.NewLine + Environment.NewLine + "Program is now terminating.", "No Session Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
return;
}
string strSession = autECLConnList[Num].Name;
autECLConnList.Refresh();
ObjEmulator.SetConnectionByName(strSession);
string Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle;
if (Window_Title.IndexOf("HOSTORS") == 0 || strSession == "A" || Window_Title.IndexOf("NDB") == 0)
{
ObjEmulator = null;
int Loop_Count = 1;
string ResEmulator = "No";
do
{
PrevNum -= 1;
if (PrevNum == 0)
{
MessageBox.Show("You need to have more than one session open." + Environment.NewLine + "Program is now terminating.", "One Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
else
{
strSession = autECLConnList[PrevNum].Name;
if (strSession == "A")
{
MessageBox.Show("You cannot use your production (A) session." + Environment.NewLine + "Please open another session." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
else
{
AutSess ObjEmulator = new AutSess();
autECLConnList.Refresh();
ObjEmulator.SetConnectionByName(strSession);
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle;
if (Window_Title.IndexOf("HOSTORS") > 0 || Window_Title.IndexOf("NDB") > 0)
{
ObjEmulator = null;
}
else
{
ResEmulator = "Yes";
}
}
}
Loop_Count++;
if (Loop_Count == 10)
{
MessageBox.Show("Unable to connect to a session." + Environment.NewLine + "Please make sure you have working sessions." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
} while (ResEmulator == "Yes");
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... n-vbscript