50481

Open a shared file in read/write mode for a particular username and keep the other users permission

<h3>Question</h3>
<b>Closed</b>. This question needs details or clarity. It is not currently accepting answers. <hr class="my12 outline-none baw0 bb bc-powder-2" /> <svg aria-hidden="true" class="svg-icon iconLightbulb" width="18" height="18" viewbox="0 0 18 18"><path d="M15 6.38A6.48 6.48 0 007.78.04h-.02A6.49 6.49 0 002.05 5.6a6.31 6.31 0 002.39 5.75c.49.39.76.93.76 1.5v.24c0 1.07.89 1.9 1.92 1.9h2.75c1.04 0 1.92-.83 1.92-1.9v-.2c0-.6.26-1.15.7-1.48A6.32 6.32 0 0015 6.37zM4.03 5.85A4.49 4.49 0 018 2.02a4.48 4.48 0 015 4.36 4.3 4.3 0 01-1.72 3.44c-.98.74-1.5 1.9-1.5 3.08v.1H7.2v-.14c0-1.23-.6-2.34-1.53-3.07a4.32 4.32 0 01-1.64-3.94zM10 18a1 1 0 000-2H7a1 1 0 100 2h3z"></path></svg> <p class="mb0"> <b>Want to improve this question?</b> Add details and clarify the problem by editing this post.

<p class="mb0 mt6">Closed 9 days ago.

Improve this question </aside>

I am working on a VBA that access a shared excel file to check if the file is used by someone else or not. By that time VBA should not allow other users to access the file in edit mode they should open it in read-only mode if they already opened the file as well. Basically, while I am accessing the same file from the shared path, if it is locked for editing by someone else then this VBA should forcefully change to read-write mode to give edit access to me. And the VBA should allow the other users to open the same file in read-only mode. Once I completed my editing and closed VBA should release the restriction to the other users. Any help on this will appreciated.

Sub wkbk_open() wkbk_name = "Project List LIVE.xlsm" wkbk_lock_file_path = "X:\~$" & wkbk_name Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(wkbk_lock_file_path) Then Debug.Print "The file is locked by " & GetFileOwner(wkbk_lock_file_path) Debug.Print "The file is locked by " & GetFileOwner2(wkbk_lock_file_path) Else Debug.Print "The file is available" End If End Sub Function GetFileOwner(strFileName) 'http://www.vbsedit.com/scripts/security/ownership/scr_1386.asp Set objWMIService = GetObject("winmgmts:") Set objFileSecuritySettings = _ objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'") intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD) If intRetVal = 0 Then GetFileOwner = objSD.Owner.Name Else GetFileOwner = "Unknown" End If End Function Function GetFileOwner2(strFileName) As String 'On Error Resume Next Dim secUtil As Object Dim secDesc As Object Set secUtil = CreateObject("ADsSecurityUtility") Set secDesc = secUtil.GetSecurityDescriptor(strFileName, 1, 1) GetFileOwner2 = secDesc.Owner End Function

来源:https://stackoverflow.com/questions/62228899/open-a-shared-file-in-read-write-mode-for-a-particular-username-and-keep-the-oth

Recommend

  • Non iterative equivalent for reversing a linked list
  • Selected range of Excel cells passed to an argument “as Variant” of a VBA function, then passed to a
  • Possible to hide app icon in iOS?
  • controlling length of the line of best fit in R
  • Read a file with dynamic file name in JavaScript
  • Inheritance and lazy loading in NHibernate
  • GitLab runner on Windows and dealing with & %ERRORLEVEL%
  • How to link address model to views
  • Planned Contrasts on glmmTMB
  • Map Annotation Disclosure Indicator - Xamarin.Form
  • Jenkins sending notifications to the wrong commit id
  • Yii Bootstrap not loading JS files
  • Unable to connect to AWS RDS through PDO
  • Is possible having two COM STA instances of the same component?
  • Showing image on a acro text field position
  • Exclude Classes from Being Included in Shaded Jar
  • Checking for valid enum types from protobufs
  • how to add dashed border on highcharts “area” graph for every point
  • Javascript inside HTML import not affecting imported HTML
  • C# code can't “see” the methods in my C++ dll
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Compiling multiple source files in Rcpp
  • Possible to set default CloudKit container not based on application name?
  • Create an average of multiple excel chart without the data source
  • concise way of flattening multiindex columns
  • gnuplot - How to make zmin equal to zmax keeeping autoscale on z axis
  • How to include associated objects using gon in Rails/jQuery
  • Error handeling in antlr 3.0
  • How can I ssh into a server that requires 2 password authentication using python's paramiko mod
  • Change cell value based on cell color in google spreadsheet
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to handle div that is created dynamically in a table
  • Background transfer download task failed when app was closed
  • ssh remote server login script
  • XEP-0166: Jingle protocol implementation for voice/video chat in iOS
  • Angular FormGroup won't update it's value immediately after patchValue or setValue