Question:
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 hangs at the point where a dialog would otherwise appear.
Here’s the unzip portion of my script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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?
Answer:
If it’s still actual, I managed to fix this with having CopyHere params equal 1564.
So in my case extract zip function looks like:
1 2 3 4 5 6 7 8 9 10 11 12 |
function Expand-ZIPFile{ param( $file, $destination ) $shell = new-object -com shell.application $zip = $shell.NameSpace($file) foreach($item in $zip.items()) { $shell.Namespace($destination).copyhere($item,1564) "$($item.path) extracted" } |
1564 description can be found here – http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx:
(4) Do not display a progress dialog box.
(8) Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
(16) Respond with “Yes to All” for any dialog box that is displayed.
(512) Do not confirm the creation of a new directory if the operation requires one to be created.
(1024) Do not display a user interface if an error occurs.