-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindLockingProcess.vbs
46 lines (36 loc) · 1.11 KB
/
FindLockingProcess.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'This doesn't return any results
Set objArgs = WScript.Arguments
If Not objArgs.Named.Exists("elevate") Then
If objArgs.Count = 1 Then
a = objArgs(0)
Else
WScript.Quit
End If
CreateObject("Shell.Application").ShellExecute WScript.FullName, """" & WScript.ScriptFullName & """ /elevate """ & a & """", "", "runas", 1
WScript.Quit
End If
Set wshShell = CreateObject("WScript.Shell")
s = objArgs.Count
For i = 0 to objArgs.Count - 1
s = s & vbCrLf & objArgs(i)
Next
WScript.Echo s
If objArgs.Count = 1 Then
fileOrFolderPath = InputBox("Enter file or folder path:")
'WScript.Echo "No file provided."
Else
fileOrFolderPath = objArgs(1)
End If
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(fileOrFolderPath)) Then
Set objExecObject = wshShell.Exec("cmd /c openfiles /query /fo table | find /I """ & fileOrFolderPath & """")
strCmdOutput = ""
Do While Not objExecObject.StdOut.AtEndOfStream
strCmdOutput = strCmdOutput & objExecObject.StdOut.ReadLine()
Loop
Wscript.Echo strCmdOutput
Else
WScript.Echo "File or directory does not exist."
End If
Set fso = Nothing
Set wshShell = Nothing