用vbscript锁定文件夹

用vbscript锁定文件夹,vbscript,Vbscript,我被困在下面的脚本中,请帮助我 ' Discover Current Drive Path curDrv = objFSO.GetParentFolderName(WScript.ScriptFullName) 'Drive Path ulpath = curdrv & "\Locker" propath = curdrv & "\Control_Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" passFile = c

我被困在下面的脚本中,请帮助我

 ' Discover Current Drive Path
  curDrv = objFSO.GetParentFolderName(WScript.ScriptFullName) 'Drive Path
  ulpath = curdrv & "\Locker"
  propath = curdrv & "\Control_Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
  passFile = curdrv & "\pass.txt"
  If objFSO.FolderExists (propath) Then call Unlock

  If Not objFSO.FolderExists (ulpath) Then
  objFSO.CreateFolder (ulpath) 
  MsgBox "Folder Created Successfully" , vbInformation, "Process Success"  & WScript.Quit
  end if
  If objFSO.FolderExists (ulpath) Then call Lock
  WScript.Quit

  Sub PassCreate
  PSCR = InputBox ("Type a password to lock folder.                          Do Not use blank password for your safety.")
  IF PSCR="" then MsgBox "Password cannot be blank" , vbCritical, "Faulty"  
  IF PSCR="" & objFSO.FileExists(passFile) then
  objFSO.DeleteFile(passFile)
  end if
  IF PSCR="" then call PassCreate 
  Set objFile = objFSO.CreateTextFile(passFile,True)
  objFile.Write PSCR & vbCrLf
  objFile.Close
  End Sub

  Sub Unlock
  PSW = InputBox ("Please Enter your 10 digit Password.               Example : 9867123456")
  Set objFile = objFSO.OpenTextFile(passFile)
  Do Until objFile.AtEndOfStream
  strLine= objFile.ReadLine
  Loop
  objFile.Close
 If not PSW=strLine Then MsgBox "Wrong Password" , vbCritical, "Illegal Operation" & WScript.Quit
 objFSO.MoveFolder propath , ulpath
 Set FO = objFSO.GetFolder(ulpath)
FO.Attributes = FO.Attributes AND 0 
MsgBox "Folder Unlocked Successfully" , vbInformation, "Success Operation" & WScript.Quit
End Sub 

 Sub Lock
 Message = "Are you Sure you want" & vbCr & vbCr
 Message = Message & "to Lock the folder ?" & vbCr & vbCr
 X = MsgBox(Message, vbOKCancel, "Confirmation")
 If not objFSO.FileExists (passFile) then call PassCreate

 Select Case X

 Case vbOK
 objFSO.MoveFolder ulpath , propath
 Set objFolder = objFSO.GetFolder(propath)
 Set FL = objFSO.GetFolder(propath)
 FL.Attributes = FL.Attributes XOR -1
 MsgBox "Folder Locked Sucessfully." , vbInformation, "Process Success"

Case vbCancel
MsgBox "Nothing Done." , vbExclamation, "Process Aborted"
End Select

End Sub 

在sub passcreate下,如果密码第一次为空,则不会写入pass.txt,因此不会创建密码。我想防止意外创建空密码。如果在两个输入框上都选择了cancel,我不知道如何取消脚本执行。

在检查是否密码为空,例如:

IF PSCR="" then
  MsgBox "Password cannot be blank" , vbCritical, "Faulty"  
  Exit Sub
End If

为什么不在这样的循环中请求密码呢

PSCR = ""
DO While PSCR = ""
    PSCR = InputBox ("Type a password to lock folder.                          Do Not use blank password for your safety.")
    IF PSCR="" then 
        MsgBox "Password cannot be blank" , vbCritical, "Faulty" 
    END IF 
Loop
这样,用户必须输入密码才能继续运行脚本

编辑: 这应该是你想要的一切

Sub TheScript
    password = GetPassword
    If password = "" Then Exit Sub
    MsgBox password
End Sub

Function GetPassword
    PSCR = ""
    DO While PSCR = ""
        PSCR = InputBox ("Type a password to lock folder. Do Not use blank password for your safety.")
        If IsEmpty(PSCR) Then 
            MsgBox "Cancel Pressed"
            Exit do            
        ElseIf PSCR = "" Then
            MsgBox "Password cannot be blank" , vbCritical, "Faulty"            
        End If
    Loop
    GetPassword = PSCR
End Function
与您的无关,但我想分享我的2锁XD
第一个很简单,另存为.bat(密码是5953,只需在脚本中查找并更改即可)



这是第二个文件。请记住,我还有另外两个与此文件相关的文件。 1。是这样的.BAT文件…


2。是这样的txt文件…


这是保存为vbs的主文件。


