0

I am writing a WPF app in C# which opens another program in the background. In my case I am opening TIA-Portal (a SIEMENS Software). To open a project the TIA-Portal needs an access authorization from the user. But the window of the access authorization always appears behind my MainWindow.

The code I am using:

private void openTIA_Click(object sender, RoutedEventArgs e) 
    {
        OpenFileDialog SearchTIAProject = new OpenFileDialog();
        SearchTIAProject.Title = "TIA Projekt öffnen";
        SearchTIAProject.Filter = "TIA Portal Project|*.ap14";

        if (SearchTIAProject.ShowDialog() == true)
        {
            Block_PfadDesTIAProgramms.Visibility = System.Windows.Visibility.Visible;
            Block_PfadDesTIAProgramms.Text = (SearchTIAProject.FileName);
            string projectpath = SearchTIAProject.FileName;
            myPublicPath = GetPublicPath(projectpath);
            myOpenedTIAProject = OpenTIAProject(projectpath); //Functioncall
        }
        else
        {
            MessageBox.Show("Keine Datei ausgewählt!");
        }
    }

public Siemens.Engineering.Project OpenTIAProject(string referedPath) 
    {
        myTIAPortal = new TiaPortal(TiaPortalMode.WithoutUserInterface);
        ProjectComposition projects = myTIAPortal.Projects;
        FileInfo projectPathTIA = new FileInfo(referedPath);
        //This line then needs the access authorization:
        myOpenedTIAProject = projects.Open(projectPathTIA); 

        return myOpenedTIAProject;
    }

I have also tried this around the functioncall but it did not work:

MainWindow.Topmost = false;
myOpenedTIAProject = OpenTIAProject(projectpath);
MainWindow.Topmost = true;
MainWindow.Topmost = false;

Is there any way to the access authorization to the foreground (or the MainWindow to the background)?

Victor .S
  • 37
  • 8
  • The parameter `TiaPortalMode.WithoutUserInterface` seems to imply that it shouldn't even *have* a UI coming up. Are you sure you cannot simply pass the credentials to the portal in code and not have a UI show up at all? – nvoigt Sep 25 '18 at 08:14
  • No this is unfortunately not possible. The WithoutUserInterface is like opening Excel in the background with ExApp.Visibility = false; But TIA needs an authorisation to open. – Victor .S Sep 25 '18 at 08:53
  • What good would that parameter be then? Why would it *exist* even? I still think you will find documentation on how to pass credentials, but I don't have access to the documentation. Do you? Could you post a link? – nvoigt Sep 25 '18 at 08:56

0 Answers0