Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2013
    Thanked 0 Times in 0 Posts

    Vbs command structure to add several files to a single zip

    What I am trying to do is to select several files that are dragged to the icon for my current vbs script and copy them all to a folder which can then be zipped as a single object to be attached to an email.
    That is the long explanation but my current script can only handle file-types that are not restricted by Outlook. It works well for several zip or txt files but cannot handle .exe or other types that Outlook will not accept as attachments.

    To make it a truly handy desktop icon, it needs to work for anything I drop onto it.
    I have been told that I need to put everything into a single location before being zipped but nothing I have tried can do that without crashing the already working part of the script.

    At this point, I am completely lost would appreciate assistance if anyone knows a way to manage this. I feel certain that this is not an impossible task.

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Thanked 1,017 Times in 946 Posts
    If you post the script we can make some suggestions.

    cheers, Paul

  3. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Manning, South Carolina
    Thanked 1,473 Times in 1,340 Posts

    I saw you post and thought "this is a job for PowerShell!" and where did I leave my cape.

    So here's some powershell code I found on the web and did some modifications to to make it do closer to what I think you want.
    You need to call this from a shortcut or if you want it available all the time from a Scheduled Task set to run on startup.

    Your Shortcut's target needs to be: C:\Windows\System32\WindowsPowerShell\v1.0\powersh ell.exe -sta -file "G:\BEKDocs\Scripts\Test-DragAndDrop.ps1" of course you'll need to adjust the file path for the location of the .ps1 file on your machine.

    Here's the code:
    # PowerShell Drag & Drop sample
    # Usage:
    # powershell -sta -file dragdrop.ps1
    # (-sta flag is required)
    # Sourec of Base Code:
    Function DragDropSample() {
      Add-Type -AssemblyName System.Windows.Forms
      $form = New-Object Windows.Forms.Form
      $form.text = "Drag&Drop sample"
      $listBox = New-Object Windows.Forms.ListBox
      $listBox.Dock = [System.Windows.Forms.DockStyle]::Fill
      $handler = {
        If ($_.Data.GetDataPresent(
             [Windows.Forms.DataFormats]::FileDrop)) {
          ForEach ($Filename in $_.Data.GetData(
             [Windows.Forms.DataFormats]::FileDrop)) {
             #***Delete following line if you don't want names listed ***
             Copy-Item -Path "$Filename" -Destination "$FileDest" -Force
          }  #End ForEach ($Filename...
        }    #End If ($_.Data...
      }      #End $handler
      $form.AllowDrop = $true
    }  #End Function DragDropSample
    #------------------------ Add a Helper ------------------------
    $SWAArgs = @{name = “Win32ShowWindowAsync” 
                 namespace = 'Win32Functions'}
    $showWindowAsync = Add-Type –memberDefinition @”
    public static extern bool ShowWindowAsync(
                IntPtr hWnd, int nCmdShow);
    “@ @SWAargs -PassThru
    Function Show-PowerShell() {
                       (Get-Process –id $pid).MainWindowHandle, 10)
    }  #End Function Show-PowerShell
    Function Hide-PowerShell() {
                       (Get-Process –id $pid).MainWindowHandle, 2)
    }  #End Function Hide-PowerShell
    #------------------------ Main Program  ------------------------
    $FileDest = "G:\Test\FilesToZip"  #*** Place your Filespec here!
    DragDropSample | Out-Null
    Here's a zipped file containing the file:

    Here's a sample run so you can see what it looks like and a view of File Explorer showing the files copied.

    Read the comments in the file for adjusting to your environment and needs. You can resize the window if you want it more the size of an Icon but that makes the file names a little hard to read.

    If you have never used PS you can find setup instructions here. Setting up PowerShell: Items 1-3

    BTW: I notice that this is only your second post so let me Welcome you to the Lounge!

    May the Forces of good computing be with you!


    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts