Using LogInAsUser Method

Hello !

I'm trying to allow an excel document to have admin autorisations so the document can do things the user can't.

In order to do that, I'm trying to connect to my M-Files vault with an admin account when I open the document (as i would with the current user session) :

I define a MFiles Client Application Object :

Dim oClientApp As Object
Set oClientApp = CreateObject("MFilesAPI.MFilesClientApplication")

Then I define my vault connection :

Dim oVaultConnection As Object
Set oVaultConnection = CreateObject("MFilesAPI.VaultConnection")
Set oVaultConnection = oClientApp.GetVaultConnection("Myvault")

And finally, I log in with the correct credentials :

Dim oVault As Object
Set oVault = CreateObject("MFilesAPI.Vault")
Set oVault = oVaultConnection.LogInAsUser(MFAuthTypeSpecificMFilesUser, "Username", "Password")

With Username and Password being the actual username and the actual password.

However, when I run the code, I get the following error :

"Automation error
Indicator proposed incorrect"

I've been trying every possible method and parameters for days and I'm out of options.

Does anyone have a clue on what to do ? The API isn't really helping...

Parents
  • How is the vault connection defined in the client?  Is it set to use (automatic) Windows auth?  What does "oVaultConnection.IsLoggedIn" return?

    My suspicion is that the connection is already made with the current user's details, so it doesn't like you attempting to re-authenticate.  Remember that you're not creating a new connection here, you're re-using whatever the user has configured (and/or is actively using).  You may instead need to switch to a server connection instead, whereby you can control the exact way in which the connection and authentication are made.

    Regards,

    Craig.

  • Hello ! Thanks for the quick reply !

    The vault connection is defined as "MFAuthTypeLoggedOnWindowsUser". "oVaultConnection.IsLoggedIn" return "True". I thought it meant that "oVaultConnection" had established a connection but still had to log in with credentials which was usually made somehow though the "BindToVault" Method. Obviously, I was wrong.

    So I'm now trying to establish a server connection, but I've never done it before, and once again, the API isn't of much help. I first declare : 

    Dim oServerApp As Object
    Set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")

    And then I try to connect to the server using the Connect Method but I don't know if I have to declare an object first or if I just can connect like that. I've tried with the default settings I've seen on the API with no success : same error as before.

    oMFServerConnection = oServerApp.Connect(MFAuthTypeSpecificMFilesUser, "Username", "Password", "ncacn_ip_tcp", "localhost", 2266, "", False)

    Can you tell me what I'm missing ?

  • Have you seen the examples here? Connecting and Authenticating (m-files.com)

    When connecting using the client mode you effectively "inherit" all of the connection details that have already been configured.  When using the server mode you need to explicitly provide both the server details and the credentials to connect with.

    Regards,

    Craig.

  • As Craig said, you need to give all the necessary data to get it. Here's a working example of VBScript

    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect MFAuthTypeSpecificWindowsUser, MFilesAdmin, MFilesAdminPass, MFilesBase, MFProtocol , MFServerAddress , MFServerPort
    Set oVault = oServerApp.LogInToVault(VaultGUID)	

Reply
  • As Craig said, you need to give all the necessary data to get it. Here's a working example of VBScript

    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect MFAuthTypeSpecificWindowsUser, MFilesAdmin, MFilesAdminPass, MFilesBase, MFProtocol , MFServerAddress , MFServerPort
    Set oVault = oServerApp.LogInToVault(VaultGUID)	

Children