Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check an Excel workbook availability
#2
Not Solved
Found a partial answer to my quesiton, I can search for the ~$ file which is created in the same folder by Windows when it is open by an other user
http://stackoverflow.com/questions/15555...7#16820357

Code:
testWorkbookLockFile = "path\~$file.xlsx"
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(testWorkbookLockFile) Then
(testWorkbookLockFile)
    WshShell.Echo "The file is locked by " & GetFileOwner(testWorkbookLockFile)
Else
    WScript.Echo "The file is available"
End If

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

Unfortunatly the
Code:
WshShell.Echo "The file is locked by " & GetFileOwner(testWorkbookLockFile)
part won't work since QTP can't execute any WScript.

Would anyone have an alternative for WshShell.Echo in order to notify the user using the file ?

Thanks a lot
Reply


Messages In This Thread
Check an Excel workbook availability - by utestqa - 05-28-2013, 07:57 PM
RE: Check an Excel workbook availability - by utestqa - 05-29-2013, 10:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to check whether data exists in excel.. venkatesh9032 1 3,555 03-06-2014, 04:37 PM
Last Post: supputuri

Forum Jump:


Users browsing this thread: 1 Guest(s)