Solved

Command line parameter (winzip) without surrounding quotes

Posted on 2003-10-23
10
3,605 Views
Last Modified: 2012-08-14
I'm trying to pass a command line parameter to unzip a file.  I create a string variable that the command line doesn't understand because it is enclosed in quotation marks.  Either I need to remove the starting/ending quotes or there's a better way to do this altogether.

More info on the string variable.........
variable composed of:
1. the location of winzip.exe (this must be enclosed in quotes)
2. the filename and the destination folder (these should not be quoted)

The string ends up looking like this in the immediate window:
""C:\Program Files\WinZip\wzunzip" oasis.zip c:\temp\"

It should look like this (ie without the starting and ending quote):
"C:\Program Files\WinZip\wzunzip" oasis.zip c:\temp\
0
Comment
Question by:jbpowell
10 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9610344
jbpowell,

> Either I need to remove the starting/ending quotes or there's a better way to
> do this altogether.

You should remove the quotes like this:
Say your string variable is "strEXE".  Before you execute the command line, do this:
    strEXE = Mid( strExe, 2, Len(strEXE)-2 )

That should remove the first and last characters from the string.  In this case, the quotes that are giving your grief.

Hope that helps,
Dex*
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 9610424
Shell ("C:\Program Files\WinZip.exe c:\temp\oasis.zip")
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 9610435
BTW, you need to check name and paths for accuracy in my last post to make sure they are what you have.

Mike
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 2

Expert Comment

by:pilby
ID: 9610464
where do the quotes come from in the original string in the first place?

try assigning your string like this:

str = """C:\Program Files\Winzip\wzunzip"" oasis.zip c:\temp"

the first and last quotes should identify the string to be passed, the double quotes ("") represent a single set of quotation marks within a string.  in the end, your string should be the way you want it.

OR if you need to assign the location of winzip and the rest separately, try:

winzipStr = "C:\Program Files\WinZip\wzunzip"   (will be assigned w/o quotes)
filenameDestStr = "oasis.zip c:\temp\"                (again, no quotes in resulting string)
str = """" & winzipStr & """"                               (putting quotes around it)
str = str & filenameDestStr                                (adds on the filename and destination w/o quotes)

the end result should be the same (assuming winzipStr and filenameDestStr don't contain any quotes)

weston
0
 
LVL 2

Expert Comment

by:pilby
ID: 9610562
what command are you using on the string?  a Shell command should do the trick (although you'll probably need: Shell ("C:\Program Files\WinZip.exe oasis.zip c:\temp\") , not the exactly what eghtebas gave you) and you won't have to worry about quotes inside strings.
0
 
LVL 2

Expert Comment

by:pilby
ID: 9610573
sorry,
Shell("C:\Program Files\WinZip\wzunzip oasis.zip c:\temp\")
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 9610655
My post, Shell ("C:\Program Files\WinZip.exe c:\temp\oasis.zip") , will open the zipped file.  It requiers mannual extraction.
0
 
LVL 4

Expert Comment

by:inox
ID: 9610744

try
  Shell ("""C:\Program Files\WinZip\wzunzip"" oasis.zip c:\temp\")
0
 

Author Comment

by:jbpowell
ID: 9616369
Thank you eightbas, I did not test your solution, what I ended up doing was to copy the wzzip.exe and wzunzip.exe files to this folder: C:\Program Files\Common Files\Autodesk Shared

That allows me to execute winzip with the code below using the following cmdline$ string parameter.

cmdline$ = "wzunzip -o c:\temp\oasis.zip c:\temp"


'***********************************************************************************************
' Module: ShellCmd
'
' This module provides the functionality necessary to synchronously execute a shell command.
'
' NOTE: We need to wait for the unzip to finish before we continue processing.  This is a more
' efficient method then polling the task Id which would be required if we used the VB shell command.
'
' See http://support.microsoft.com/support/kb/articles/Q129/7/96.ASP for more information on
' this code.
'***********************************************************************************************
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type

   Private Type PROCESS_INFORMATION
      hProcess As Long
      hThread As Long
      dwProcessID As Long
      dwThreadID As Long
   End Type
   
Public Function ExecCmd(cmdline$)
'***********************************************************************************************
' Function:     ExecCmd
' Parameters:   cmdline$ - string containing the full command line to be executed,
'                           including parameters
'
' Returns: 0 iff successful (long)
'
' This function will execute a shell command in a new window.  The window will receive focus.
' This function only returns when the command has terminated (and the commands
' window is closed).
'***********************************************************************************************
On Error GoTo ErrorHandler
      Dim proc As PROCESS_INFORMATION
      Dim start As STARTUPINFO
      Dim ret&

      ' Initialize the STARTUPINFO structure:
      start.cb = Len(start)

      ' Start the shelled application:
      ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
         NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

      ' Wait for the shelled application to finish:
         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         Call GetExitCodeProcess(proc.hProcess, ret&)
         Call CloseHandle(proc.hThread)
         Call CloseHandle(proc.hProcess)
         ExecCmd = ret&
         
    Exit Function
ErrorHandler:
    MsgBox "Error: " & Err.Description
End Function
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 9617052
Thanky you.

Mike
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question