Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Marking items as downloaded

Reply
 
Old 09-14-2006   #1 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Marking items as downloaded

Does anyone know whether it is possible to mark an item as downloaded from
the Internet, so you get a warning on attempts to access it?

PowerShell honors file blocking done by IE, of course, but if we use
Net.WebClient or another tool to download the file, IE has no way of knowing
about the file.



My System SpecsSystem Spec
Old 09-14-2006   #2 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

RE: Marking items as downloaded

you should find an alternate Stream on the files downloaded :

:Zone.Identifier of 26 bits that holds: [ZoneTransfer] ZoneID=3

or 4

to do this by hand (CMD.exe)
make a zone.txt file in notepad incuiding this :

C:\>type zone.txt
[ZoneTransfer]
ZoneID=4

C:\>type zone.txt > test.ps1:Zone.Identifier

Greetings Marc


"Alex K. Angelopoulos [MVP]" wrote:

> Does anyone know whether it is possible to mark an item as downloaded from
> the Internet, so you get a warning on attempts to access it?
>
> PowerShell honors file blocking done by IE, of course, but if we use
> Net.WebClient or another tool to download the file, IE has no way of knowing
> about the file.
>
>
>

My System SpecsSystem Spec
Old 09-14-2006   #3 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Marking items as downloaded

Brilliant. I hate the workaround, but.. hey, it works.

"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:E9431A3D-4721-40A8-B6BE-0E13EBEBC9BC@microsoft.com...
> you should find an alternate Stream on the files downloaded :
>
> :Zone.Identifier of 26 bits that holds: [ZoneTransfer] ZoneID=3
>
> or 4
>
> to do this by hand (CMD.exe)
> make a zone.txt file in notepad incuiding this :
>
> C:\>type zone.txt
> [ZoneTransfer]
> ZoneID=4
>
> C:\>type zone.txt > test.ps1:Zone.Identifier
>
> Greetings Marc
>
>
> "Alex K. Angelopoulos [MVP]" wrote:
>
>> Does anyone know whether it is possible to mark an item as downloaded
>> from
>> the Internet, so you get a warning on attempts to access it?
>>
>> PowerShell honors file blocking done by IE, of course, but if we use
>> Net.WebClient or another tool to download the file, IE has no way of
>> knowing
>> about the file.
>>
>>
>>



My System SpecsSystem Spec
Old 09-14-2006   #4 (permalink)
Lee Holmes [MSFT]


 
 

Re: Marking items as downloaded

Unfortunately, there are no managed APIs that allow you to manage alternate
streams from a .Net language.

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:%235BSvlB2GHA.1588@TK2MSFTNGP02.phx.gbl...
> Brilliant. I hate the workaround, but.. hey, it works.
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:E9431A3D-4721-40A8-B6BE-0E13EBEBC9BC@microsoft.com...
>> you should find an alternate Stream on the files downloaded :
>>
>> :Zone.Identifier of 26 bits that holds: [ZoneTransfer] ZoneID=3
>>
>> or 4
>>
>> to do this by hand (CMD.exe)
>> make a zone.txt file in notepad incuiding this :
>>
>> C:\>type zone.txt
>> [ZoneTransfer]
>> ZoneID=4
>>
>> C:\>type zone.txt > test.ps1:Zone.Identifier
>>
>> Greetings Marc
>>
>>
>> "Alex K. Angelopoulos [MVP]" wrote:
>>
>>> Does anyone know whether it is possible to mark an item as downloaded
>>> from
>>> the Internet, so you get a warning on attempts to access it?
>>>
>>> PowerShell honors file blocking done by IE, of course, but if we use
>>> Net.WebClient or another tool to download the file, IE has no way of
>>> knowing
>>> about the file.
>>>
>>>
>>>

>
>



My System SpecsSystem Spec
Old 09-14-2006   #5 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

Re: Marking items as downloaded

in .NET also the : is not accepted, we need to use the API to get to ADS

