Command line parameter (winzip) without surrounding quotes

jbpowell
jbpowell used Ask the Experts™
on
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\
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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*
Database and Application Developer
Commented:
Shell ("C:\Program Files\WinZip.exe c:\temp\oasis.zip")
Mike EghtebasDatabase and Application Developer

Commented:
BTW, you need to check name and paths for accuracy in my last post to make sure they are what you have.

Mike
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
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

Commented:
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.

Commented:
sorry,
Shell("C:\Program Files\WinZip\wzunzip oasis.zip c:\temp\")
Mike EghtebasDatabase and Application Developer

Commented:
My post, Shell ("C:\Program Files\WinZip.exe c:\temp\oasis.zip") , will open the zipped file.  It requiers mannual extraction.

Commented:

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

Author

Commented:
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
Mike EghtebasDatabase and Application Developer

Commented:
Thanky you.

Mike

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial