Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback

Last updated on 7 April 2025 · 3 min read

Admin
M-Files Admin

Overview

How to create a command to automate taking the vaults offline and online?

This can be useful to automate administrative actions such as server OS updates or hardware changes for your on-premises environment. In the M-Files Cloud you do not need to manage the infrastructure, M-Files takes care of that for you.

Notes

Note 1

It can be helpful to be familiar with the M-Files API in the first place: 

https://developer.m-files.com/APIs/COM-API/Reference/#gettingstarted.html

see the "Getting Started with the M-Files Server Interface" section in particular.

The relevant methods are:

Note 2

Do not force a shutdown of M-Files servers or the OS. This may corrupt the databases where a recovery is not possible:

Do not force a shutdown of an M-Files/SQL Server process or computer

Note 3

Implementing custom solutions via scripting is not something that is part of the standard M-Files support offering. Use caution when writing code and implement error handling and resilience. Make sure you understand the code and tasks you are performing to avoid adverse side effects. The examples provided below are merely starting points to illustrate the concept.

Solution

To get the vaults that are available on the server, you can use this method:

Public Function GetVaults() As VaultsOnServer

To take vaults offline use this one:

Public Sub TakeVaultOffline( _
   ByVal VaultGUID As String, _
   ByVal DisconnectUsers As Boolean _
) 

Here is a bigger example with creating the connection and looping over all vaults:

' NOTE THIS IS BARE BONES CORE EXAMPLE

' ADD ERROR HANDLING, LOGGING, FIX CONNECTION DETAILS AS NEEDED

Option Explicit

Dim oApp, connectionData, oVaults, i

Set oApp = CreateObject("MFilesApi.MFilesServerApplication")

Set connectionData = CreateObject("MFilesApi.ConnectionData")

connectionData.Endpoint = "7766"

connectionData.NetworkAddress = "127.0.0.1"

connectionData.ProtocolSequence = "grpc"

oApp.ConnectEx7(connectionData)

Set oVaults = oApp.GetVaults()

WScript.Echo("got vaults")

for i = 1 to oVaults.Count

    Dim currVaultGuid

   currVaultGuid = oVaults.Item(i).GUID

   WScript.Echo("taking offline vault: " & currVaultGuid)

   oApp.VaultManagementOperations.TakeVaultOffline currVaultGuid, True

Next     

WScript.Echo("Done!")

To bring the vault online use this method:

Public Sub BringVaultOnline( _
   ByVal VaultGUID As String _
) 

Here is a bigger example with creating the connection and looping over all vaults:

' NOTE THIS IS BARE BONES CORE EXAMPLE

' ADD ERROR HANDLING, LOGGING, FIX CONNECTION DETAILS AS NEEDED

Option Explicit

Dim oApp, connectionData, oVaults, i

Set oApp = CreateObject("MFilesApi.MFilesServerApplication")

Set connectionData = CreateObject("MFilesApi.ConnectionData")

connectionData.Endpoint = "7766"

connectionData.NetworkAddress = "127.0.0.1"

connectionData.ProtocolSequence = "grpc"

oApp.ConnectEx7(connectionData) 

Set oVaults = oApp.GetVaults()

WScript.Echo("got vaults")

for i = 1 to oVaults.Count

    Dim currVaultGuid

   currVaultGuid = oVaults.Item(i).GUID

   WScript.Echo("bringing online vault: " & currVaultGuid)

   oApp.VaultManagementOperations.BringVaultOnline currVaultGuid

Next     

WScript.Echo("Done!")

Still need help?