cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get mega root besides from a mega object?

rbpatesmega
Super Contributor

I wrote a script with the following code below.

 

Sub LoginLogger()

  Dim  pathFile, strInfo, userName, fso, fullpath, currentUser, mgRoot, myFile

  pathFile = "D:\Login Activity\loginLogs.txt"

 'Get Current User
  currentUser = megaRoot.GetObjectFromID(mgRoot.CurrentEnvironment.GetCurrentUserId)
  Set fso = CreateObject("Scripting.FileSystemObject")
  fullpath = fso.GetAbsolutePathName(pathFile)
  Set myFile = fso.OpenTextFile(fullpath, 8, True)
  myFile.WriteLine("Username:" &  currentUser.getProp("Name") & "|Repository:" & mgRoot.getProp("Name")& "|Date:" & Date() & "|Time:" & Time)
  Set myFile = nothing
  Set fso = nothing

End Sub

 

how can i get mega root( variable in red font)  in this scenario?

3 Replies

Hello,

 

Use megaenv.getroot :

 

objMegaRoot = megaenv.getRoot

 

Regards,

 

Lionel

I am getting this error  after calling GetRoot() inside a  macro.

 

Thanks.

lmazurie
Honored Contributor

Dear,

 

You can try a GetRoot() for a macro  or a .GetRoot directly in the current object for a macro as a Metacommand.

 

Regards,

Lionel Mazurié