|
try something like this
WindowsPrincipal myPrincipal;
myPrincipal = (WindowsPrincipal) System.Threading.Thread.CurrentPrincipal;
WindowsIdentity myIdentity;
myIdentity = (WindowsIdentity)myPrincipal.Identity;
MessageBox.Show(myIdentity.Name);
|
|
|
|
|
I'm afraid I can't get it to work. The cast
(WindowsPrincipal) System.Threading.Thread.CurrentPrincipal generates an invalid-cast-exception, so I tried
string strUser=System.Threading.Thread.CurrentPrincipal.Identity.Name;
but the resulting string is empty. Have I missed something?
Thanks
/EnkelIk
|
|
|
|
|
I'm sorry, I didnt test the code, I just assumed it would work
You need to add this before the cast
AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
Regards,
Kannan
|
|
|
|
|
Thanks, that helped on the exception. Unfortunatelly the name returned is: NT AUTHORITY\LOCAL SERVICE
so back to where I started more or less...
/EnkelIk
|
|
|
|
|
This isn't a simple task.
The user physically sitting at the computer always uses the window station named WinSta0 . You can use the unmanaged APIs OpenWindowStation and GetUserObjectInformation with the UOI_USER_SID flag to get the user's security identifier or SID. You can then LookupAccountSid to discover the associated username.
|
|
|
|
|
Thanks.
That seems to be the way to do it. I implemented it as a separate module and my problem now is that it works fine when I run it from a normal exe, but not when I run it from the service -it's as if I can't even create an instance of the module class. Sigh.
Thanks
/EnkelIk
|
|
|
|
|
What is it supposed to return if there is no user logged on?
It is a windows service. No UI. If a user is logged on then
it returns the logged on user name. The Environment class
has a UserInteractive property.
Thank You
Bo Hunter
|
|
|
|
|
I'm not sure yet. If no user is logged on, it is supposed to return something (an empty string perhaps or a null reference) from which I can tell that no user is logged on. I'm working at a university and part of the idea with the service is to have it listening for calls from a program 'gathering' information on the computers and to be able to answer whether someone is logged on or not and then the calling program display the rooms where there are, say three or more, free computers on monitors placed on different locations on campus. The students will then be able to see where a free computer can be found.
/EnkelIk
|
|
|
|
|
I have two ListBox's ... listBox1, listBox2 ... I want to use the list boxs to obtain values from the "row" and "column" indices from an initialized multidimensional array. listBox1 will grab the "row" value, and listBox2 will grab the column value. I will display the data in a read-only text box... can anyone help me figure this out ???
Thanx ... total newbie to programming Windows .... I can do this in DOS ...
but I have no clue how to get the listbox to "tie-in" to my ..
double[,]DataArray = {{ values here },
{ " " },
{ " " },
{ " " }};
Chris R
|
|
|
|
|
Hi!
Please help me with this. I want to make a program that inherits
from two third party classes. (Let's just call it ClassA and ClassB)
I know I cannot do multiple inheritance so I need to use interface.
But I don't know how. Please help.
"To teach is to learn twice"
|
|
|
|
|
i found this site with excelent tutorials on c#
this is chapter 7 , that teach abstract classes & interfaces
http://www.programmersheaven.com/2/les_csharp_7_p1
|
|
|
|
|
I have already read that site. It doesn't answer my question.
Actually the problem here is that, the classes are THIRD PARTY CLASSES.
It already has existing methods that I need to use. Thanks anyway.
"To teach is to learn twice"
|
|
|
|
|
If the methods in the third party classes that you are interested in are public, then you do not need to use any inheritence, multiple or single. Simply use objects of these classes.
Otherwise if the methods are protected, then subclass both the third party classes, yourself, and add public methods in the subclasses, that use the protected methods of your interest. Then use your subclasses, instead of the original third party classes. This is kind of a hack.
In either case, you can avoid inheriting from those third party classes.
|
|
|
|
|
Use inheritance for one class and containment for the other:
class C : A
{
private B b;
public void SomeMethodInB()
{
b.SomeMethod();
}
public int SomeOtherMethodInB()
{
return b.SomeOtherMethod();
}
...
}
Regards,
Alvaro
Can I ask you a question?
|
|
|
|
|
i wanted to create a nice midi program in c# as my first app
i had little experience with directx so i downloaded this time the whole package including managed-directx, installed it and ...
i cant find direct-music in managed directx ???
maybe im missing something but i couldnt find midi support!
if im missing something or there is another api that has midi for c# please tell me, and is it planned to add directmusic to managed directx soon ?
|
|
|
|
|
AudioVideoPlayback is the what your probably looking for.
Greetings....
|
|
|
|
|
hmm , this is not good , its @#@*(#
this only let me play midi files, what i wanna do , is create a midi player with a piano control im writing to let me play midi notes in real time, any suggestions ?
|
|
|
|
|
I'm shocked: the line
dataAdapter.Fill(dataSet, dataTableName);
(a local MySQL connection, ODBC, 8k rows)
took more than 1 min to execute, it needs about 2 min to show the window
just I'm so unlucky ? or it is a known performance problem here?
can I do something to speed it up? (I HAVE to show all those lines)
Thanks
|
|
|
|
|
I know the problem, mysql and odbc have a speed penalty in the managed code... try to use microsoft desktop database engine instead of the mysql database. This one is fully supported and costs nothing
Greetings....
|
|
|
|
|
Are there classes in C# to parse the HTML pages and do some related activities .
Srikar Y
NITK Surathkal
|
|
|
|
|
|
COM+ and remoting
Hi, I'm trying to expose COM+ component via remoting, it works just fine - it seems. But I'm confused by how COM+/Remoting works together.
Remoting - lifetime depends on whether the object is published as SAO(singleton/singlecall), CAO and lifetime services.
In COM+, lifetime of server objects (COM+ application/component) depends on object pooling and whether JIT is enabled. My understanding is that if a COM+ app is published via remoting, than activation option must be "server". I am a little confused at how/what determines an object's life time in this situation.
For instance, how can you have SAO/Singlecall and COM+ Object Pooling at the same time?
Following are nine possible scenario:
COM+ JIT enabled/Pooling disabled + CAO
COM+ JIT enabled/Pooling enabled + CAO
COM+ JIT disabled/Pooling disabled + CAO
COM+ JIT enabled/Pooling disabled + SAO/Singlecall
COM+ JIT enabled/Pooling enabled + SAO/Singlecall
COM+ JIT disabled/Pooling disabled + SAO/Singlecall
COM+ JIT enabled/Pooling disabled + SAO/Singleton
COM+ JIT enabled/Pooling enabled + SAO/Singleton
COM+ JIT disabled/Pooling disabled + SAO/Singleton
Any idea? Thanks!
norm
|
|
|
|
|
I tried launching a GUI app from Windows Service by first launching another console app (launch.exe), which in turn launch the GUI app.
I have tried using:
a. WinExec (both unmanaged Win32 console app and PInvoke in C# console app)
b. CreateProcess
c. System.Diagonostic.Start() method
in "launch.exe", none avoided "TypeInitializationException" (Exception triggered when you tried to launch anything with a GUI from a Windows Service.)
Is there anyway to get around this?
norm
|
|
|
|
|
Even if there is a way to get around this, I do not think that you should be doing this.
A windows service may be up and running before any user logs-in into the system. What do you propose would happen to such a UI in this case? This is precisely the reason why you cannot start a UI from the service. The context that windows uses for windows services is not the interactive user context, which is the requirement for UI.
Try changing the achitecture of your application.
|
|
|
|
|
Hi
I am trying to develop a toolbar (for IE)to bring up the annotations on the page on the browser . When a section of the text is highlited on the browser then i need to return the parent ID of he item selected .By ID i mean that assuming that each of the html atags in the page are given an ID tag such that we have a tree structure .
for eg
thus
the question is having sucha page i need to write a function to return the id of the parent node(since we have a tree structure ) of the portion of the text selected . Can any one guide me to do it(Using C#) . Is there any other way to do it .
And what are the classes to parse the html page currently in he rowser . is this the WebBrowser class . Please let me know about any classes that might be useful for the purpose . I shall look into the docs .
Srikar Y
NITK Surathkal
Srikar Y
NITK Surathkal
|
|
|
|