我正在尝试使用VBScript创建一个简单的程序,每次打开时关闭一个特定的文件夹,从而拒绝访问该文件夹。我已经成功地将此代码用于许多文件夹,但出于某种原因,它无法与<div id="toggle">Toggle child 2</div>
<div id="parent" class="parent">
<div class="child" name="child1">SOMETHING_INSIDE</div>
<div class="child" name="child2"></div>
</div>
一起使用。
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
有没有办法可以拒绝使用.vbs文件访问该特定文件夹?
答案 0 :(得分:2)
您可以尝试这样:
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
'*********************************************************************************************