Check if have Permission to access a server/share

  • Hello,

    Following is my current ActiveX script in DTS:

    '**********************************************************************

    '  Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

            Dim fso

            Set fso = CreateObject("Scripting.FileSystemObject")

            IF NOT(fso.FileExists("\\STGMESQLCM1M\MESQL\MESQLCMAUpdateProductionLog.txt")) THEN

      

                    Main = DTSTaskExecResult_Failure

            ELSE

     

     'fso.movefile("\\STGMESQLCM1M\MESQL\MESQLCMAUpdateProductionLog.txt"), ("\\STGMESQLCM1M\MESQL\Updated\MESQLCMAUpdateProductionLog.txt")

       Main =  DTSTaskExecResult_Success

            END IF

            set fso = nothing

    End Function

    '****************************************

    How can I modify the script to first see if I have permission to view the server/share I am trying to copy the file from? The way it is right now it just reports failure if the file was not found or even if it couldn't even access the network share - same error. This runs every five minutes so there will be situations that the file might not exist in which case I still continue my job and move on to next step, but I need to know if I couldn't even access the drive/share in which case I need a report to tell me that permission denied rather than job reported failure, which could also mean the file was processed already so not there any more and move on to next step.

    If there is a different way than to do this in ActiveX sript, please suggest.

    Thanks much.

    JN

  • You may want to use WMI scripts. See the link for an example for getting NTFS permissions for a folder

    http://www.microsoft.com/technet/scriptcenter/scripts/security/dacls/sedcvb02.mspx

    WMI can get to the remote computer too.

    Download Scriptomatic tool from Microsoft (search by a keyword Scriptomatic) . Run it. It loads a list of WMI classes. You select one. Scriptomatic creates a VB script for you that you can run right away or save for using somewhere else. I selected Win32_Share class for this example. The tool created:

    On Error Resume Next

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_Share",,48)

    For Each objItem in colItems

        Wscript.Echo "AccessMask: " & objItem.AccessMask

        Wscript.Echo "AllowMaximum: " & objItem.AllowMaximum

        Wscript.Echo "Caption: " & objItem.Caption

        Wscript.Echo "Description: " & objItem.Description

        Wscript.Echo "InstallDate: " & objItem.InstallDate

        Wscript.Echo "MaximumAllowed: " & objItem.MaximumAllowed

        Wscript.Echo "Name: " & objItem.Name

        Wscript.Echo "Path: " & objItem.Path

        Wscript.Echo "Status: " & objItem.Status

        Wscript.Echo "Type: " & objItem.Type

    Next

    You can modify the script to replace a dot for a computer name in strComputer and then return only a security parameter.

    Yelena

    Regards,Yelena Varsha

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply