Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
josekhouri
Contributor
Contributor

Grant in Folder by VBScript

Hi everyone,

I'm looking for a way to give grant to some users in a specific folder by VBSCript, using module and the script to pass the parameters, but it doesn't work.

I was searching on the community, but I didn't found nothing specific about grant access in folder by VBScript or a similar question. Can anyone help me with this answer?

I'm upload an example help to clarify the idea.

Thanks in advance,

José Khouri

Labels (3)
1 Solution

Accepted Solutions
cwolf
Creator III
Creator III

If you call a macro from the script, you can not use references to any Qlikview object like Application, ActiveDocument and so on.

You can do it in the following way:

Script:

IF(NoOfRows('UsersAccess')>0) THEN

LET nUsers = NoOfRows('UsersAccess');
LET docPath=DocumentPath();
TRACE '$(docPath)';

FOR i = 0 to nUsers - 1
     LET UsersAccess = Peek('User', i, 'UsersAccess');
     TRACE '$(UsersAccess)';
     LET ExecuteGrant = GrantScript('$(docPath)','$(UsersAccess)');
     TRACE '$(ExecuteGrant)';
NEXT

END IF

Macro:

Function GrantScript(TmpPath,strDomainUser)
    LastBackSlash = InStrRev(TmpPath, "\")
    strPath = Left(TmpPath,(LastBackSlash - 1))

    Set WshShell = CreateObject("Wscript.Shell")
    WshShell.Run "Icacls " & strPath & " /grant " & strDomainUser & ":(OI)(CI)RX"

    GrantScript=strPath & " - " & strDomainUser
End Function

- Christian

View solution in original post

6 Replies
marcus_sommer

Maybe this is helpful: set-permission-with-vbscript.

- Marcus

josekhouri
Contributor
Contributor
Author

Hello Marcus,

Thanks for the tip, but my module is functional. It works separate, if I test it on edit module, but it doesn't work when I call it in QV script.

I noticed the function apparently don't work in the loop FOR in script. Is it anything I wrote wrong in code?

- José Khouri

marcus_sommer

What do you mean with:

...  It works separate, if I test it on edit module, but it doesn't work when I call it in QV script. ...

Where and how is this call executed. For example triggered by the QMC won't work and also the user which runs this macro must have the rights to change such access-rights for this folder.

- Marcus

josekhouri
Contributor
Contributor
Author

I mean, in edit module (CTRL+M) there's a button called "Test" that you can execute your function, and it runs correct for me. The grant was granted succefull in my example qvw.

In script (CTRL+E) I called that function inside the FOR statement in the line 17, but the function doens't work and the grant wasn't granted.

- José Khouri

cwolf
Creator III
Creator III

If you call a macro from the script, you can not use references to any Qlikview object like Application, ActiveDocument and so on.

You can do it in the following way:

Script:

IF(NoOfRows('UsersAccess')>0) THEN

LET nUsers = NoOfRows('UsersAccess');
LET docPath=DocumentPath();
TRACE '$(docPath)';

FOR i = 0 to nUsers - 1
     LET UsersAccess = Peek('User', i, 'UsersAccess');
     TRACE '$(UsersAccess)';
     LET ExecuteGrant = GrantScript('$(docPath)','$(UsersAccess)');
     TRACE '$(ExecuteGrant)';
NEXT

END IF

Macro:

Function GrantScript(TmpPath,strDomainUser)
    LastBackSlash = InStrRev(TmpPath, "\")
    strPath = Left(TmpPath,(LastBackSlash - 1))

    Set WshShell = CreateObject("Wscript.Shell")
    WshShell.Run "Icacls " & strPath & " /grant " & strDomainUser & ":(OI)(CI)RX"

    GrantScript=strPath & " - " & strDomainUser
End Function

- Christian

josekhouri
Contributor
Contributor
Author

Great! It worked!

I just needed to put one more condition in the docPath statement to get the path without the qvw app name.

Like this... LET docPath = Left(DocumentPath(), Index(DocumentPath(),'\',-1));

Thanks Christian!

- José Khouri