Solved

Command line parameter (winzip) without surrounding quotes

Posted on 2003-10-23
10
3,602 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now