Keith's profileKeith Hill's BlogPhotosBlogListsMore Tools Help
    August 25

    Windows PowerShell Has Moved Up to #15 on the TIOBE Programming Community Index

    The popularity of PowerShell is shooting through the roof right now.  Check out this TIOBE index from August 2008.  Notice the delta in position rating on PowerShell. What is that, like 10 up arrows. Impressive.

    August 14

    Error "Cannot delete file: Cannot read from the source file or disk"

    I got asked this question by someone I can't seem to reply to. Anyway the scenario involves Unix, Macs and PCs writing to the same Samba server.  The file attributes indicate readonly, hidden and system.  The use of the -force parameter will get PowerShell to display hidden/system files.  However the OP reports that Windows Explorer gets the same error.  This smells like invalided characters in the path.  This Microsoft KB article gives some guidance on this sort of problem in the "Invalid File Names" section.  If anyone else has run into this issue specifically, feel free to post a comment on how you eventually removed the offending files.

    August 02

    Finding Which Executables Use A DLL Entry Point

    Raymod Chen wrote a blog post called "Don't be helpless: ..." where he shows a batch command to start the process of finding which executables use a particular DLL entry point.

    for /f %i in (dlls.txt) do ^
    @echo %i & link /dump /imports %i | findstr PostThreadMessage

    The hard work is done by link (dumpbin really) so the script provides the glue code and formatting support.  I just had to give this a go in PowerShell where I knew the formatting would be superior plus I wanted to support searching on multiple entry points.  Here is the script I came up with:

    param([string[]]$filter=$(throw "-filter parameter is required"))
    
    get-process | select ProcessName -expand Modules -ea 0 |
        foreach {
            $dll = $_
            link /dump /imports $_.filename | 
                select-string $filter | 
                select @{n='Process';e={$dll.ProcessName}}, 
                       @{n='Dll';    e={$dll.ModuleName}}, 
                       @{n='Entry';  e={$_.Line.Substring(6)}} 
        } | 
        format-table Dll, Entry -groupby Process 
    
    The script output looks like this:
    PS> .\FindDllEntryPoint.ps1 'PostThreadMessage','QueueUserWorkItem'
    
    
       Process: apcsystray
    
    Dll                       Entry
    ---                       -----
    SHELL32.dll               77E19FF7    35F QueueUserWorkItem
    SHELL32.dll               77D718C9    222 PostThreadMessageW
    SHLWAPI.dll               77E09FF7    35F QueueUserWorkItem
    SHLWAPI.dll               77D5B4B9    221 PostThreadMessageA
    ole32.dll                 77D618C9    222 PostThreadMessageW
    MSCTF.dll                 77D618C9    222 PostThreadMessageW
    DpOFeedb.dll                          205 PostThreadMessageW
    
    
       Process: DPAgnt
    
    Dll                       Entry
    ---                       -----
    DPAgnt.exe                            205 PostThreadMessageW
    SHELL32.dll               77E19FF7    35F QueueUserWorkItem
    

    Now that is some nice formatting made possible by the Format-Table -GroupBy parameter.