Access Rights Linqpad
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
Thank you, for your answer.
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?
I forgot the try / except iterating the processlist.