none
vbscript Object not a collection RRS feed

  • Question

  • Dear,

    i am not able to dertermine whats wrong in line 29


    ' List the Subfolders of a Folder

    Function getus
    Dim strusr
    strComputer = "."
    Dim str(100)
    int i

     i = 0

    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colSubfolders = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='c:\Users'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")
      
    ForEach objFolderin colSubfolders
        str(i) =  LCase(objFolder.Name) 
         i = i + 1
    Next
    getus = str

    Dim replstring
    ForEach objFoldin str
    replstring = objFold
    replstring = Replace(replstring, "c:\users\", "")
    ForEach replcIn replstring
        If replc <> ""then
            getus = replc
        Endif
    Next
    Next

    EndFunction

    WScript.Echo getus


    Support@Mytechnet.me

    Monday, June 30, 2014 4:53 PM

Answers

  • As you can see, it is basically impossible to simply copy-and-paste and guess about how to write scripts.

    Scripting is a form of programming, which means you have to take a systematic approach to the problem. Once you have decided on a solution you can express the solution in code. Guesswork and copy-and-paste are not going to do it for you because you have to understand what the code is doing.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 30, 2014 6:44 PM
    Moderator

All replies

  • What's on line 29?

    Is this a homework question?

    Are you being a help vampire?

    Please read the following:


    -- Bill Stewart [Bill_Stewart]

    Monday, June 30, 2014 5:01 PM
    Moderator
  • Try looking things up in the documentation.  Try all examples until you understand each item.

    Here is a hint as to how this works.  It will show you that you are overcomplicating things by failing to research the issue thoroughly.

    GetUsers
    
    Function GetUsers()
     
        Set objWMIService = GetObject("winmgmts:")
        
        wql="Associators of {Win32_Directory.Name='c:\Users'} Where AssocClass = Win32_Subdirectory ResultRole = PartComponent"
        Set colSubfolders = objWMIService.ExecQuery(wql)
        
        For Each objFolder In colSubFolders
            WScript.Echo objFolder.FileName
        Next
    
    End Function


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, June 30, 2014 5:52 PM
    • Proposed as answer by Frederik Long Thursday, July 17, 2014 7:44 AM
    Monday, June 30, 2014 5:52 PM
  • If your aim is to confuse everyone (including yourself) then you're doing very well. Here you call an array "str":
    str(i) =  LCase(objFolder.Name) 

    and here you call a string "objFold".
    ForEach objFoldin str

    The interpreter does not care but humans certainly do!


    Monday, June 30, 2014 6:18 PM
  • As you can see, it is basically impossible to simply copy-and-paste and guess about how to write scripts.

    Scripting is a form of programming, which means you have to take a systematic approach to the problem. Once you have decided on a solution you can express the solution in code. Guesswork and copy-and-paste are not going to do it for you because you have to understand what the code is doing.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 30, 2014 6:44 PM
    Moderator