|
My last post got me thinking and I did some retesting of our code.
It seems the EventLogPermission.Assert makes no difference. We got lucky because most times the source got created by a Service we are running under a the SYSTEM account. The rest of the time everything was falling into the "Application Error" catch. This gives a bit of a messy message but at least you get one. We hope to have very few errors, if any, to log, but that is living in hope.
In search of a better solution I did some tests and everything runs afoul of the Operating System ACL's with no way round it.
I have thought of two possible solutions that I will be trying.
1) Run a separate Windows Service just to log errors under the SYSTEM account.
2) Impersonate the SYSTEM account in code.
This second option I have managed to use with a hard coded username and password, which isn't much use for a wider deployment, but may be a step in the right direction.
Public Overloads Shared Sub WriteMessage(ByVal message As String, ByVal source As String, ByVal log As String)
Dim password As String = "****"
Dim username As String = "****"
Dim tokenHandle As IntPtr = IntPtr.Zero
Dim returnValue As Boolean = LogonUser(username, System.Environment.MachineName, password, 2, 0, tokenHandle)
Dim impersonatedUser As WindowsImpersonationContext = WindowsIdentity.Impersonate(tokenHandle)
Try
CustomEventLog.InternalWriteMessage(message, source, log)
Catch ex As PlatformNotSupportedException
End Try
impersonatedUser.Undo()
End Sub
Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Bother.
You can only impersonate if you have impersonation privileges as per the article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure03132003.asp[^]. This says that the ability to impersonate is only granted to accounts with the Service SID (Network Service, Local Service, and Local System) and Administrators.
If you are one of those you can write to the registry anyway so no point in impersonation!
So we are back to making use of an existing source, or creating your own source in the installer package.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
I received notification on your original response with the code samples via e-mail, but after that message I was not notified and didn't see the additional info you posted... Sorry.
I did however plan to follow-up with what we found:
1) Security is the hitch when a standard client tries to write to the registry. The app searches for the eventsource and when it cannot find it, tries to create one. Due to the rights, it fails and causes our error.
2) We have a class that we wrote for use in our shop, which can be referenced in any program, and if called, can display a message box, write to the eventlog and e-mail, depending what parameters are set. We took a sample of the code you posted and we check if the event source is there. If not, we try to create the event source. If the create fails we notify the client that they need to call us and run a process we call DeployEventSource.
3) We wrote an app (DeployEventSource) which creates the eventsource and is basically setup to be installed by our team with admin or power user rights. We wanted to try to to eliminate as much maintenance as possible and I believe we accomplished this goal. Since our class above writes to a source name that we keep consistent, and our install / create source program creates a source with the same name, we only have to run the install app when someone gets a new machine or system reload. If profiles change with terminations / new hires, we do not have to keep reinstalling or hacking a registry setting. Also we can create several apps that run on this pc which uses our class to write to the eventlog, and as long as the eventsource was created once, it will work for all apps.
You pointed us in the right direction and I really appreciate all your help and continued testing.
Thanks again!!
KreativeKai
Lost in the vast sea of .NET
|
|
|
|
|
Hi people!
I'm using OleDbDataReader to get rows one-by-one from Excel sheet. The
code I'm using to do this:
oConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + name +
";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"");
oConn.Open();
OleDbCommand oCmd = new OleDbCommand("SELECT * FROM [Sheet1$]",
oConn);
OleDbDataReader oReader = oCmd.ExecuteReader();
while (oReader.Read())
{
//array to store current row
object[] rowValues = new object[oReader.FieldCount];
oReader.GetValues(rowValues);
.....
}
Parameter TypeGuessRow=0. So the problem I'm getting is: values from
column with mixed types is imported with loosing their precision! For
example I have column with values {'9133.13', '87654321', '586472.12',
'a.27'}. First value imported correctly, second and third - are not.
For second I got 8.76543e+007 and for third I got 586472. Fourth value
is also correct. Firstly these cells has "Currency" format, but after
it was changed by user to "Text" without reentering values to the
cells. After this changes my problem had arised. May someone knows how
to fix it - any comments/advices/links appreciated.
|
|
|
|
|
Hi,
I've implemented global mouse and keyboard hooks in C#, however, once I set the hook type to WH_CBT and run the application, an ugly black command prompt screen prompts out saying there was an error in CLR at runtime
Has anybody been able to implement system-wide CBT hooks in any .NET language?
If I keep getting stuck in this, can I make a c++ DLL that does all the hooking and use it in my C#/VB.NET app?
Thanks
|
|
|
|
|
I have a web service client that is written in VC++.net and needs to connect to different application servers(dev, test, and production).
When this application starts a user is presented with a dialog box asking for their username and password. I also need to add the server to this dialog box.
I have created the call to the web service, using the "Add Web Reference" wizard and browsing to the WSDL document. Is there any way at runtime to have the client choose which server to connect to?
Josh Angolano
|
|
|
|
|
Does anyne know how to connecto to Lotus notes using asp.net or a data provider to do that.
thanks.
.]
|
|
|
|
|
|
Thanks Kevin I really apreciate your help baut that object is only freeware for 30 days, don't you know something that is free.
|
|
|
|
|
No, I don't. Can you follow the same principles and use the OleDb provider?
Kevin
|
|
|
|
|
Do you know where can i see how to do that.
Thanks for your time.
|
|
|
|
|
I'm not familiar with Lotus Notes, I just did a Google search for Lotus Notes Data Provider. I assume you could copy the example they have there and replace the provider with the .NET OleDbProvider. But maybe it's not as simple as that? Have you tried a Lotus Notes discussion forum?
Kevin
|
|
|
|
|
Can I ask for some advice.
I am currently running Visual Studio 2002 (7.0) and have noticed that Microsoft are giving away Visual C++ Toolkit 2003.
I was trying to use mySQL++ API, but I need to upgrade to VS2003 (7.1).
So my question can I downoad this toolkit and build a VS 7.1 project?
I have looked at the documentation and I am a bit confused?
i.e. how does the VS IDE fit into this Visual C++ Toolkit 2003.
|
|
|
|
|
I'm creating two version of a program: A free version (myprogram) and an enhanced version (myprogram_PRO). The source code has to be released with the free version since it will be open source. Is there some way to have both programs in the same project? I can create two projects but if I make a change to one version then I have to be sure to update the other. If I have to add a dialog, for example, then it is not a simple matter to make everything match between the two. Any suggestions?
Using .Net
Jack
|
|
|
|
|
Hi Jack,
this is interesting problem. Two versions of same app is usually handled by #ifdef and things like that. Anyway, it doesn't help with open source. It could be good idea to make a tool which will remove "pro" code. I wish I had time... I think it can be useful tool. Is anything like that already done? Try google...
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
I think it may be already set up to be done with .Net but I can't figure it out. I usually just add a project and go at it. This is the first time I needed something more involved. I set up a test project and added two different projects to it (the solution they call it). That would at least make copying from one file to another easier. But when I tried it on my main project, it won't let me do it since they have the same internal names. Supposedly, you can just click on Rename to have .Net rename the project but that didn't work. Although it wouldn't surprise me to find I am doing it wrong. If anyone knows how to rename a project with .Net I would appreciate the help.
Jack
|
|
|
|
|
|
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
I think something can be accomplished with a good source control system. They have a feature called Branching, so that you can keep the separate source for two versions of your project.
Say you have version 1.0 final, and then you start working on 2.0. If you find a big bug in 1.0, you fix it and release 1.0a. So you create a branch for updating 1.x code, while working on 2.0 (both based on 1.0) and you can merge branches, so 1.x modifications are merged into 2.0 code.
Well, it's something like that.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
You could have all your Pro functionality contained in a dll that acts as a plugin to the free version
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Thanks for your and Luis' suggestions. They both sound like soultions to the problem and I will look into them.
Jack
|
|
|
|
|
You may have bigger problems depending on the licence you use.
For example if you licence the free version using the GNU licence [^]then you also have to distribute your PRO version under the GNU licence and provide the full source code as it is using code from your free version.
If you use the BSD licence [^]you can just make sure you include the same copyright info in both versions.
|
|
|
|
|
Hmm, Thanks for mentioning this - I wasn't aware of it. I'm not sure if the BSD license is acceptable by the place I am submitting it to. In the event it is not, is it OK to have the free version, say "MyProgram," and then a non-free version but call it "My Other Program." And then mention in the description for My Other Program that it does everything My Program does and more. How do others get around this? I see free and non-free versions all of the time on various web sites.
Jack
|
|
|
|
|
It was something I came across with the GNU license, which many people use for open source development. Where I work we had our own license drawn up by experts which covers our particular oddities. Writing your own license does solve the problem as you can say whatever you want. I have come across a number of forum posts recently that advocate the BSD license over the GNU license. For my own free stuff I just put in a "use this at your own risk" disclaimer. That way I can use it at my own risk in a non-free version and license that completely differently. The issue is more to do with making your source code available, or not, than anything else.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
I want to write a small utility for changing the speed of playing of a wave file, i will have to change the header information or what ???... need suggestions !.
|
|
|
|