I also did make a wrapper for the API in VB.NET
I planned to make it into a Cmdlet some time ago, as I did run into this
restriction in powershell also on testing, but not had time for it yet
(seeing this good use of it, might speed it up, if you want the VB code I can
look it up).
would be cleaner as a CMD /C in PowerShell (jsut did a quick sample with
notepad)

Greetings /\/\o\/\/

PS Alex, it's not my meaning to post only workarounds to your posts, just
did answer the question how to set it and where it was stored, and give a way
it is possible ;-)

"Lee Holmes [MSFT]" wrote:

> Unfortunately, there are no managed APIs that allow you to manage alternate
> streams from a .Net language.
>
> --
> Lee Holmes [MSFT]
> Windows PowerShell Development
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
> news:%235BSvlB2GHA.1588@TK2MSFTNGP02.phx.gbl...
> > Brilliant. I hate the workaround, but.. hey, it works.
> >
> > "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> > news:E9431A3D-4721-40A8-B6BE-0E13EBEBC9BC@microsoft.com...
> >> you should find an alternate Stream on the files downloaded :
> >>
> >> :Zone.Identifier of 26 bits that holds: [ZoneTransfer] ZoneID=3
> >>
> >> or 4
> >>
> >> to do this by hand (CMD.exe)
> >> make a zone.txt file in notepad incuiding this :
> >>
> >> C:\>type zone.txt
> >> [ZoneTransfer]
> >> ZoneID=4
> >>
> >> C:\>type zone.txt > test.ps1:Zone.Identifier
> >>
> >> Greetings Marc
> >>
> >>
> >> "Alex K. Angelopoulos [MVP]" wrote:
> >>
> >>> Does anyone know whether it is possible to mark an item as downloaded
> >>> from
> >>> the Internet, so you get a warning on attempts to access it?
> >>>
> >>> PowerShell honors file blocking done by IE, of course, but if we use
> >>> Net.WebClient or another tool to download the file, IE has no way of
> >>> knowing
> >>> about the file.
> >>>
> >>>
> >>>

> >
> >

>
>
>

My System SpecsSystem Spec
Old 09-14-2006   #6 (permalink)
=?Utf-8?B?ZHJlZXNjaGtpbmQ=?=


 
 

Re: Marking items as downloaded

"/\/\o\/\/ [MVP]" wrote:

> I also did make a wrapper for the API in VB.NET
> I planned to make it into a Cmdlet some time ago, as I did run into this
> restriction in powershell also on testing, but not had time for it yet
> (seeing this good use of it, might speed it up, if you want the VB code I can
> look it up).


Yeah, this might be a nice addition to the PowerShell Community Extensions
on CodePlex. I also wondered how to set this file property using standard
tools.
Maybe someone has the time to build a full-featured Cmdlet from it.
Would be nice to have it as a ScriptMethod for FileInfo objects.

--
greetings
dreeschkind
My System SpecsSystem Spec
Old 09-15-2006   #7 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

Re: Marking items as downloaded

I compiled this libarary (part of that where base of my translation to VB.NET
I think when I did find it back)

http://www.codeproject.com/csharp/nt...ams.asp?df=100

this Library gives me all the ADS power I want in PoSH see my commandline
example, see output, and is c# so easy to use for functions or CMDlets

My only problem with the File Blocking is that you need to load a new Shell
for it to work, I think tis was bugged the other way around allready, but was
in core OS.


[System.Reflection.Assembly]::LoadFile("c:\powershell\ntfs.dll")

"echo test" | out-file c:\powershell\test.ps1

$FS = new NTFS.FileStreams('c:\powershell\test.ps1')
$fs.add('Zone.Identifier')

$stream = $fs.Item('Zone.Identifier').open()

$sw = [System.IO.streamwriter]$stream
$Sw.writeline('[ZoneTransfer]')
$sw.writeline('ZoneID=4')
$sw.close()

$stream.close()

$FS = new NTFS.FileStreams('c:\powershell\test.ps1')
$FS | ft -a

PoSH>$FS | ft -a