该条件仍然存在。密码为空。Tester101您的答案有效,但如果我想取消ie不锁定文件夹,我就不能。我在谷歌搜索时找到了一个更好的解决方案,将其粘贴到此处,以方便像我这样的新手。Dim vResponse vResponse=InputBox(“输入姓名:”,“数据输入”)如果是空的(vResponse),则MsgBox“未输入数据”,VB惊叹,“取消按”ElseIf Len(vResponse)=0,然后MsgBox“啊!没有名字的人”,vbInformation,“确定按”否则MsgBox“问候语”&“vResponse&”.”,vbInformation,“确定按”如果您不知道如何以脚本格式粘贴脚本,请结束如果您找到了解决方案,可以将其添加到原始帖子并将其标记为编辑,或者回答您自己的问题并将代码发布到那里。
cls

@ECHO OFF

title Folder Locker

if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK

if NOT EXIST Locker goto MDLOCKER

:LOCK

ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

goto End

:UNLOCK
cls

echo Enter password to Unlock folder

set/p "pass=>"

if NOT %pass%==5953 goto FAIL

attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker

goto End

:FAIL

ECHO.

echo Invalid password.

ECHO.

echo Want to give it another try ???(Y/N)

set/p "cho=>"

if %cho%==Y goto UNLOCK

if %cho%==y goto UNLOCK

if %cho%==n goto SHUTDOWN

if %cho%==N goto SHUTDOWN

:MDLOCKER

md Locker

echo Locker Folder was created successfully.

goto End


:SHUTDOWN


Shutdown.exe -s -t 10

cls

msg * Wrong Password Bro.


:End
@echo off  
Shutdown.exe -s -t 10  
cls  
msg * your message here!
.LOG
Option Explicit
Dim sapi,x,filler,T,objSHL,n,i,KContinue
set x=createobject("wscript.shell")
Set sapi=CreateObject("sapi.spvoice")
Set objSHL = CreateObject("WScript.Shell")

sapi.Speak "Please enter your access key"

KContinue = True
Do While KContinue
filler = inputbox("Enter your Access key.")
KContinue = False
if filler= "2648" then
call a
elseif filler= "" then
call b
else
call c
end if
Loop


sub a
x.Run ("""C:\Finnished Scripts\Intruder Alert.txt""")
wscript.sleep 2000
x.sendkeys "Access Granted"
wscript.sleep 2000
x.sendkeys "{enter}"
x.sendkeys "%"
wscript.sleep 500
x.sendkeys "{enter}"
x.sendkeys "s"
wscript.sleep 300
x.sendkeys "{enter}"
wscript.sleep 500
x.sendkeys "%"
x.sendkeys "{enter}"
x.sendkeys "x"
x.sendkeys "{enter}"
sapi.Speak "access granted"
end sub


sub b
x.Run ("""C:\Finnished Scripts\Intruder Alert.txt""")
wscript.sleep 2000
x.sendkeys "Access Denied, User gave no input"
wscript.sleep 2000
x.sendkeys "{enter}"
x.sendkeys "%"
x.sendkeys "{enter}"
x.sendkeys "s"
wscript.sleep 300
x.sendkeys "{enter}"
wscript.sleep 500
x.sendkeys "%"
x.sendkeys "{enter}"
x.sendkeys "x"
x.sendkeys "{enter}"
sapi.Speak "Access Denied, User gave no input"
sapi.Speak "You have ten seconds left on this PC" 
call tb
end sub


sub c
x.Run ("""C:\Finnished Scripts\Intruder Alert.txt""")
wscript.sleep 2000
x.sendkeys "Access Denied, User input"
x.sendkeys "{enter}"
x.sendkeys filler
wscript.sleep 2000
x.sendkeys "{enter}"
x.sendkeys "%"
x.sendkeys "{enter}"
x.sendkeys "s"
wscript.sleep 300
x.sendkeys "{enter}"
wscript.sleep 500
x.sendkeys "%"
x.sendkeys "{enter}"
x.sendkeys "x"
x.sendkeys "{enter}"
sapi.Speak "Access Denied, User input" 
sapi.Speak filler
sapi.Speak "You have ten seconds left on this PC" 
call tb
end sub



sub tb

n=10
For i = 1 To n
sapi.Speak(n)&("select yes to try the password again")
T = objSHL.Popup("Want to try again? You have "&n&" seconds",1,"title",vbYesNo)

If T  = vbYes Then
sapi.Speak"YOU MAY TRY AGAIN"
KContinue = True
 Exit for

ElseIf T = vbNo Then
sapi.Speak("you have selected no, no pc access for you")
x.Run ("""C:\Finnished Scripts\Shutdown computer.bat""")
 Exit for
End If


n=n-1
If n = 0 then
sapi.Speak("you have selected nothing, no pc access for you")
x.Run ("""C:\Finnished Scripts\Shutdown computer.bat""")
 End If
Next
end sub