我正在編寫一個VBScript,它在Active Directory中搜索計算機對象。如果該對象不存在或存在且位於正確的OU中,則它應該運行一個單獨的腳本來創建/將計算機連接到AD。如果語句條件不符合,代碼仍在執行
ObjExist_CorrectOU_7 = Null
ObjExist_CorrectOU_10 = Null
If compare = True Then
Win7_OU = "OU=DisallowRDP,OU=64Bit,OU=Win8"
Win10_OU = "OU=DisallowRDP,OU=64Bit,OU=Win10"
For x = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), x, 1)) = Asc(Mid(Win7_OU, (x - 15), 1)) Then
ObjExist_CorrectOU_7 = True
Else
ObjExist_CorrectOU_7 = False
End If
Next
For y = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), y, 1)) = Asc(Mid(Win10_OU, (y - 15), 1)) Then
ObjExist_CorrectOU_10 = True
Else
ObjExist_CorrectOU_10 = False
End If
Next
End If
If ObjExist_CorrectOU_7 = True Then
WScript.Echo "TRUE"
End If
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
filename = "C:\programdata\dell\kace\k2000_deployment_info.conf"
Win7_Deployment = "deployment_name=Windows 7 x64 with SP1, join AD"
Win10_Deployment = "deployment_name=Development Windows 10 (x64), join AD"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next
Loop
f.Close
Set g = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((g.ReadLine = Win10_Deployment) Or ((g.ReadLine = Win10_Deployment) And (ObjExist_CorrectOU_10 = True))) Then
'objShell.Run "JoinAD_Win10.vbs"
WScript.Echo "IT WORKED AGAIN!"
Exit Do
End If
On Error Resume Next
Loop
g.Close
Set objShell = Nothing
我遇到的問題是,這兩個If..Then
語句執行每一次,儘管我知道絕對沒有得到滿足的條件。
這與我使用Or
和And
有什麼關係?
歡迎使用StackOverflow;感謝您發佈您的第一個問題。請確定你正在談論的具體陳述。這對新用戶閱讀以下內容很有幫助:[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask),[完美問題](http://codeblog.jonskeet .uk/2010/08/29/writing-the-perfect-question /)和[Minimal,Complete,and Verifiable example](http://stackoverflow.com/help/mcve)。請考慮編輯你的問題。 – MikeC