jbpowell
asked on
Command line parameter (winzip) without surrounding quotes
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\
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\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, you need to check name and paths for accuracy in my last post to make sure they are what you have.
Mike
Mike
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
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
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.
sorry,
Shell("C:\Program Files\WinZip\wzunzip oasis.zip c:\temp\")
Shell("C:\Program Files\WinZip\wzunzip oasis.zip c:\temp\")
My post, Shell ("C:\Program Files\WinZip.exe c:\temp\oasis.zip") , will open the zipped file. It requiers mannual extraction.
try
Shell ("""C:\Program Files\WinZip\wzunzip"" oasis.zip c:\temp\")
ASKER
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(vbNullStrin g, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.h Process, INFINITE)
Call GetExitCodeProcess(proc.hP rocess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
Exit Function
ErrorHandler:
MsgBox "Error: " & Err.Description
End Function
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(vbNullStrin
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.h
Call GetExitCodeProcess(proc.hP
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
Exit Function
ErrorHandler:
MsgBox "Error: " & Err.Description
End Function
Thanky you.
Mike
Mike
> 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*