The question in class was “How do I list all the files in a remote computer?” First off, make sure that you are a member of the Administrators group on the target machine. In the first line (strComputer=”.”), replace the period with the name or IP address of the target machine. In the third command, replace ‘C:\Windows’ with the target folder.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\Windows'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In colFileList
Wscript.Echo objFile.Name
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\Windows'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In colFileList
Wscript.Echo objFile.Name
Next
Comments