CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Location
    Washington DC
    Posts
    2

    Shell command to execute Pkzip in Windows NT

    I created a VB program which creates a database, executes Pkzip to zip the mdb, and create an executable file. The application works in Windows 98 and Windows 2000, but for some reason it is not working in Windows NT. I have read Microsofts website and how Pkzip can "hang" the system, so I moved the application to a read and write directory, but it still isn't working. I am new to the programming world, so bear with me. Any help would be greatly appreciated! Thank you!


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Shell command to execute Pkzip in Windows NT

    If you manually run PKzip on your winnt machine, does it works? (You know, via the old Dos prompt...).
    If so, something is missing in your application. Ie: you know PKzip will require short Path and File names?...
    Hope this may help
    Cesare Imperiali

    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    May 2001
    Location
    Washington DC
    Posts
    2

    Re: Shell command to execute Pkzip in Windows NT

    Thanks for the input. I tested Pkzip on an associates computer running Windows NT, and it worked without any problems. Then I ran my application on it and it seemed to work this time? But then I got a "Dr. Watson Fatal error code 87" I think it is because I left the MS-DOS window open from when I ran it manually. Does this make sense??? Thanks again for your response. Have a great day!


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Shell command to execute Pkzip in Windows NT

    Have a look at this code (special tahnks to codeguru people-some of it is of some guys here). Look expecially at module .bas code. There are some Api inside, so check for sintax under NT (it may be different, and it may be reason why it may not work on that machine: I run this only under win98).
    Option Explicit
    'remember position of files pkzip e pkunzip
    Public strToUnZip As String
    Public strToZip As String
    '--------------
    'pkzip and winzip (even version 8.0)
    'work with short files name
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

    '--------------
    'wait for end of task
    Const INFINITE = -1&

    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

    Public Function Chiama_E_Attendi(sfile As String) As Long
    Dim strNomeArchivio As String
    Dim lngExecOK As Long
    Dim lProcessHandle As Long
    Dim lReturnValue As Long

    On Error GoTo errHandler

    Fshell.Hide 'hide form

    'pkzip and winzip work with dos names!
    Dim lenShort As Long
    lenShort = Len(sfile)
    Dim sfileShort As String * 255
    Dim sfileShort2 As String
    Dim lngCallApi As Long

    lngCallApi = GetShortPathName(sfile, sfileShort, lenShort)


    sfileShort2 = Left(sfileShort, lngCallApi)
    'if first byte= 0,
    'path is already short
    If Asc(Left(sfileShort2, 1)) = 0 Then
    sfileShort2 = sfile
    End If
    'choose what to do on extension of file
    If UCase(Right(sfile, 3)) = "ZIP" Then
    'where is pkunzip.exe?
    If Dir(strToUnZip, vbDirectory) = "" Or Len(strToUnZip) = 0 Then
    strToUnZip = InputBox("insert path to ''Pkunzip.exe'' without last slash ")
    End If
    If Dir(strToUnZip & "\pkunzip.exe") = "" Then
    MsgBox "pkunzip.exe not found in " & strToUnZip
    strToUnZip = ""
    Fshell.Show ' show form
    Exit Function
    End If
    lngExecOK = Shell(strToUnZip & "\pkunzip.exe" & Space(1) & "-d" & Space(1) & sfileShort2, vbNormalFocus)
    Else
    ' mdb extension
    'compress with pkzip
    '1)where is pkzip.exe?

    If Dir(strToZip, vbDirectory) = "" Or Len(strToZip) = 0 Then
    strToZip = InputBox("insert path to ''Pkzip.exe'' without ending slash")
    End If
    If Dir(strToZip & "\pkunzip.exe") = "" Then
    MsgBox "pkzip.exe not found in " & strToZip
    strToZip = ""
    Fshell.Show 'show form
    Exit Function
    End If

    '2)name for compress file
    strNomeArchivio = InputBox("input a name for comprtess archive (Max 8 char. do not type extension)")
    If Len(strNomeArchivio) > 8 Then
    strNomeArchivio = Left(strNomeArchivio, 8) & ".zip"
    ElseIf strNomeArchivio = "" Then
    ' cancel pressed or not name inserted
    'Default name:
    'strNomeArchivio = "backup.zip"
    'or show fShell again
    Fshell.Show 'rimostra la form
    Exit Function

    End If
    lngExecOK = Shell(strToZip & "\pkzip.exe" & Space(1) & strNomeArchivio & Space(1) & sfileShort2, vbNormalFocus)
    End If

    'utilizza il valore di ritorno della funzione shell
    'per ottenere un handle al processo
    lProcessHandle = OpenProcess(&H100000, True, lngExecOK)

    'aspetta finchè il processo non si chiude
    lReturnValue = WaitForSingleObject(lProcessHandle, INFINITE)


    'quando la riga seguente verr* eseguita,
    'il programma chiamato avr* terminato la sua esecuzione

    Fshell.Show 'rimostra la finestra

    'MsgBox "Terminato " & Now

    Chiama_E_Attendi = lReturnValue
    Exit Function
    errHandler:
    MsgBox Err & Space(2) & Error$
    Err.Clear
    Unload Fshell
    Set Fshell = Nothing
    End
    End Function

    Sub Main()
    'impedisci il lancio di cloni di questo programma
    'da parte dello stesso utente. Questo non è il modo
    'migliore per farlo: due copie di questo eseguibile
    'in due directory diverse possono ingannare il
    'sistema. In sostituzione, esiste un'Api che trova
    'le finestre in base al loro nome...
    If App.PrevInstance Then
    End
    End If
    Load Fshell
    Fshell.Show
    End Sub


    Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured