none
Statement taking an inordinate amount of time to execute RRS feed

  • Question

  • I have this routine that queries the WMI system to find the location of an executable file in Windows …

    	CALL	subLog( 1, "" )
    CALL subLog( 1, "#################################################################################################" ) CALL subLog( 1, "fnFindExecutable(): finding '" & strFilename & "' executable.") CALL subLog( 1, "#################################################################################################" ) CALL subLog( 1, "" ) strQuery = "WinMgmts:\\" & strLocalPC & "\Root\CIMV2" CALL subLog( 5, "About to open WinMgmts, query is '" & strQuery & "'." ) SET objWMI = GetObject( strQuery ) strQuery = "SELECT * FROM CIM_DataFile WHERE fileName = '" & strFilename & "' AND Extension = 'exe'" CALL subLog( 5, "About to query WinMgmts, query is '" & strQuery & "'." ) SET colFiles = objWMI.ExecQuery( strQuery ) CALL subLog( 5, "returned from query." ) intNumFiles = colFiles.Count CALL subLog( 5, CStr( intNumFiles ) & " returned in collection." )
    As you can see, I have logging statements both before and after the intNumFiles = colFiles.Count statement. when I run the script
    # 10/9/2019 10:24:23 AM: #################################################################################################
    # 10/9/2019 10:24:23 AM: fnFindExecutable(): finding 'WinSCP' executable.
    # 10/9/2019 10:24:23 AM: #################################################################################################
    # 10/9/2019 10:24:23 AM:
    # 10/9/2019 10:24:23 AM: About to open WinMgmts, query is 'WinMgmts:\\HPS20778\Root\CIMV2'.
    # 10/9/2019 10:24:23 AM: About to query WinMgmts, query is 'SELECT * FROM CIM_DataFile WHERE fileName = 'WinSCP' AND Extension = 'exe''.
    # 10/9/2019 10:24:23 AM: returned from query.
    # 10/9/2019 10:35:56 AM: 1 returned in collection.
    # 10/9/2019 10:35:56 AM: strPath is 'c:\program files (x86)\winscp\winscp.exe'.
    # 10/9/2019 10:35:56 AM: 'WinSCP' found at 'c:\program files (x86)\winscp\winscp.exe'.
    # 10/9/2019 10:35:56 AM: End of file collection processing.
    # 10/9/2019 10:35:56 AM: WinSCP found at 'c:\program files (x86)\winscp\winscp.exe'.
    # 10/9/2019 10:35:56 AM:
    # 10/9/2019 10:35:56 AM: #################################################################################################
    # 10/9/2019 10:35:56 AM: fnFindExecutable(): finding 'AcroDist' executable.
    # 10/9/2019 10:35:56 AM: #################################################################################################
    # 10/9/2019 10:35:56 AM:
    # 10/9/2019 10:35:56 AM: About to open WinMgmts, query is 'WinMgmts:\\HPS20778\Root\CIMV2'.
    # 10/9/2019 10:35:56 AM: About to query WinMgmts, query is 'SELECT * FROM CIM_DataFile WHERE fileName = 'AcroDist' AND Extension = 'exe''.
    # 10/9/2019 10:35:56 AM: returned from query.
    # 10/9/2019 10:36:24 AM: 1 returned in collection.
    # 10/9/2019 10:36:24 AM: strPath is 'c:\program files (x86)\adobe\acrobat 2017\acrobat\acrodist.exe'.
    # 10/9/2019 10:36:24 AM: 'AcroDist' found at 'c:\program files (x86)\adobe\acrobat 2017\acrobat\acrodist.exe'.
    # 10/9/2019 10:36:24 AM: End of file collection processing.
    # 10/9/2019 10:36:24 AM: Distiller found at 'c:\program files (x86)\adobe\acrobat 2017\acrobat\acrodist.exe'.
    As you can see from the logging, the first time that this procedure is called, that one statement takes 11 minutes to execute.    Is there a more optimal way to do this?
    

    

    Wednesday, October 9, 2019 9:24 PM

All replies

  • Please post your script. The log files ae kind of useless here. It looks like your WMI use is wrong.

    The file query will search all of the drives to return a result.  This can take a long time.


    \_(ツ)_/

    Wednesday, October 9, 2019 9:36 PM
  • To get a single file back quickly from all drives use the MS Search provider with PowerShell. It can instantly find any file in the indexers catalog.

    \_(ツ)_/

    Wednesday, October 9, 2019 9:38 PM