Advertisement
Guest User

Test if file exists and popup

a guest
Jan 30th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.66 KB | None | 0 0
  1. 'Word creates a small file whose name starts with a tilde mark to indicate when the file is open.
  2. 'Full path to the file to check, double up back slashes
  3. fileName = "Z:\\Chris\\~$Test.docx"
  4.  
  5. 'Name of the computer to check
  6. strComputer = "."
  7.  
  8. Set WshShell = CreateObject("WScript.Shell")
  9. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  10.  
  11. Set colFiles = objWMIService.ExecQuery _
  12.     ("Select * From CIM_Datafile Where Name = '"&fileName&"'")
  13.  
  14. If colFiles.Count > 0 Then
  15.     strMessage = "The file is open."
  16. Else
  17.     strMessage = "The file is NOT open."
  18. End If
  19.  
  20. intButton = WshShell.Popup (strMessage,30,"Safe to copy and edit?" , 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement