For loop 对于每个循环语法错误

For loop 对于每个循环语法错误,for-loop,vbscript,For Loop,Vbscript,此Windows Installer软件包有问题。作为安装程序一部分运行的程序未按预期完成。请与您的支持人员或软件包供应商联系 嘿,我写了这个脚本来删除计算机的共享,但是当我运行脚本时,它会重复相同的wscript.echo,以保存被删除的共享。为什么我的代码在运行时永远不会结束我该如何修复它 我的建议是: 'The function that is called to run the command Line that deletes a specific share from a pc Fu

此Windows Installer软件包有问题。作为安装程序一部分运行的程序未按预期完成。请与您的支持人员或软件包供应商联系

嘿,我写了这个脚本来删除计算机的共享,但是当我运行脚本时,它会重复相同的wscript.echo,以保存被删除的共享。为什么我的代码在运行时永远不会结束我该如何修复它

我的建议是:

'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

如果非要我猜的话,那是因为您正在通过让脚本回显
DeleteThisShare
函数来创建递归循环。该函数到达该行并在能够继续之前再次调用


尝试只为函数的结果赋值,并使用局部变量来存储任何其他调试/临时值。

如果我不得不猜测这是因为您的脚本通过回显
deleteThishare
函数来创建递归循环。该函数到达该行并在能够继续之前再次调用


尝试只为函数的结果赋值,并使用局部变量存储任何其他调试/临时值。

我认为问题是由于使用函数名作为变量引起的。您正在编译的VB没有问题,但我认为VBScript无法以相同的方式识别它。使用一个单独的变量名来代替
deletetetThisShare
,例如
strDeleteThisShare

我认为问题是将函数名用作变量引起的。您正在编译的VB没有问题,但我认为VBScript无法以相同的方式识别它。使用单独的变量名代替
deletetetThisShare
,例如
strDeleteThisShare