Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Querying and setting user rights with vbscript

  Asked By: Geoffrey    Date: Oct 09    Category: Sharepoint    Views: 30568

could you please show me same sample code, which represents how can I query and
set the user rights on a folder with vbscript?

We are migrating from one domain to an other, and we need to set
programmatically set the user rights.

(We tried SMSEXImex utility - this cannot works for us. Both the export and the
import was full of errors)



4 Answers Found

Answer #1    Answered By: Aayushman Kanvinde     Answered On: Oct 09

Here is a script to get you started. It is an update from www.sharepointcode.
com. But I fixed some errors  in the script. If you need help with
it please let me know.

Answer #2    Answered By: Edgardo Atkins     Answered On: Oct 09

If you could cut and paste the script into the email, I (and probably
others) would appreciate it. Our Exchange administrators typically strip off
most email attachments.

Answer #3    Answered By: Kamal Mayachari     Answered On: Oct 09

Sorry here is the script
' FolderPermssions.vbs
' Various folder  functions and subs
' replaces ShowFolderPermissions.vbs
' ShowFolderPermissions
' ShowFolderPermissionsAll
' CopyFolderPermissions
' Andy Ball 18/12/2001
' Updated 2/20/03 by Michael Linster. I had found some problems
with script as it was and have updated it to function correctly.

Option Explicit

Const adModeReadWrite = 3

Dim oArgs ' for arguements passed in
Dim WshShell
Dim arrPermissions

Dim SourceFolderPath
Dim DestFolderPath

Dim Counter
dim oCode

' get the args
Set WshShell = Wscript.CreateObject("Wscript.Shell")
set oArgs=Wscript.Arguments

' Call the relevant

' ie this is an error
If oArgs.Count < 1 Then
WScript.Echo "Usage : CSCRIPT ShowFolderPermission.vbs <sourcefolderpath>
WScript.Echo "Usage : CSCRIPT ShowFolderPermission.vbs
Elseif oArgs.Count > 1 then
DestFolderPath = oArgs.Item(1)
SourceFolderPath = oArgs.Item(0)
oCode = "1"
SourceFolderPath = oArgs.Item(0)
oCode = "2"
End If

' copy perms and show
if oCode = "1" then
CopyFolderPermissions SourceFolderPath, DestFolderPath
ShowFolderPermissionsAll SourceFolderPath
end if

' Sub ShowFolderPermission
' Shows permissions on the relevant folder
Sub ShowFolderPermissions (FolderPath, Permission)
Dim arPermissions ' Array to store current permissions
Dim oFolder ' folder object
Dim user  ' item used in FOR EACH in array
Dim ArrayItemCount

' Create object
set oFolder = CreateObject("CDO.KnowledgeFolder")

' Open the folder
oFolder.DataSource.Open FolderPath

' Return the relevant array depending on the type of user
Select Case UCASE(Permission)
Case "READER" arPermissions = oFolder.Readers
Case "COORDINATOR" arPermissions = oFolder.CoOrdinators
Case "AUTHOR" arPermissions = oFolder.Authors
' trap dodgy permission. Would be cool if could retrive valid permissions
as this is likely to change between versions
Case Else WScript.Echo Permission & " is not valid. Should be
READER, AUTHOR or Coordinator"
Exit Sub
End Select

' Get the number of items in the array
ArrayItemCount = UBound(arPermissions) + 1

' ie if no (say) readers print message
if ArrayItemCount = 0 Then
WScript.Echo "No " & Permission & " Permissions on " & FolderPath
' Otherwise roll through printing permissions
Wscript.Echo Permission & "S of " & FolderPath
For Each User in arPermissions
Wscript.Echo vbTAB & User
End If
set oFolder = Nothing
End Sub

show  all permissions
' Procedure ShowFolderPermissionsAll
Sub ShowFolderPermissionsAll(FolderPath)
ShowFolderPermissions FolderPath, "READER"
ShowFolderPermissions FolderPath, "AUTHOR"
ShowFolderPermissions FolderPath, "COORDINATOR"
End Sub

' CopyFolderPermissions - Copy Folder Permissions from one folder
to another.
Sub CopyFolderPermissions (SourceFolderPath, DestFolderPath)
Dim arPermissions ' Array to store current permissions
Dim oSourceFolder ' folder object
Dim oDestFolder

Dim User ' item used in FOR EACH in array
Dim ArrayItemCount

' Create objects - one for source , one for dest
set oSourceFolder = CreateObject("CDO.KnowledgeFolder")
set oDestFolder = CreateObject("CDO.KnowledgeFolder")

' Open the folder, note need to open dest in read write mode.
oSourceFolder.DataSource.Open SourceFolderPath
oDestFolder.DataSource.Open DestFolderPath , , adModeReadWrite

' copy over the 3 permissions
oDestFolder.Readers = oSourceFolder.Readers
oDestFolder.Authors = oSourceFolder.Authors
oDestFolder.CoOrdinators = oSourceFolder.Coordinators

' then save
End Sub

Answer #4    Answered By: Kelsie Terrell     Answered On: Oct 09

yes, I would like to ask the same that Megan wish - I didn't receive the code.

I tried to find it in the www.sharepointcode.com but maybe I am a little bit lamer. so I can't find the code  on the website.

Didn't find what you were looking for? Find more on Querying and setting user rights with vbscript Or get search suggestion and latest updates.