2010-02-14 76 views
0

我被困在下面的脚本锁定,请帮助文件夹使用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 = 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 

在分passcreate如果密码为空,第一次没有被写入pass.txt所以没有密码created.I希望防止意外空白的密码创建。如果在两个输入框上都选择了取消,我不知道如何取消脚本执行。

+0

如果您找到解决方案,您可以将其添加到原始帖子中并将其标记为编辑,或者回答自己的问题并在其中发布代码。 – Tester101 2010-02-16 13:02:30

回答

0

为什么不能在这样的循环索要密码。

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 
+0

Tester101你的答案工作除了如果我想取消即不锁定文件夹,我不能。我发现一个更好的解决方案,同时谷歌搜索,粘贴在这里为了方便像我这样的其他新手。 Dim vResponse vResponse = InputBox(“Enter Name:”,“Data Entry”)If IsEmpty(vResponse)Then MsgBox“No data entered”,vbExclamation,“Cancel Pressed”ElseIf Len(vResponse)= 0 Then MsgBox“Ah!The man没有名字。“,vbInformation,”确定按下“Else MsgBox”Greetings“”&vResponse&“'。”,vbInformation,“OK pressed”结束如果 对不起,不知道如何粘贴脚本的脚本格式 – 2010-02-16 09:20:48

0

只是你在哪里检查,如果密码为空例如,以下条件使用exit sub

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

条件仍然存在。密码为空。 – 2010-02-15 09:27:34

相关问题