Name Size
---- ----
Zone.Identifier 26

PoSH>.\test.ps1
test

PoSH>powershell
Windows(R) PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

PoSH>C:\PowerShell\test.ps1
The file C:\PowerShell\test.ps1 cannot be loaded. The file
C:\PowerShell\test.ps1 is not digitally signed. The script w
ill not execute on the system. Please see "get-help about_signing" for more
details..
At line:1 char:22
+ C:\PowerShell\test.ps1 <<<<

PoSH>exit
PoSH>.\test.ps1
test

PoSH>
"dreeschkind" wrote:

> "/\/\o\/\/ [MVP]" wrote:
>
> > I also did make a wrapper for the API in VB.NET
> > I planned to make it into a Cmdlet some time ago, as I did run into this
> > restriction in powershell also on testing, but not had time for it yet
> > (seeing this good use of it, might speed it up, if you want the VB code I can
> > look it up).

>
> Yeah, this might be a nice addition to the PowerShell Community Extensions
> on CodePlex. I also wondered how to set this file property using standard
> tools.
> Maybe someone has the time to build a full-featured Cmdlet from it.
> Would be nice to have it as a ScriptMethod for FileInfo objects.
>
> --
> greetings
> dreeschkind

My System SpecsSystem Spec
Old 10-12-2006   #8 (permalink)
dreeschkind


 
 

Re: Marking items as downloaded

I was able to create new alternate file streams without external library by
using COM.
However, deleting an alternate file stream causes an error message.
Any idea what may cause this error?

# functions:

function New-AFS {
param (
[IO.FileInfo]$file = $(throw 'Usage: New-AFS [IO.FileInfo]'),
[String]$streamName = $(throw 'Usage: New-AFS [String]'),
[String]$streamText = $(throw 'Usage: New-AFS [String]')
)
$fullFilePath = Convert-Path $file
if (Test-Path $fullFilePath) {
$fso = New-Object -ComObject Scripting.FileSystemObject
if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
'NTFS') {
$fileStreamName = "${file}:${streamName}"
$ts = $fso.CreateTextFile($fileStreamName)
$ts.Write($streamText)
$ts.Close()
}
}
}

function Get-AFS {
param (
[IO.FileInfo]$file = $(throw 'Usage: Get-AFS [IO.FileInfo]'),
[String]$streamName = $(throw 'Usage: Get-AFS [String]')
)
$fullFilePath = Convert-Path $file
if (Test-Path $fullFilePath) {
$fso = New-Object -ComObject Scripting.FileSystemObject
if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
'NTFS') {
$fileStreamName = "${file}:${streamName}"
$ts = $fso.OpenTextFile($fileStreamName)
$ts.ReadAll()
$ts.Close()
}
}
}

function Remove-AFS {
param (
[IO.FileInfo]$file = $(throw 'Usage: Remove-AFS [IO.FileInfo]'),
[String]$streamName = $(throw 'Usage: Remove-AFS [String]')
)
$fullFilePath = Convert-Path $file
if (Test-Path $fullFilePath) {
$fso = New-Object -ComObject Scripting.FileSystemObject
if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
'NTFS') {
$fileStreamName = "${file}:${streamName}"
$fso.DeleteFile($fileStreamName)
}
}
}

# test code:

PS> 'echo Hallo Welt!' > C:\Test-AFS.ps1

PS> New-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier' "[ZoneTransfer]`r`nZoneID=4"

PS> Get-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
[ZoneTransfer]
ZoneID=4

PS> Remove-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
Exception calling "DeleteFile" with "1" argument(s): "Ausnahme von HRESULT:
0x800A0034 (CTL_E_BADFILENAMEORNUMBER)"
At line:11 char:22
+ $fso.DeleteFile( <<<< $fileStreamName)


--
greetings
dreeschkind

"/\/\o\/\/ [MVP]" wrote:

