none
How can I wait for the win32 code exit ? RRS feed

  • 問題

  • I've read the article here: http://blogs.msdn.com/powershell ... -in-powershell.aspx
    But I still can not wait for the win32 code exit, that means the script will exit with error. Beacause when I remove the net drive the zip is still runing.
    So How can I get the exit ?
    Here the code:
       1. # http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx
    2. function Add-Zip
    3. {
    4. param([string]$zipfilename)
    5.

    6. if(-not (test-path($zipfilename)))
    7. {
    8. set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
    9. (dir $zipfilename).IsReadOnly = $false
    10. }
    11.
    12. $shellApplication = new-object -com shell.application
    13. $zipPackage = $shellApplication.NameSpace($zipfilename)
    14.
    15. foreach($file in $input)
    16. {
    17. $zipPackage.CopyHere($file.FullName)
    18. Start-sleep -milliseconds 500
    19. }
    20. }
    21.

    22. get-childitem $driveLetter\$dirName\ |add-zip $driveLetter\$dirName.zip
     

    田海洋
    2009年7月7日 上午 07:35

解答

所有回覆