views:

3172

answers:

17

Hello, I was testing on a customer's box this afternoon which has Windows Vista (He had home, but I am testing on a Business Edition with same results).

We make use of a .DLL that gets the Hardware ID of the computer. It's usage is very simple and the sample program I have created works. The Dll is This from AzSdk. In fact, this works perfectly under Windows XP. However, for some strange reason, inside our project (way bigger), we get this exception:

Exception Type:        System.DllNotFoundException
Exception Message:     Unable to load DLL 'HardwareID.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
Exception Target Site: GetHardwareID

I don't know what can be causing the problem, since I have full control over the folder. The project is a c#.net Windows Forms application and everything works fine, except the call for the external library.

I am declaring it like this: (note: it's not a COM library and it doesn't need to be registered).

[DllImport("HardwareID.dll")]
public static extern String GetHardwareID(bool HDD,
   bool NIC, bool CPU, bool BIOS, string sRegistrationCode);

And then the calling code is quite simple:

private void button1_Click(object sender, EventArgs e)

        {

            textBox1.Text = GetHardwareID(cb_HDD.Checked, 

                                               cb_NIC.Checked, 

                                               cb_CPU.Checked, 

                                               cb_BIOS.Checked, 

                                       "*Registration Code*");

        }

When you create a sample application, it works, but inside my prj it doesn't. Under XP works fine. Any ideas about what should I do in Vista to make this work? As I've said, the folder and its subfolders have Full Control for "Everybody".

Thanks in advance,

UPDATE: I do not have Vista SP 1 installed.

