Access Rights Linqpad
Options
Hi everyone,
I have a simple question. The following code runs in LINQPad without admin rights. If I start the same code from a simple console application I get access rights exceptions.
Any hint?
I have a simple question. The following code runs in LINQPad without admin rights. If I start the same code from a simple console application I get access rights exceptions.
Any hint?
void Main()
{
var processList = Process.GetProcesses();
foreach(var process in processList)
try
{
GetCommandLine(process).Dump();
Console.WriteLine();
}
catch (Win32Exception ex)
{
if ((uint)ex.ErrorCode != 0x80004005)
{
throw;
}
}
}
// Define other methods and classes here
private static string GetCommandLine(Process process)
{
var commandLine = new StringBuilder(process.MainModule.FileName + " ");
using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
{
foreach (var @object in searcher.Get())
{
commandLine.Append(@object["CommandLine"] + " ");
}
}
return commandLine.ToString();
}
Comments
-
It works OK for me from a Console App. Are you sure the error is related to needing admin rights?
-
If you set the uac (user access control) to the second entry. Than it doesn't work on my machine. I found out, that 'process.MainModule.File' is not working.
Thank you, for your answer. -
I found it.
The code in Linqpad is just a snippet of the code in the console app.
The console app was build of the program and an assembly and the above code was call from this assembly internally. That causes the problem for some reason. If I call the 'GetCommandLine' code from the program direct instead letting the dll call it's own code - all works well.
Maybe a dll cannot have access to the data of another process - but why the program can do this? -
Oh, I even found that!
I forgot the try / except iterating the processlist.