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!
Help compressing with ActiveXPosh
Help compressing with ActiveXPosh
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.
Maybe the development team can find something deeper. What version of PowerShell are you running and what OS?
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")
Help compressing with ActiveXPosh
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.
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.
Help compressing with ActiveXPosh
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.
Help compressing with ActiveXPosh
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...
I just try to transpose and understand the mecanism of Powershell ans ActiveXPosh...
Help compressing with ActiveXPosh
Try it with native PowerShell cmdlets like Get-Process and Get-Eventlog and you'll have better results.