UPDATE 2: I have installed Vista SP1 and now, with UAC disabled, not even the simple sample works!!! :( Damn Vista.

A: 

Just a thought, have you tried running VS.NET on that machine "as administrator"?

xanadont
A: 

Is the machine you have the code deployed on a 64-bit machine? You could also be running into a DEP issue.

Edit

This is a 1st gen Macbook Pro with a 1st gen Core Duo 2 Intel processor. Far from 64 bits.

I mentioned 64 bit, because at low levels structs from 32 bit to 64 bit do not get properly handled. Since the machines aren't 64bit, then more than likely disabling DEP would be a good logical next step. Vista did get more secure than XP SP2.

Well, I've just turned DEP globally off to no avail. Same error.

Well, I also read that people were getting this error after updating a machine to Vista SP1. Do these Vista installs have SP1 on them?

Turns out to be something completely different. Just for the sake of testing, I've disabled de UAC (note: I was not getting any prompt).

Great, I was actually going to suggest that, but I figured you probably tried it already.

Dale Ragan
A: 

Actually, I haven't VS installed on that machine (yet). I use XP regularly. But since I detected this issue, I have just installed a Vista Business inside VMWare Fusion to perform some tests. Our application doesn't really need an installer so I simply copied it to the vista and ran it from there. As we speak I am copying all my Dev files (1gb of subversion folders) and I'm looking for the VS2005 DVD.

But if the VM could be a problem, I gotta mention that the customer had an new HP laptop with vista preinstalled, so this doesn't seem to be an issue of my Virtual Machine.

I haven't debugged the app yet (my fault) but the fact that this runs out of the box in XP and it fails under Vista made me thought that this is a vista issue and therefore it must be something I have to do.

In either case, I'm moving my develop environment over to Vista to be able to debug properly; despite that, the Exception Msg is quite clear on where the exception is happening (I have the source code, so I know where it is). Debugging will probably confirm what I already know, when I call the HardwareDLL method... an exception is thrown.

:S

As soon as I have VS installed and compiling (Vista is a little bit slower than XP) I will post back if there's new info.

Thanks.

Martín Marconcini
A: 

Dale,

I am not sure the HP laptop is 64bit (don't think so), but I know that my VMware is not 64-bit. This is a 1st gen Macbook Pro with a 1st gen Core Duo 2 Intel processor. Far from 64 bits ;)

However, I will now boot the Vista VM (as soon as my XP machine ends .Raring the /develop folder) to temporarily disable DEP. Thanks for the tip.

Martín Marconcini
A: 

Well, I've just turned DEP globally off to no avail. Same error.

I turned DEP off by issuing:

bcdedit.exe /set {current} nx AlwaysOff

At an "elevated" command prompt. (Run cmd.exe as an Administrator).

But I still get the same error. I'm decompressing the devel folder…

Martín Marconcini
A: 

Have you made a support request to the vendor? Perhaps there's something about the MacBook Pro hardware that prevents the product from working.

Curt Hagenlocher
A: 

Given that the exception is a DllNotFoundException, you might want to try checking the HardwareID.dll with Dependency Walker BEFORE installing any dev tools on the Vista install to see if there is in fact a dependency missing.

imaginaryboy
A: 

Well… Thanks for the Dependency Walker tip. I couldn't find anything interesting there. Actually, as I've mentioned, the simple sample works…

Turns out to be something completely different. Just for the sake of testing, I've disabled de UAC (note: I was not getting any prompt).

Voilá. After I disabled UAC. It all started to work again. What am I missing here?

My application wants to write a file, but I have FULL control of the folder. Is there any Attribute I have to use in my code to work with Vista? Am I missing something?

Martín Marconcini
A: 

Thanks for all the answers. It is the UAC prompt not being prompted for DLLs. Taken from google:

Privilege tokens are only assigned once for a process at start up, so the application invoking the dll needs to be elevated prior to making the calling to a dll that requires elevation. Vista applications simply cannot change elevation level at will once running, and hence why some applications might restart their process in order to elevate after initial launch (task manager).

So, unless my application runs "elevated" (why!?), then the "elevated privileges" I need to use the DLL are not available. A possible solution might be to use a manifest like described here, but I'm suspicious about that.

Martín Marconcini
A: 

In addition to allowing full control to "Everyone" does the location also allow processes with a medium integrity level to write?

imaginaryboy
A: 

In addition to allowing full control to "Everyone" does the location also allow processes with a medium integrity level to write?

How do I check that ? I am new to Vista, I don't like it too much, it's too slow inside a VM for daily work and for VStudio usage inside a Virtual Machine, it doesn't bring anything new.

Martín Marconcini
+1  A: 

Unable to load DLL 'HardwareID.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

The name of DllNotFoundException is confusing you - this isn't a problem with finding or loading the DLL file, the problem is that when the DLL is loaded, it does an illegal memory access which causes the loading process to fail.

Like another poster here, I think this is a DEP problem, and that your UAC, etc, changes have finally allowed you to disable DEP for this application.

Will Dean
A: 

Hi Martin

HardwareID.DLL is not a MS DLL it looks like a new dll from a company.

I suggest you check the version as there is a new version out http://www.azsdk.com/hardwareid.html

A: 

@littlegeek: I have the latest version (3.1.0.0) of the .DLL

@Will Dean: Yes, the name is confusing, but I know that the DLL is being found. It was working with UAC disabled, but after I left the SP1 installing overnight, this morning I found out that it wasn't working anymore. Apparently SP1 changed something. UAC is still disabled so is DEP. :(

UPDATE: Well I disabled DEP again (by executing the code mentioned below), made sure that UAC was disabled and restarted the box. It's now working again, but I'd like to know how to make it work with UAC enabled and DEP. :S I guess that there's nothing I can do since the DLL is not a ".net managed" dll.

Martín Marconcini
+2  A: 

@Martín

The reason you were not getting the UAC prompt is because UAC can only change how a process is started, once the process is running it must stay at the same elevation level. The UAC will prompt will happen if:

  • Vista thinks it's an installer (lots of rules here, the simplest one is if it's called "setup.exe"),
  • If it's flagged as "Run as Administrator" (you can edit this by changing the properties of the shortcut or the exe), or
  • If the exe contains a manifest requesting admin privileges.

The first two options are workarounds for 'legacy' applications that were around before UAC, the correct way to do it for new applications is to embed a manifest resource asking for the privileges that you need.

Some program, such as Process Explorer appear to elevate a running process (when you choose "Show details for all process" in the file menu in this case) but what they really do is start a new instance, and it's that new instance that gets elevated - not the one that was originally running. This is the recommend way of doing it if only some parts of your application need elevation (e.g. a special 'admin options' dialog).

Wilka
A: 

In addition to allowing full control to "Everyone" does the location also allow processes with a medium integrity level to write?

How do I check that ? I am new to Vista, I don't like it too much, it's too slow inside a VM for daily work and for VStudio usage inside a Virtual Machine, it doesn't bring anything new.

From a command prompt to you can execute:

icacls C:\Folder

If you see a line such as "Mandatory Label\High Mandatory Level" then the folder is only accessible to a high integrity process. If there is no such line then medium integrity processes can access it provided there are no other ACLs denying access (based on user for example).

EDIT: Forgot to mention you can use the /setintegritylevel switch to actually change the required integrity level for accessing the object.

imaginaryboy
+1  A: 

I found this question just a little bit ago, I thought you may be interested in it for your situation.

Dale Ragan