Help compressing with ActiveXPosh

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 15 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
nick44
Posts: 4
Last visit: Fri Nov 07, 2008 12:53 am

Help compressing with ActiveXPosh

Post by nick44 »

Hello,
I'm a new user of ActiveXPosh. It's a very helpful tool but I meet a problem when I try to compress a file.
This is the Powershell syntax:
(new-object -com shell.application).NameSpace("c:tempTest.Zip").CopyHere("c:tempNotepad.txt")

This works very well.

But when I transpose it to a vbscript with ActiveXPosh, nothing happens:



Dim ActiveXPoshSet ActiveXPosh = CreateObject("SAPIEN.ActiveXPosh")ActiveXPosh.Init(vbFalse)

zip = "c:tempTest.Zip"txt = "c:tempNotepad.txt"
ActiveXPosh.Execute("$Obj = (new-object -ComObject shell.application)") ActiveXPosh.Execute("$Zip = $Obj.NameSpace(" & """" & zip & """" & ")")ActiveXPosh.Execute("$Zip.CopyHere(" & """" & txt & """" & ")")
Do you have any idea where the problem is?
Many Thnaks for your help!
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Help compressing with ActiveXPosh

Post by jhicks »

I know from experience that COM interop in PowerShell is not always 100% effective or even consistent. I can get this to work natively in PowerShell but I too can't get the CopyHere method to work.

Code: Select all

Dim ActiveXPosh

Const OUTPUT_CONSOLE = 0 
Const OUTPUT_WINDOW = 1 
Const OUTPUT_BUFFER = 2 

Set ActiveXPosh = CreateObject("SAPIEN.ActiveXPosh")
ActiveXPosh.Init(vbFalse)

zip = "c:temptest.zip"
txt = "c:tempfoo1.txt"

ActiveXPosh.OutputMode = OUTPUT_CONSOLE

ActiveXPosh.Execute("$Obj = (new-object -ComObject shell.application)")

ActiveXPosh.Execute("$Zip = $Obj.NameSpace(" & """" & zip & """" & ")")
ActiveXPosh.Execute("$zip.title")
ActiveXPosh.Execute("dir " & txt)
ActiveXPosh.Execute("$Zip.CopyHere(""c:tempfoo1.txt"")")
ActiveXPosh.execute("$zip.items() | Select name,Path")
Maybe the development team can find something deeper. What version of PowerShell are you running and what OS?
User avatar
nick44
Posts: 4
Last visit: Fri Nov 07, 2008 12:53 am

Help compressing with ActiveXPosh

Post by nick44 »

Yes, It seems that the problem come from the CopyHere method.
Do someone know another way to compress files using ActiveXPosh ?

My version of Powershell is 1.0.0.0 and I run it on Vista.
Later It will probably run on a WS2003.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Help compressing with ActiveXPosh

Post by jhicks »

Since you are using a COM object anyway, why are you even bothering with ActiveXPosh? You should be able to accomplish everything you want with a simple VBScript. ActiveXPosh was intended so you could run PowerShell cmdlets from your VBScript. Technically you are running Powershell code, but there are probably better ways to do it.
User avatar
nick44
Posts: 4
Last visit: Fri Nov 07, 2008 12:53 am

Help compressing with ActiveXPosh

Post by nick44 »

That's right and the code for doing this exists and run in vbs.
I just try to transpose and understand the mecanism of Powershell ans ActiveXPosh...
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Help compressing with ActiveXPosh

Post by jhicks »

Try it with native PowerShell cmdlets like Get-Process and Get-Eventlog and you'll have better results.
User avatar
nick44
Posts: 4
Last visit: Fri Nov 07, 2008 12:53 am

Help compressing with ActiveXPosh

Post by nick44 »

I'm going to try it, thank you for your answers!
This topic is 15 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.