Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Visual Studio run Tests with a less privileged process?

I have an application that is supposed to read from the Registry and when executing a console application my registry access works perfectly.

However when I move it over to a test this returns null:

var masterKey = Registry.LocalMachine.OpenSubKey("path_to_my_key");

So my question is:

Does Visual Studio run Tests with a less privileged process?

I tested to see what user this gave me: var x = WindowsIdentity.GetCurrent().Name; and it gives me the same as in the console application. So I am a bit confused here.

I am using MS Test Framework and the machine is Windows 2003 64 Bit.

like image 223
Filip Ekberg Avatar asked May 07 '10 07:05

Filip Ekberg


People also ask

How do I run a test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

Does Visual Studio Professional Support coded UI?

Visual Studio 2019 is the last version to provide test creation via the recorder. Only basic minimal support for Coded UI Test is available in Visual Studio 2022.

Is Visual Studio a testing tool?

Visual Studio testing tools can help you and your team develop and sustain high standards of code excellence. Unit testing is available in all editions of Visual Studio. Other testing tools, such as Live Unit Testing and IntelliTest, are only available in Visual Studio Enterprise edition.


1 Answers

It is not a security issue. It's the fact that you are running on a 64-bit operating system. 64-bit apps have a different view of HKLM\Software than 32-bit apps. 64-bit apps get the "normal" view, 32-bit apps are redirected to HKLM\Software\Wow6432Node. The EXE determines the bit-ness of the process, it will be different when mstest runs the code. 32-bit, probably.

You'll need to create the key you are trying to read in the Wow6432Node tree. Or make the regular app have the same bit-ness, Project + Properties, Build tab, Platform Target = x86. Also changeable on-the-fly with Corflags.exe.

like image 178
Hans Passant Avatar answered Sep 27 '22 16:09

Hans Passant