PDA

Click to See Complete Forum and Search --> : writing to registry with an assembly


PJ6
Nov 5th, 2003, 01:41 AM
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:




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

<ABX
Nov 5th, 2003, 12:11 PM
where does it fail?

Is it on the registry access bit or the file writing?

hellswraith
Nov 5th, 2003, 11:47 PM
The ASP.Net account may not have the required permissions to do this.

PJ6
Nov 6th, 2003, 02:29 AM
@<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

wrecklesswun
Oct 5th, 2006, 12:46 AM
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

Valleysboy1978
Oct 5th, 2006, 04:33 AM
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 :thumb: