Google Grupper understøtter ikke længere nye Usenet-opslag eller -abonnementer. Tidligere indhold er fortsat synligt.

zipping a file via vb and wsh

21 visninger
Gå til det første ulæste opslag

djc

ulæst,
10. dec. 2002, 08.37.2510.12.2002
til
I need to add zipping up some files as part of a script. Any known good
methods out there? The first thing that comes to mind for me is to get rar
and spawn a command shell to run it... any other, different, easier, better
ways out there?

any input is greatly appreciated. Thanks
DJC


Atrax _

ulæst,
10. dec. 2002, 22.32.2910.12.2002
til
There's a lightweight ZIP component I wrote at :

http://rtfm.atrax.co.uk/boards/asp.asp?action=viewPost&postID=295

I still; haven't got around to documenting it fully, though, and I
haven't released the 'full' version yet.

________________________________________
I got bored with my old signature,
so I changed it

Atrax. MVP, IIS
http://rtfm.atrax.co.uk/

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

djc

ulæst,
11. dec. 2002, 08.06.1811.12.2002
til
cool... I'll check it out. Thanks.

"Atrax _" <anon...@devdex.com> wrote in message
news:OB4fvXMoCHA.1600@TK2MSFTNGP11...

Torgeir Bakken (MVP)

ulæst,
11. dec. 2002, 03.54.4711.12.2002
til
djc wrote:

> I need to add zipping up some files as part of a script. Any known good
> methods out there? The first thing that comes to mind for me is to get rar
> and spawn a command shell to run it... any other, different, easier, better
> ways out there?

Hi

You can use the Run method and shell out and call a command line based zip
program, or you can use an ActiveX component to do this from a script (e.g. the
one Atrax pointed to).


ZipGenius has a command line interface (freeware)
http://www.zipgenius.it/

WinZip Command Line Support Add-On
http://www.winzip.com/wzcline.htm

PowerArchiver has a command line version as well:
http://www.powerarchiver.com


An alternativ to zip is to use cab files instead:

From: Torgeir Bakken (Torgeir.B...@hydro.com)
Subject: Re: create a cab file
Newsgroups: microsoft.public.scripting.jscript
Date: 2002-07-16 20:03:35 PST
http://groups.google.com/groups?selm=3D34DC2F.DD931369%40hydro.com

--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway


Alex K. Angelopoulos (MVP)

ulæst,
12. dec. 2002, 17.28.3112.12.2002
til
"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3DF6FD57...@hydro.com...

>
> An alternativ to zip is to use cab files instead:
>
> From: Torgeir Bakken (Torgeir.B...@hydro.com)
> Subject: Re: create a cab file
> Newsgroups: microsoft.public.scripting.jscript
> Date: 2002-07-16 20:03:35 PST
> http://groups.google.com/groups?selm=3D34DC2F.DD931369%40hydro.com
>

By the way, here's an enhanced form of the catsrvut.dll-based cab file creation.
Torgeir, would you be able to verify that this works on your WIn2KSP2? I've
noticed an oddity with the calls if I try to use a string variable instead of a
string literal; on XP any such call will fail. If I coerce it to a string while
sending, though, it runs fine....

f = Array("C:\WINDOWS\system32\vbscript.dll", "C:\WINDOWS\system32\wshom.ocx",
"C:\WINDOWS\system32\wshext.dll", "C:\WINDOWS\system32\wshcon.dll")
'f = "C:\WINDOWS\system32\vbscript.dll"
MakeCabFile "C:\tmp\Wshcore.cab", f


