|
If you are using a BackgroundWorker , the RunWorkerCompleted event delegate has a RunWorkerCompletedEventArgs argument that contains a Result property. You can set this property with the value you wish to exchange and read it back from your main thread.
|
|
|
|
|
Hi,
I am trying to get some logged-on user details from a service running as LocalSystem.
After spending the weekend trying to find the best way of doing this, having found that the P/Invoke method is lengthy and arduous and that the get-owner-token-from-process method isn't suitable in this instance I am trying the following method but it won't compile giving non-useful errors.
The code:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
string LOU = (queryObj["UserName"].ToString());
WindowsIdentity wi = new WindowsIdentity(LOU);
WindowsImpersonationContext ctx = null;
ctx = wi.Impersonate();
WindowsPrincipal wp = new WindowsPrincipal(wi);
string LOU1 = wi.Name;
string AuthType = wi.AuthenticationType;
string Authd = wi.IsAuthenticated.ToString();
string isGuest = wi.IsGuest.ToString();
string SidNo = wi.Owner.ToString();
string SidPlain = wi.Owner.Translate(typeof(System.Security.Principal.NTAccount)).ToString();
string Token = wi.Token.ToString();
Console.WriteLine(LOU1);
Console.WriteLine(AuthType);
Console.WriteLine(Authd);
Console.WriteLine(isGuest);
Console.WriteLine(SidNo);
Console.WriteLine(SidPlain);
Console.WriteLine(Token);
foreach (System.Security.Principal.IdentityReference group in wi.Groups)
{
Console.WriteLine(group.Translate(typeof(System.Security.Principal.NTAccount)));
}
Can anyone shed some light on this please?
|
|
|
|
|
CCodeNewbie wrote: it won't compile giving non-useful errors.
They may appear non-useful to you, but unless you tell us what they are then it's difficult to help.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Errors are:
1) When deploying an office solution, check to make sure you have fulfilled all necessary security requirements"
- not deploying an office solution
2) Use a certificate to obtain the required permission/s
- haven't had to do this in other impersonations
3) If an assembly implementing the custom security object references other assemblies, add the reference assemblies to the full trust assembly list
- don't think this is accessing anything else as I am currently testing it as a standalone Console App running under the original user (i.e. not local system)
4) Get general help for this exception
|
|
|
|
|
It would be much more useful if you used copy and paste from the output of the compiler so we can see the actual lines of code that the compiler is complaining about.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi Richard,
The output fails after the first writeline with the pop-up box containing the list of errors in my previous post.
I have put the code into my service but now I am getting an error (catch exception sends the error to my eventlog)
"System.Security.SecurityException: Incorrect function.
at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
at Smith.Smith.OnTimedEvent(Object source, ElapsedEventArgs e)
The Zone of the assembly that failed was:
MyComputer"
I think the string from "string LOU = (queryObj["UserName"].ToString())" may not be the correct UPN although I am getting domain\username as the output.
Doing a bit of research now...
|
|
|
|
|
Those aren't compiler errors, they might be run-time exception messages. And either way, they normally also provide file, class and line number information which you should work on. Have you learned nothing in the months you were coding and asking questions here?
|
|
|
|
|
Hi Luc,
As mentioned in my post to Richard (believing that the errors were indeed of a run-time nature) I put the code back into the service which generated a more accurate description of what the cause of the error is - I think the error in the formatting of the UPN that is being passes to wi - the error is
UserInfo write failed for host 2. Reason System.Security.SecurityException: Incorrect function.
at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
at Smith.Smith.OnTimedEvent(Object source, ElapsedEventArgs e)
The Zone of the assembly that failed was:
MyComputer
from the line "WindowsIdentity wi = new WindowsIdentity(logonuser)"
string LOU = (queryObj["UserName"].ToString());
string[] LOUser = LOU.Split('\\');
string logonuser = (LOUser[1]+"@"+LOUser[0]);
WindowsIdentity wi = new WindowsIdentity(logonuser)
following the suggestions at http://forums.asp.net/p/1095241/1654338.aspx[^] and http://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx[^]
From the error I gather that it is a constructor error but as the constructor is legal (or at least compiles in the service if not in the Console APP.) I am stuck.
I am sorry if my ignorance disappoints you, quote " " unquote.
Yes, I am learning but as stated above, when the compiler/execution throws me a curve-ball I do struggle sometimes, especially when after multiple hours of research, trial-and-error and throwing code at the problem leaves me back where I started.
I do not develop code as a profession, I try and grab a few hours a week where time allows to try and develop an app that would help me and others in the job that I do.
Out of curiosity, which of my previous posts refers to the issues I am encountering above?
|
|
|
|
|
CCodeNewbie wrote: giving non-useful errors.
that is a non-useful statement.
When YOU don't understand a message, it means you MUST provide it in your post so others could provide detailed help.
BTW: your code compiles just fine, when put in a file; inside a namespace, class, and method; with the right usings and references added.
|
|
|
|
|
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
namespace MyProgram
{
class Program
{
static void Main(string[] args)
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
string LOU = (queryObj["UserName"].ToString());
Console.WriteLine(LOU);
Console.ReadLine();
WindowsIdentity wi = new WindowsIdentity(LOU);
WindowsImpersonationContext ctx = null;
ctx = wi.Impersonate();
WindowsPrincipal wp = new WindowsPrincipal(wi);
string AuthType = wi.AuthenticationType;
string Authd = wi.IsAuthenticated.ToString();
string isGuest = wi.IsGuest.ToString();
string SidNo = wi.Owner.ToString();
string SidPlain = wi.Owner.Translate(typeof(System.Security.Principal.NTAccount)).ToString();
string Token = wi.Token.ToString();
Console.WriteLine(AuthType);
Console.WriteLine(Authd);
Console.WriteLine(isGuest);
Console.WriteLine(SidNo);
Console.WriteLine(SidPlain);
Console.WriteLine(Token);
foreach (System.Security.Principal.IdentityReference group in wi.Groups)
{
Console.WriteLine(group.Translate(typeof(System.Security.Principal.NTAccount)));
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
I know there are a lot of non-required references listed but I have just copied and pasted from the service into the Console App. while testing the code. Am I missing one?
|
|
|
|
|
Hi there, I would like to convert an audio file into binary display (0000 1010 0001 1001 ..... ) and then to use in this display in my project in C#.
how can i do that ?
thank you, kfir.
|
|
|
|
|
That's not really a question we can answer.
You can read the audio file as binary - but that probably won't do what you want, as it will get the packaging, levels, and loads of other file related info which isn't the "pure sound".
You don't say how you want to display it (or why, either) so we can't help there either. Single "tone"? Changing as the sound plays? Or what?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I'm sorry, I will try to explain myself:
my goal is to "light up" virtual LED's on the screen.
when the volume is high 8 LED's and when it's low 1 LED.
how can i do it ?
Thank you.
|
|
|
|
|
Google for a VU-meter example? There's a CodeProject[^] article in the top results
Bastard Programmer from Hell
|
|
|
|
|
I think you need to find out how to plot the sound intensity instead of byte representation. You want a "stereo like" visual representation of the sound intensity preferably by frequency, correct?
I have never done it, but I would start like this:
1. What files am I using (wav, mp3, ogg, flac, ...)? Depending on the supported file types, search for the structure of that file bytewise on google.
2. Make sure you understand the file, there should be some way to identify the sounds' intensity (amplitude if it is a sine function).
3. Figure out how to map the time (location within the file) with a certain intensity.
4. Put two and two together. Should I mention you're working with a multi-threaded application?
Keywords: file structure, intensity/amplitude.
Hope this helps.
V.
|
|
|
|
|
I have written Symbian via C#.
i generate the project and get *.sis and *.sisx file and send to mobile and install it successfuly.
but when i wanna to run the installed program on my nokia it get this error:
Luncher not supported by runtime!
PLEASE HELP!
modified 26-Feb-12 10:24am.
|
|
|
|
|
That looks a lot like an add.
I'm gonna help by telling you to remove the link.
All the best,
Dan
|
|
|
|
|
What do u mean ?
I uploaded the project so u can run it and check the problem.
|
|
|
|
|
You have been with this site for two years, and you still haven't figured that people don't like to download unknown programs to "run it and check the problem"?
Tell me, do the phrases "Computer Virus" and "Trojan" mean anything to you?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
but how can i explain the problem?
I will Remove it !
|
|
|
|
|
Just post something like what you already have, then if necessary post the relevant piece of code
and tell were it goes wrong, maybe the exception(or what have you) details.
All the best,
Dan
|
|
|
|
|
HELP!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Shouting isn't going to help, especially as you are using an unsupported product. RedFiveLabs are no longer in business, and you really shouldn't be using C# to write applications for Symbian. You were told this.
|
|
|
|
|
hello every1, I have Copry CP-U858 joystick and I am trying to read data from it using Managed DX or SlimDX (not too good at it). I succeed almost, because I can read x and y values of moving joystick and all the buttons. However I cant read the Throttle level indicator data on the bottom and two more axis. The funny thing is that it finds these six axis but it cant read all these axis.
|
|
|
|
|
Mine is windows form application in C#. Application find some page on internet e.g. IE window. And then send some value to text of the IE page.
I have used below code for the same. But some how SendMessageTimeout function return nothing, without error.
private IHTMLDocument2 documentFromDOM()
{
Process[] processes = Process.GetProcessesByName("iexplore");
if (processes.Length > 0)
{
IntPtr hWnd = processes[0].MainWindowHandle;
int lngMsg = 0;
int lRes;
EnumProc proc = new EnumProc(EnumWindows);
EnumChildWindows(hWnd, proc, ref hWnd);
if (!hWnd.Equals(IntPtr.Zero))
{
lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT");
if (lngMsg != 0)
{
SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes);
if (!(bool)(lRes == 0))
{
int hr = ObjectFromLresult(lRes, ref IID_IHTMLDocument, 0, ref document);
if ((bool)(document == null))
{
MessageBox.Show("No IHTMLDocument Found!", "Warning");
}
}
}
}
}
return document;
}
Any help is welcome. Or if somebody has an C# example of SendMessageTimeout with IE window to retrieve IE HTML will be greatful.
|
|
|
|