> I compiled this libarary (part of that where base of my translation to VB.NET
> I think when I did find it back)
>
> http://www.codeproject.com/csharp/nt...ams.asp?df=100
>
> this Library gives me all the ADS power I want in PoSH see my commandline
> example, see output, and is c# so easy to use for functions or CMDlets
>
> My only problem with the File Blocking is that you need to load a new Shell
> for it to work, I think tis was bugged the other way around allready, but was
> in core OS.
>
>
> [System.Reflection.Assembly]::LoadFile("c:\powershell\ntfs.dll")
>
> "echo test" | out-file c:\powershell\test.ps1
>
> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
> $fs.add('Zone.Identifier')
>
> $stream = $fs.Item('Zone.Identifier').open()
>
> $sw = [System.IO.streamwriter]$stream
> $Sw.writeline('[ZoneTransfer]')
> $sw.writeline('ZoneID=4')
> $sw.close()
>
> $stream.close()
>
> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
> $FS | ft -a
>
> PoSH>$FS | ft -a
>
> Name Size
> ---- ----
> Zone.Identifier 26
>
> PoSH>.\test.ps1
> test
>
> PoSH>powershell
> Windows(R) PowerShell
> Copyright (C) 2006 Microsoft Corporation. All rights reserved.
>
> PoSH>C:\PowerShell\test.ps1
> The file C:\PowerShell\test.ps1 cannot be loaded. The file
> C:\PowerShell\test.ps1 is not digitally signed. The script w
> ill not execute on the system. Please see "get-help about_signing" for more
> details..
> At line:1 char:22
> + C:\PowerShell\test.ps1 <<<<
>
> PoSH>exit
> PoSH>.\test.ps1
> test
>
> PoSH>
> "dreeschkind" wrote:
>
> > "/\/\o\/\/ [MVP]" wrote:
> >
> > > I also did make a wrapper for the API in VB.NET
> > > I planned to make it into a Cmdlet some time ago, as I did run into this
> > > restriction in powershell also on testing, but not had time for it yet
> > > (seeing this good use of it, might speed it up, if you want the VB code I can
> > > look it up).

> >
> > Yeah, this might be a nice addition to the PowerShell Community Extensions
> > on CodePlex. I also wondered how to set this file property using standard
> > tools.
> > Maybe someone has the time to build a full-featured Cmdlet from it.
> > Would be nice to have it as a ScriptMethod for FileInfo objects.
> >
> > --
> > greetings
> > dreeschkind

My System SpecsSystem Spec
Old 10-13-2006   #9 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Marking items as downloaded

First, where the heck did you come up with that approach?

As for deleting the stream, I can think you can ge the proper effect by
opening the stream as if you are overwriting. I don't know if you need to
actually write anything to the stream to get it to overwrite, but writing an
empty string or a null character should be sufficient if you need to.

"dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message
news:38BCAE2E-80B6-49B1-A6B8-2A973D57F244@microsoft.com...
>I was able to create new alternate file streams without external library by
> using COM.
> However, deleting an alternate file stream causes an error message.
> Any idea what may cause this error?
>
> # functions:
>
> function New-AFS {
> param (
> [IO.FileInfo]$file = $(throw 'Usage: New-AFS [IO.FileInfo]'),
> [String]$streamName = $(throw 'Usage: New-AFS [String]'),
> [String]$streamText = $(throw 'Usage: New-AFS [String]')
> )
> $fullFilePath = Convert-Path $file
> if (Test-Path $fullFilePath) {
> $fso = New-Object -ComObject Scripting.FileSystemObject
> if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> 'NTFS') {
> $fileStreamName = "${file}:${streamName}"
> $ts = $fso.CreateTextFile($fileStreamName)
> $ts.Write($streamText)
> $ts.Close()
> }
> }
> }
>
> function Get-AFS {
> param (
> [IO.FileInfo]$file = $(throw 'Usage: Get-AFS [IO.FileInfo]'),
> [String]$streamName = $(throw 'Usage: Get-AFS [String]')
> )
> $fullFilePath = Convert-Path $file
> if (Test-Path $fullFilePath) {
> $fso = New-Object -ComObject Scripting.FileSystemObject
> if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> 'NTFS') {
> $fileStreamName = "${file}:${streamName}"
> $ts = $fso.OpenTextFile($fileStreamName)
> $ts.ReadAll()
> $ts.Close()
> }
> }
> }
>
> function Remove-AFS {
> param (
> [IO.FileInfo]$file = $(throw 'Usage: Remove-AFS [IO.FileInfo]'),
> [String]$streamName = $(throw 'Usage: Remove-AFS [String]')
> )
> $fullFilePath = Convert-Path $file
> if (Test-Path $fullFilePath) {
> $fso = New-Object -ComObject Scripting.FileSystemObject
> if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> 'NTFS') {
> $fileStreamName = "${file}:${streamName}"
> $fso.DeleteFile($fileStreamName)
> }
> }
> }
>
> # test code:
>
> PS> 'echo Hallo Welt!' > C:\Test-AFS.ps1
>
> PS> New-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> "[ZoneTransfer]`r`nZoneID=4"
>
> PS> Get-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> [ZoneTransfer]
> ZoneID=4
>
> PS> Remove-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> Exception calling "DeleteFile" with "1" argument(s): "Ausnahme von
> HRESULT:
> 0x800A0034 (CTL_E_BADFILENAMEORNUMBER)"
> At line:11 char:22
> + $fso.DeleteFile( <<<< $fileStreamName)
>
>
> --
> greetings
> dreeschkind
>
> "/\/\o\/\/ [MVP]" wrote:
>
>> I compiled this libarary (part of that where base of my translation to
>> VB.NET
>> I think when I did find it back)
>>
>> http://www.codeproject.com/csharp/nt...ams.asp?df=100
>>
>> this Library gives me all the ADS power I want in PoSH see my
>> commandline
>> example, see output, and is c# so easy to use for functions or CMDlets
>>
>> My only problem with the File Blocking is that you need to load a new
>> Shell
>> for it to work, I think tis was bugged the other way around allready, but
>> was
>> in core OS.
>>
>>
>> [System.Reflection.Assembly]::LoadFile("c:\powershell\ntfs.dll")
>>
>> "echo test" | out-file c:\powershell\test.ps1
>>
>> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
>> $fs.add('Zone.Identifier')
>>
>> $stream = $fs.Item('Zone.Identifier').open()
>>
>> $sw = [System.IO.streamwriter]$stream
>> $Sw.writeline('[ZoneTransfer]')
>> $sw.writeline('ZoneID=4')
>> $sw.close()
>>
>> $stream.close()
>>
>> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
>> $FS | ft -a
>>
>> PoSH>$FS | ft -a
>>
>> Name Size
>> ---- ----
>> Zone.Identifier 26
>>
>> PoSH>.\test.ps1
>> test
>>
>> PoSH>powershell
>> Windows(R) PowerShell
>> Copyright (C) 2006 Microsoft Corporation. All rights reserved.
>>
>> PoSH>C:\PowerShell\test.ps1
>> The file C:\PowerShell\test.ps1 cannot be loaded. The file
>> C:\PowerShell\test.ps1 is not digitally signed. The script w
>> ill not execute on the system. Please see "get-help about_signing" for
>> more
>> details..
>> At line:1 char:22
>> + C:\PowerShell\test.ps1 <<<<
>>
>> PoSH>exit
>> PoSH>.\test.ps1
>> test
>>
>> PoSH>
>> "dreeschkind" wrote:
>>
>> > "/\/\o\/\/ [MVP]" wrote:
>> >
>> > > I also did make a wrapper for the API in VB.NET
>> > > I planned to make it into a Cmdlet some time ago, as I did run into
>> > > this
>> > > restriction in powershell also on testing, but not had time for it
>> > > yet
>> > > (seeing this good use of it, might speed it up, if you want the VB
>> > > code I can
>> > > look it up).
>> >
>> > Yeah, this might be a nice addition to the PowerShell Community
>> > Extensions
>> > on CodePlex. I also wondered how to set this file property using
>> > standard
>> > tools.
>> > Maybe someone has the time to build a full-featured Cmdlet from it.
>> > Would be nice to have it as a ScriptMethod for FileInfo objects.
>> >
>> > --
>> > greetings
>> > dreeschkind



