views:

267

answers:

2

I'm running a Windows Service (Hudson) which in turn spawns a PowerShell process to run my custom PowerShell commands. Part of my script is to unzip a file using CopyHere. When I run this script locally, I see a progress dialog pop up as the files are extracted and copied. However, when this runs under the service, it hands at the point where a dialog would otherwise appear.

Here's the unzip portion of my script.

# Extract the contents of a zip file to a folder
function Extract-Zip {
    param([string]$zipFilePath, [string]$destination)
    if(test-path($zipFilePath))     {   
        $shellApplication = new-object -com shell.application

        $zipFile = get-item $zipFilePath
        $zipFolder = $shellApplication.NameSpace($zipFile.fullname)

        $destinationFile = get-item $destination
        $destinationFolder = $shellApplication.NameSpace($destinationFile.fullname)

        $destinationFolder.CopyHere($zipFolder.Items())
    }
}

I suspect that because its running under a service process which is headless (no interaction with the desktop), its somehow stuck trying to display a dialog.

Is there a way around this?

+1  A: 

Looking at the documentation for PowerShell, it looks like the -NonInteractive option may help here

Michael Donohue
That would prevent PowerShell from displaying a prompt but I don't think it would prevent the Windows shell from displaying UI.
Keith Hill
+2  A: 

If this is running on Vista or Windows 7, popping up UI from a service isn't going to be seen by the end user as you suspected. See this paper on Session 0 Isolation. However, does the progress dialog require user input? If not, I wouldn't think that would cause the service to hang. I would look for an option to disable the progress display. If you can't find that, then try switching to another ZIP extractor. PSCX 1.2 comes with an Expand-Archive cmdlet. I'm sure there are also others available.

Keith Hill
The progress dialog shoudl not be requiring user input. When I run it from a command prompt, it doesn't -- it just shows the progress dialog without any required input, and then when its done the dialog disappears.The actual progress dialog is spawned by the CopyHere method. Supposedly, there are options you should be able to pass to block any potential interaction, but there's dozens of posts out there complaining that PowerShell ignores those particular options.I had hoped to avoid 3rd-party stuff as much as possible, but I may have to cave.
Trinition
PSCX providers wrapper cmdlets on top of 7-Zip but if you want, you can always use 7-Zip directly - http://www.7-zip.org/
Keith Hill