Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENI 
Author Message
 Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENI

Not Sure Why this is causing a security error. I checked
The web but couldn't find any usefull Info on this one
exept that you need to grant ASPNET privlages on your
computer. I have already done this for some web
aplications so that cant be it unless ther is a difrent
account for VB.NET whitch I cant find.
This Is Some of my code, the part that the debuger is
{*filter*} on

Private Sub Button1_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Button1.Click
        Dim oFileSys, fh1, fh2, fh3, fh4, fh5
        Dim Dir, filcnt
        Dim Wedone
        Dim strDirDoneTxt
        Dim strMsgTitle
        Dim strInput, strRunit
        Dim IExec, strTarget

        ' Change this file name if you
        ' want to use a different one.
        strTarget = "\Z_MapList.txt"
        strlincol = 1
        strInput = TextBox1.Text

        Dir = strInput

        oFileSys = CreateObject
("Scripting.FileSystemObject")
        fh1 = oFileSys.createTextFile(strInput & strTarget)
        Dim oFolder, oFolders, oFiles, oName, item, Item2,
dacolr

        oFolder = oFileSys.GetFolder(Dir) 'This is wher it
Locks the Debuger
        oFolders = oFolder.SubFolders
        oFiles = oFolder.Files

        For Each Item2 In oFiles
            fh3 = oFileSys.openTextFile(strInput &
strTarget, 8)
            fh3.WriteLine(Item2.Name)
            fh3.close()

        Next
    End Sub



Mon, 07 Nov 2005 17:55:16 GMT  
 Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENI
Hi, lets do it the managed way (you need to import the System.IO namespace
at the top of your code):

Private Sub Buton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
    Dim strTarget As String
    strTarget = "\Z_MapList.txt"

    Dim fsStream As StreamWriter = File.CreateText(TextBox1.Text &
strTarget)

    For Each strFile As String In Directory.GetFiles(CurDir)
        fsStream.WriteLine(strFile)
    Next
    fsStream.Close()
End Sub

Note: If you aren't using VS.NET 2003, then you'll have to change this line:
For Each strFile As String In Directory.GetFiles(CurDir)

To this:

Dim strFile As String
For Each strFile In Directory.GetFiles(CurDir)

Hope this helps, and I had to assume that the 'Dir' in your code was
referring to the current directory, so I changed it to CurDir in the
GetFiles statement.
--
Happy to help,
-- Tom Spink


Quote:
> Not Sure Why this is causing a security error. I checked
> The web but couldn't find any usefull Info on this one
> exept that you need to grant ASPNET privlages on your
> computer. I have already done this for some web
> aplications so that cant be it unless ther is a difrent
> account for VB.NET whitch I cant find.
> This Is Some of my code, the part that the debuger is
> {*filter*} on

> Private Sub Button1_Click(ByVal sender As Object, ByVal e
> As System.EventArgs) Handles Button1.Click
>         Dim oFileSys, fh1, fh2, fh3, fh4, fh5
>         Dim Dir, filcnt
>         Dim Wedone
>         Dim strDirDoneTxt
>         Dim strMsgTitle
>         Dim strInput, strRunit
>         Dim IExec, strTarget

>         ' Change this file name if you
>         ' want to use a different one.
>         strTarget = "\Z_MapList.txt"
>         strlincol = 1
>         strInput = TextBox1.Text

>         Dir = strInput

>         oFileSys = CreateObject
> ("Scripting.FileSystemObject")
>         fh1 = oFileSys.createTextFile(strInput & strTarget)
>         Dim oFolder, oFolders, oFiles, oName, item, Item2,
> dacolr

>         oFolder = oFileSys.GetFolder(Dir) 'This is wher it
> Locks the Debuger
>         oFolders = oFolder.SubFolders
>         oFiles = oFolder.Files

>         For Each Item2 In oFiles
>             fh3 = oFileSys.openTextFile(strInput &
> strTarget, 8)
>             fh3.WriteLine(Item2.Name)
>             fh3.close()

>         Next
>     End Sub



Mon, 07 Nov 2005 18:21:37 GMT  
 Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENI
Well I think I fuigerd out the error. I'm doing this in
VBS and VB.NET and it works fine in VBS but now I have
more errors. I changed all my dir variables to dirc and it
resolved the "Exception from HRESULT" error.
I have the Scripting and system.io Namespaces included:)
Now I get theas errors with this code:

A first chance exception of
type 'System.NullReferenceException' occurred in
microsoft.visualbasic.dll

Additional information: Object reference not set to an
instance of an object.

A first chance exception of
type 'System.InvalidCastException' occurred in
microsoft.visualbasic.dll

Additional information: Cast from type 'IFile' to
type 'String' is not valid.

Breaks at the if statment

Private Sub Button1_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Button1.Click
        Dim oFileSys, fh1, fh2, fh3, fh4, fh5
        Dim Dirc, filcnt
        Dim Wedone
        Dim strDirDoneTxt
        Dim strMsgTitle
        Dim strInput, strRunit
        Dim IExec, strTarget

        ' Change this file name if you
        ' want to use a different one.
        strTarget = "\Z_MapList.txt"
        strlincol = 1
        strInput = TextBox1.Text

        Dirc = strInput

        oFileSys = CreateObject
("Scripting.FileSystemObject")
        fh1 = oFileSys.createTextFile(strInput & strTarget)
        Dim oFolder, oFolders, oFiles, oName, item, Item2,
dacolr

        oFolder = oFileSys.GetFolder(Dirc)
        oFolders = oFolder.SubFolders
        oFiles = oFolder.Files

        For Each Item2 In oFiles
            If InStr(1, Item2, TextBox2.Text) = 0 Then
                fh3 = oFileSys.openTextFile(strInput &
strTarget, 8)
                fh3.WriteLine(Item2.Name)
                fh3.close()
            End If
        Next
    End Sub



Mon, 07 Nov 2005 19:11:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Question about "Exception from HRESULT: 0x80131019"

2. How can i get the hResult of the Exception class

3. Exceptions and HResults revisited

4. Permission denied (0x800A0046) on f.OpenAsTextStream

5. Permission Denied - 0x800A0046

6. Microsoft VBScript runtime (0x800A0046) - Permission Denied

7. Project1 (0x800A0046)

8. SetReportVariableValue returns Permission Denied (Microsoft VBScript runtime (0x800A0046))

9. Catch Exception Compluss Exception Code

10. Setting Custom HResult for User Defined Exceptions in Interop...

11. Excel HRESULT: 0x800A03EC when using Workbooks.open or Workbooks._opentext in C#

12. HRESULT: 0x800A003A (CTL_E_FILEALREADYEXISTS).

 

 
Powered by phpBB® Forum Software