Author Topic: C# ChangeLoginUser Security Not enabled  (Read 2361 times)

Kristian Walker

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
C# ChangeLoginUser Security Not enabled
« on: February 25, 2014, 12:22:55 am »
I have a C# console application that i have created which opens up a backup .eap and generates some HTML output.

However as the Backup file is encrypted when the app opens the file it prompts for the admin username and password.

I have tried use the following line in my code r.ChangeLoginUser("Myusernamehere","Mypasswordhere");

However when i run the app i get a System.Runtime.InteropServices.COMException: Security not enabled error

My code is below.

Could someone tell me how i can bypass the error and have the app switch to the admin user before opening the file.

CODE:

Code: [Select]
using System;
using System.Runtime.Remoting.Channels;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;

namespace SparxHtmlPublication
{
      class Program
      {
            public static void Main(string[] args)
            {
                  

                  Console.Title = "Sparx Automation HTML Publication App:";
                  Console.ForegroundColor =  ConsoleColor.Yellow;
                  Console.WindowHeight = 50;
                  
                  // Console Welcome Text
                  Console.WriteLine("Welcome to the Sparx Automation HTML Publication App:\n ");
                  htmlpublish.open();
                  Console.Write("HTML Published - Press any key to exit . . . ");
                  Console.ReadKey(true);

            }
            
            class htmlpublish
            {
                  
                  public static void open()

                  {
                        
                        EA.Repository r = new EA.Repository();
                        
                        
                        try
                        {
                              r.ChangeLoginUser("Usernamehere","Passwordhere");
                        }
                        catch (System.Runtime.InteropServices.COMException e)
                        {
                              Console.WriteLine("Changing to Admin User Failed");
                              Console.WriteLine(r.IsSecurityEnabled);
                              throw e;
                        }
                        
                        
                        r.OpenFile("C:\\sparxbackup\\Backup01.eap");                        
                        Console.WriteLine("Generating HTML  ..\n" +
                                          "\n " +
                                          "Please be Patient:\n");
                        // Guid is set to the IT package in the persisent repository which includes the teams and domains sub folders
                        r.GetProjectInterface().RunHTMLReport("{C9139357-5C1E-493f-8344-3DF51A14F7A8}","C:\\sparxhtmltest\\html","png","default","htm" );
                        // Safely close the backup file when finished with it.
                        r.CloseFile();
                        
                  }
                  
            }
      }
}

Kristian Walker

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: C# ChangeLoginUser Security Not enabled
« Reply #1 on: February 25, 2014, 01:08:08 am »
I have fixed this by using the openfile2 method which takes 3 paramaters (file path, username , password). The code i used is below:

Code: [Select]
                 r.OpenFile2("C:\\sparxbackup\\Backup01.eap","username","password");
« Last Edit: February 25, 2014, 01:08:43 am by walkek4 »