2013-11-14 47 views
1

沒有與此Windows安裝程序包的問題。作爲設置的一部分運行的程序未按預期完成。請與支持人員或程序包供應商對於每一個循環語法錯誤

嘿,我寫這個劇本中刪除計算機的股份,但是當我運行我的腳本,重複進行同樣的wscript.echo statating份額被刪除。爲什麼我的代碼在運行時永遠不會結束如何解決這個問題。

我fumction:

'The function that is called to run the command Line that deletes a specific share from a pc 
Function DeleteThisShare(Share) 
    Dim objShell 
    'Logging The deleted Approved Shares 
    objDeletedFile.WriteLine (Now & " - Removed share " & Trim(Share)) 
    DeleteThisShare = "net share " & chr(34) & Share & chr(34) &" /DELETE" 
    Wscript.echo DeleteThisShare 
    Set objShell = CreateObject("Wscript.Shell") 
    objShell.Run DeleteThisShare 
End Function 

我的循環:

'Compares The UnApproved Shares to the Current Shares 
For Each objItem In colItems 
    Dim StrNonUnapprovedShares, Item 
    StrCurrentShares = objItem.name 

    if instr(AdminShares,lcase(objitem.name)) > 0 or mid(objitem.name,2,1) = "$" or left(lcase(objitem.name),10) = "pkgsvrhost" then 
     'Skipping known admin share 
    Else 
      For each Item in arrUnApprovedLines 
      If Lcase(Item) = Lcase(strCurrentShares) Then 
       StrNonUnapprovedShares = (StrNonUnapprovedShares & strCurrentShares & vbCrLf) 
      End If 
     Next 
    End If 
Next 


Dim notUnapprovedShares, notUnapprovedLines 
notUnapprovedLines = StrNonUnapprovedShares 
notUnapprovedLines = Split(notUnapprovedLines, vbCrLf) 

Dim y, Line2 

For y = 0 to uBound(notUnapprovedLines) 
    Line2 = Trim(notUnapprovedLines(y)) 
    If len(Line2) > 0 Then 
     DeleteThisShare(Line2) 
    End If 
Next 

回答

0

如果我猜那是因爲你具有腳本創建一個遞歸循環呼應DeleteThisShare功能。該函數到達該行並在能夠繼續之前再次被調用。

儘量只賦值函數的結果,並使用局部變量存儲任何其他調試/臨時值。

1

我認爲這個問題是通過使用功能名稱作爲變量引起的。對於編譯的VB來說沒關係,但我認爲VBScript不會以相同的方式識別它。使用單獨的變量名稱代替DeleteThisShare,例如strDeleteThisShare