Sub MakeCabFile( Cabpath, fil)
Dim cab, i
On Error Resume Next
' We turn on error control because different versions of catsrvut.dll
' take different numbers of non-optional arguments.
' An XP version (numbered 2001.12.4414.46) needs 4 arguments;
' A Win2K SP2 version (2000.2.3488.0) takes 3 arguments only
Set cab = CreateObject("MakeCab.MakeCab.1")
' The Methods of catsrvut seem to be finicky about argument types as well
' they tend to throw errors if we don't explicitly coerce the paths to
' strings before sending.
cab.CreateCab CStr(Cabpath), False, False
If Err.Number<>0 Then
If Err.Number = 450 Then
cab.CreateCab CStr( cabpath ), False, False, False
Else
Exit Sub
End If
End If
On Error Goto 0
' following allows simple calls to the function; the files argument
' can be supplied as a single string for one file or as an array for
' multiple files.
' This also
If IsArray(fil) Then
for i = 0 to Ubound(fil)
cab.AddFile CStr( Trim(fil(i)) ), _
CStr( Mid(fil(i), InStrRev(fil(i), "\")+1) )
next
Else
cab.AddFile CStr( fil ), CStr( Mid(fil, InStrRev(fil, "\")+1) )
end if
cab.CloseCab
End Sub


Torgeir Bakken (MVP)

ulæst,
12. dec. 2002, 17.36.0212.12.2002
til
"Alex K. Angelopoulos (MVP)" wrote:

> "Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
> news:3DF6FD57...@hydro.com...
>
> >
> > An alternativ to zip is to use cab files instead:
> >
> > From: Torgeir Bakken (Torgeir.B...@hydro.com)
> > Subject: Re: create a cab file
> > Newsgroups: microsoft.public.scripting.jscript
> > Date: 2002-07-16 20:03:35 PST
> > http://groups.google.com/groups?selm=3D34DC2F.DD931369%40hydro.com
> >
>
> By the way, here's an enhanced form of the catsrvut.dll-based cab file creation.
> Torgeir, would you be able to verify that this works on your WIn2KSP2? I've
> noticed an oddity with the calls if I try to use a string variable instead of a
> string literal; on XP any such call will fail. If I coerce it to a string while
> sending, though, it runs fine....

Your script worked very well on my Win2k SP2 :-)

Michael Harris (MVP)

ulæst,
12. dec. 2002, 17.46.5812.12.2002
til
> ... I've noticed an oddity with the calls if I try to

> use a string variable instead of a string literal; on XP any such
> call will fail. If I coerce it to a string while sending, though, it
> runs fine....

A symptom of a COM method parameter defined as strongly type byref (ByRef As
String in VB-speak). Not very script friendly ;-).

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Alex K. Angelopoulos (MVP)

ulæst,
12. dec. 2002, 18.16.5812.12.2002
til
For this interface, it actually shows as being ByVal in an object viewer. What
else might be happening?


--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
----------
Subscribe to Microsoft's Security Bulletins:
http://www.microsoft.com/technet/security/bulletin/notify.asp


"Michael Harris (MVP)" <mik...@mvps.org> wrote in message
news:#VGVdBjoCHA.1636@TK2MSFTNGP10...

Michael Harris (MVP)

ulæst,
12. dec. 2002, 21.00.1612.12.2002
til
Alex K. Angelopoulos (MVP) wrote:
> For this interface, it actually shows as being ByVal in an object
> viewer. What else might be happening?
>

There's really no guarantee that the typelib (which is created from an *.idl
file which someone authored independent of the source/executable) is
correct. Don't you have a gizmo for getting typelib info from a running
instance of an object?

Alex K. Angelopoulos (MVP)

ulæst,
13. dec. 2002, 04.31.2513.12.2002
til
Using Tlbinf32.dll I do, but that's the same as TLViewer's technique - which is
where I pulled by the ByVal data from...

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
----------
Subscribe to Microsoft's Security Bulletins:
http://www.microsoft.com/technet/security/bulletin/notify.asp


"Michael Harris (MVP)" <mik...@mvps.org> wrote in message

news:#sv9TtkoCHA.704@TK2MSFTNGP09...

Prisca

ulæst,
4. jan. 2003, 13.15.4704.01.2003
til
"djc" <david.co...@hesstech.com> wrote in message news:<#g5FWFFoCHA.1612@TK2MSFTNGP09>...

> I need to add zipping up some files as part of a script. Any known good

Hi,

Can we also do the opposite, eg to read a cab file from WSH?

Purpose: to examine its contents programmatically, be able to answer
questions like "does xyz.cab contain abc.dll" from vbscript

regards,

Prisc.

Torgeir Bakken (MVP)

ulæst,
4. jan. 2003, 14.48.5504.01.2003
til
Prisca wrote:

> "djc" <david.co...@hesstech.com> wrote in message news:<#g5FWFFoCHA.1612@TK2MSFTNGP09>...
> > I need to add zipping up some files as part of a script. Any known good
>

> Can we also do the opposite, eg to read a cab file from WSH?
>
> Purpose: to examine its contents programmatically, be able to answer
> questions like "does xyz.cab contain abc.dll" from vbscript

Hi

This can be done by using Extract.exe from the Microsoft Cabinet SDK (free) or
EclipseCabinet99.ocx from Green Eclipse Software (free)

Download links here:
http://groups.google.com/groups?selm=3D34DC2F.DD931369%40hydro.com

Examples with the two methods:

==================================================
Extract.exe

Parse the output of Extract.exe. Use e.g. output redirection to a file with something like this:

"%comspec% /c extract.exe ... >c:\extract.log"


In a cabinet where abc.dll exists:

C:\>EXTRACT.EXE /D C:\test\Sample.cab abc.dll
Microsoft (R) Diamond Extraction Tool - Version (32) 1.00.0601 (03/18/97)
Copyright (c) Microsoft Corp 1994-1997. All rights reserved.

Cabinet Sample.cab

10-14-2001 1:22:00a A--- 297 abc.dll
1 File 997 bytes


In a cabinet where abc.dll does not exists:

C:\>EXTRACT.EXE /D C:\test\Sample.cab abc.dll
Microsoft (R) Diamond Extraction Tool - Version (32) 1.00.0601 (03/18/97)
Copyright (c) Microsoft Corp 1994-1997. All rights reserved.

Cabinet Sample.cab

No matching files.


==================================================
EclipseCabinet99.ocx


' File to check
sFile = "abc.dll"

' Cabfile
sCabFile = "C:\test\Sample.cab"

Set oExtract = CreateObject("EclipseCabinet99.ecExtract")

oExtract.Filename = sCabFile

On Error Resume Next
sReturn = oExtract.Files.ItemByName(sFile)

If Err.Number <> 0 Then
WScript.Echo "File " & sFile & " does not exist in the cab file " & sCabFile
Else
WScript.Echo "File " & sFile & " does exist in the cab file " & sCabFile


End If
On Error Goto 0

Prisca

ulæst,
5. jan. 2003, 09.58.3205.01.2003
til
you are right, thank you!
However I am surprised there is no "pure vbscript/COM" way (=without
third party component or separate exe), as cabinets seem to be a deep
basic feature of windows: setup programs, also from Microsoft,
downloaded components in Internet Explorer, SQL Server analysis
services backup etc are relying on them. Having to expand a cabinet
file to check its contents seems like using a cannon to hit a fly, is
it not?
In Java, it would be possible to open an archive using standard API's,
without any supplemental component or program.

Prisc.


"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message news:<3E173AA7...@hydro.com>...

Torgeir Bakken (MVP)

ulæst,
5. jan. 2003, 11.45.5205.01.2003
til
Prisca wrote:

> you are right, thank you!
> However I am surprised there is no "pure vbscript/COM" way (=without
> third party component or separate exe), as cabinets seem to be a deep
> basic feature of windows: setup programs, also from Microsoft,
> downloaded components in Internet Explorer, SQL Server analysis
> services backup etc are relying on them. Having to expand a cabinet
> file to check its contents seems like using a cannon to hit a fly, is
> it not?

Note that none of the two methods I supplied expands the cabinet file to check if a file exists in it...

E.g. EXTRACT.EXE /D will only display files, not extract them.

0 nye opslag