My System SpecsSystem Spec
Old 10-13-2006   #10 (permalink)
dreeschkind


 
 

Re: Marking items as downloaded

"Alex K. Angelopoulos [MVP]" wrote:

> First, where the heck did you come up with that approach?


"...there are no managed APIs that allow you to manage alternate streams..."
-- Lee Holmes [MSFT]

Well, I thought COM is not a managed API... :-)

I forgot to mention this article in my last post:

http://msdn.microsoft.com/library/de...html/ntfs5.asp

According to that article, I think my third function should work fine:
"The content of the selected stream can be deleted with a simple call to
DeleteFile()"
Have you tried it on your system? Do you get the same error message?

> As for deleting the stream, I can think you can ge the proper effect by
> opening the stream as if you are overwriting. I don't know if you need to
> actually write anything to the stream to get it to overwrite, but writing an
> empty string or a null character should be sufficient if you need to.


I think I'm gonna play with this stuff some more.
You can also create hard links and other NTFS features like VolumeMountPoints.
See second part of that article:

http://msdn.microsoft.com/library/de...html/ntfs2.asp

--
greetings
dreeschkind

> "dreeschkind" <dreeschkind@discussions.microsoft.com> wrote in message
> news:38BCAE2E-80B6-49B1-A6B8-2A973D57F244@microsoft.com...
> >I was able to create new alternate file streams without external library by
> > using COM.
> > However, deleting an alternate file stream causes an error message.
> > Any idea what may cause this error?
> >
> > # functions:
> >
> > function New-AFS {
> > param (
> > [IO.FileInfo]$file = $(throw 'Usage: New-AFS [IO.FileInfo]'),
> > [String]$streamName = $(throw 'Usage: New-AFS [String]'),
> > [String]$streamText = $(throw 'Usage: New-AFS [String]')
> > )
> > $fullFilePath = Convert-Path $file
> > if (Test-Path $fullFilePath) {
> > $fso = New-Object -ComObject Scripting.FileSystemObject
> > if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> > 'NTFS') {
> > $fileStreamName = "${file}:${streamName}"
> > $ts = $fso.CreateTextFile($fileStreamName)
> > $ts.Write($streamText)
> > $ts.Close()
> > }
> > }
> > }
> >
> > function Get-AFS {
> > param (
> > [IO.FileInfo]$file = $(throw 'Usage: Get-AFS [IO.FileInfo]'),
> > [String]$streamName = $(throw 'Usage: Get-AFS [String]')
> > )
> > $fullFilePath = Convert-Path $file
> > if (Test-Path $fullFilePath) {
> > $fso = New-Object -ComObject Scripting.FileSystemObject
> > if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> > 'NTFS') {
> > $fileStreamName = "${file}:${streamName}"
> > $ts = $fso.OpenTextFile($fileStreamName)
> > $ts.ReadAll()
> > $ts.Close()
> > }
> > }
> > }
> >
> > function Remove-AFS {
> > param (
> > [IO.FileInfo]$file = $(throw 'Usage: Remove-AFS [IO.FileInfo]'),
> > [String]$streamName = $(throw 'Usage: Remove-AFS [String]')
> > )
> > $fullFilePath = Convert-Path $file
> > if (Test-Path $fullFilePath) {
> > $fso = New-Object -ComObject Scripting.FileSystemObject
> > if (($fso.GetDrive($fso.GetDriveName($fullFilePath))).FileSystem -eq
> > 'NTFS') {
> > $fileStreamName = "${file}:${streamName}"
> > $fso.DeleteFile($fileStreamName)
> > }
> > }
> > }
> >
> > # test code:
> >
> > PS> 'echo Hallo Welt!' > C:\Test-AFS.ps1
> >
> > PS> New-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> > "[ZoneTransfer]`r`nZoneID=4"
> >
> > PS> Get-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> > [ZoneTransfer]
> > ZoneID=4
> >
> > PS> Remove-AFS 'C:\Test-AFS.ps1' 'Zone.Identifier'
> > Exception calling "DeleteFile" with "1" argument(s): "Ausnahme von
> > HRESULT:
> > 0x800A0034 (CTL_E_BADFILENAMEORNUMBER)"
> > At line:11 char:22
> > + $fso.DeleteFile( <<<< $fileStreamName)
> >
> >
> > --
> > greetings
> > dreeschkind
> >
> > "/\/\o\/\/ [MVP]" wrote:
> >
> >> I compiled this libarary (part of that where base of my translation to
> >> VB.NET
> >> I think when I did find it back)
> >>
> >> http://www.codeproject.com/csharp/nt...ams.asp?df=100
> >>
> >> this Library gives me all the ADS power I want in PoSH see my
> >> commandline
> >> example, see output, and is c# so easy to use for functions or CMDlets
> >>
> >> My only problem with the File Blocking is that you need to load a new
> >> Shell
> >> for it to work, I think tis was bugged the other way around allready, but
> >> was
> >> in core OS.
> >>
> >>
> >> [System.Reflection.Assembly]::LoadFile("c:\powershell\ntfs.dll")
> >>
> >> "echo test" | out-file c:\powershell\test.ps1
> >>
> >> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
> >> $fs.add('Zone.Identifier')
> >>
> >> $stream = $fs.Item('Zone.Identifier').open()
> >>
> >> $sw = [System.IO.streamwriter]$stream
> >> $Sw.writeline('[ZoneTransfer]')
> >> $sw.writeline('ZoneID=4')
> >> $sw.close()
> >>
> >> $stream.close()
> >>
> >> $FS = new NTFS.FileStreams('c:\powershell\test.ps1')
> >> $FS | ft -a
> >>
> >> PoSH>$FS | ft -a
> >>
> >> Name Size
> >> ---- ----
> >> Zone.Identifier 26
> >>
> >> PoSH>.\test.ps1
> >> test
> >>
> >> PoSH>powershell
> >> Windows(R) PowerShell
> >> Copyright (C) 2006 Microsoft Corporation. All rights reserved.
> >>
> >> PoSH>C:\PowerShell\test.ps1
> >> The file C:\PowerShell\test.ps1 cannot be loaded. The file
> >> C:\PowerShell\test.ps1 is not digitally signed. The script w
> >> ill not execute on the system. Please see "get-help about_signing" for
> >> more
> >> details..
> >> At line:1 char:22
> >> + C:\PowerShell\test.ps1 <<<<
> >>
> >> PoSH>exit
> >> PoSH>.\test.ps1
> >> test
> >>
> >> PoSH>
> >> "dreeschkind" wrote:
> >>
> >> > "/\/\o\/\/ [MVP]" wrote:
> >> >
> >> > > I also did make a wrapper for the API in VB.NET
> >> > > I planned to make it into a Cmdlet some time ago, as I did run into
> >> > > this
> >> > > restriction in powershell also on testing, but not had time for it
> >> > > yet
> >> > > (seeing this good use of it, might speed it up, if you want the VB
> >> > > code I can
> >> > > look it up).
> >> >
> >> > Yeah, this might be a nice addition to the PowerShell Community
> >> > Extensions
> >> > on CodePlex. I also wondered how to set this file property using
> >> > standard
> >> > tools.
> >> > Maybe someone has the time to build a full-featured Cmdlet from it.
> >> > Would be nice to have it as a ScriptMethod for FileInfo objects.
> >> >
> >> > --
> >> > greetings
> >> > dreeschkind

>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Marking threads? General Discussion
Downloaded items not found Vista General
spam marking Vista mail
Items not showing up when downloaded Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46