Reputation: 36080
I was trying to read some values from some registry keys with code (c#) on windows and I found out that the reason why I was not able to read the values was because the admin user did not had permissions:
So I manually navegated to the registry key that was giving me trouble and this is how the permissions tab looked like:
So that made me thought about how can I run a process as the user "system"? That sounds weird but apparently there is a system user right? I know how to run as administrator but maybe it is also possible to run as system.
here is my code. Basically I will like to traverse through all the registry keys:
class Program
{
// class to store reg key.
[Serializable]
[DebuggerDisplay("Name = {Name}, Val = {value}, type={type}")]
class MyRegKey
{
public string Name;
public object value;
public RegistryValueKind type;
public List<MyRegKey> SubKeys = new List<MyRegKey>();
public List<MyRegKey> Values = new List<MyRegKey>();
}
static MyRegKey root = new MyRegKey();
static void TraverseTree(RegistryKey key, MyRegKey temp)
{
foreach (var v in key.GetValueNames())
{
var kind = key.GetValueKind(v);
var value = key.GetValue(v, null);
var name = v;
temp.Values.Add(new MyRegKey { Name = name, value = value, type = kind });
}
var x = key.GetSubKeyNames();
for (var i = 0; i < x.Length; i++)
{
RegistryKey productKey;
productKey = key.OpenSubKey(x[i], false); // <--------- Code crashes here
if (productKey != null)
{
var y = new MyRegKey() { Name = productKey.Name };
temp.SubKeys.Add(y);
Foo(productKey, y);
}
}
}
public static void Main()
{
var key = Registry.LocalMachine;
root.Name = key.Name;
TraverseTree(key, root);
}
}
I am running that code as an administrator...
And here is an image of how my program crashes stating that I don't have permissions:
Upvotes: 2
Views: 5770
Reputation: 2180
PsExec -s
run remote process in the System account
C:\Windows\system32>psexec -i -d -s cmd
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd started on SERGMATCOMP with process ID 5356.
Output from the cmd with PID5356
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
nt authority\system
Upvotes: 2