你可以嘗試這樣的:
myfolder = "C:\temp"
Set sh = CreateObject("shell.application")
For Each w In sh.Windows
If w.document.folder.self.Path = myfolder Then w.Quit
Next
這裏是一個完整的例子關閉您的臨時文件夾:如果你想拒絕訪問的文件夾做直路
Option Explicit
If AppPrevInstance() Then
MsgBox "There is an existing proceeding !" & VbCrLF &_
CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"
WScript.Quit
Else
Dim MyFolder,ws
Set ws = CreateObject("wscript.shell")
Myfolder = ws.ExpandEnvironmentStrings("%temp%")
Do
Call CloseThis(MyFolder)
wscript.sleep 1000
Loop
End If
'*********************************************************************************************
Sub CloseThis(Folder)
Dim sh,w
Set sh = CreateObject("shell.application")
For Each w In sh.Windows
If w.document.folder.self.Path = Folder Then w.Quit
Next
End Sub
'*********************************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'*********************************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'*********************************************************************************************
調整文件夾權限。 –
@AnsgarWiechers我想使用一個.vbs腳本,而不是觸摸任何文件夾權限。有沒有辦法做到這一點? 在此先感謝 – nicochulo
*「我想用這一個.vbs腳本,而不是做」 *不,你不會。相信我。 –