Results 1 to 6 of 6

Thread: writing to registry with an assembly

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    13

    writing to registry with an assembly

    hi@all!

    I have a component (assembly) with an object that writes data to a registry key.

    When this is run from a Windows app, it works like a charm. When run from a web app, it doesnt work.

    here is the code:


    Code:
     
    
      Public Function sendandprint(ByVal path As String)
    
          Dim Key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\pdfMachine\BroadGun pdfMachine", True)
            Dim f As New RegistryPermission(RegistryPermissionAccess.AllAccess, Key.Name)
            f.Assert()
    
    
            Dim success As Integer
            Dim strfile As String
            Dim strpath As String
            Dim pdffile As String
    
            Dim reader As StreamReader = New StreamReader(path + "pdfpath.txt")
            pdffile = reader.ReadLine
            reader.Close()
    
            Try
                If Not IsNothing(Key) Then
                    Key.SetValue("DefaultSaveDir", path)
                    Key.SetValue("DefaultSaveFilename", pdffile)
                    strfile = Key.GetValue("DefaultSaveFilename")
                    strpath = Key.GetValue("DefaultSaveDir")
                    Key.Close()
                    Dim fs4 As New FileStream(path & "print.txt", FileMode.Append)
                    Dim sw4 As New StreamWriter(fs4)
                    sw4.WriteLine("done")
                    sw4.Close()
    
                Else
                    Dim fs4 As New FileStream(path & "print.txt", FileMode.Append)
                    Dim sw4 As New StreamWriter(fs4)
                    sw4.WriteLine("is nothing")
                    sw4.Close()
                End If
            Catch ex As Exception
                Dim fs4 As New FileStream(path & "print.txt", FileMode.Append)
                Dim sw4 As New StreamWriter(fs4)
                sw4.WriteLine(ex.Message + " Fehler beim Schreiben")
                sw4.Close()
            End Try
    
    End Function

    thx for any suggestions u have!

    greetings

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    where does it fail?

    Is it on the registry access bit or the file writing?
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    The ASP.Net account may not have the required permissions to do this.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    13
    @<ABX: nothing at all... the registry seems to be written, but it is not "refreshed" cuz when i read strfile and strpath, they show me the new values. and when i open regedit i still see the old values in the registry. p.s: reboot doesnt work also.

    @hellswraith: the asp.net account already has full rights, also my assembly...

    thx so far,

    greetings

  5. #5
    Member
    Join Date
    Sep 2005
    Posts
    49

    Re: writing to registry with an assembly

    does the aspnet acct have full access on both reg and filesystem? It might be easier to test by adding the aspnet acct to the admin group...just a thought

  6. #6
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: writing to registry with an assembly

    Hellswraith is correct, the ASPNET account (default) will not have sufficient access to the registry as it will not be a local Administrator. You can instead change IIS to use the SYSTEM account which may have sufficient access rights
    Life is one big rock tune

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width