2
Contributors
6
Replies
37
Views
3 Years
Discussion Span
Last Post by cgeier
0

The attached code is written in C#. This would probably be better placed in the C# forum.

0

The issue is that you need to run as administrator.

Add an Application Manifest File: (to "HW_Lib_Test")

  • Click "Project"
  • Select "Add New Item"
  • Select "Application Manifest File"
  • Click "Add"

Then (in app.manifest) change from:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

To:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

In "HardwareHelperLib" in "GetAll", add HWList.Sort();, because it is annoying to look through all the output if it is not sorted.

          ...
HWList.Add(DeviceName.ToString());
HWList.Sort(); //added
          ...

Then in "HardwareHelperLib", in "ChangeIt", you have the following:

catch (Exception ex)
{
   return false;
}

It is better to print out some sort of exception message or log the error message to a file (in my opinion).

Edited by cgeier

0

It works for me. You need to provide more details. Also, your xp is most likely 32-bit. What version of win 7 are you using? Check to see if you are compiling for x86 or any cpu.

0

bool rstl2 = Native.SetupDiCallClassInstaller(Native.DIF_PROPERTYCHANGE, hDevInfo, ptrToDevInfoData);
This line shows false in my system.
I am using win7 64 bit

Edited by swathi sajja

0

In addition to the above, in "HardwareHelperLib" change from:

DeviceInfoData.cbSize = 28;

To:

//for 32-bit, IntPtr.Size = 4
//for 64-bit, IntPtr.Size = 8
if (IntPtr.Size == 4)
{
    DeviceInfoData.cbSize = 28;
}//if
else if (IntPtr.Size == 8)
{
    DeviceInfoData.cbSize = 32;
}//if

Note: There are two occurrences of the above (one in "SetDeviceState", and another in "GetAll").

Also, ensure that you are compiling for "Any CPU".

Resources:

SP_DEVINFO_DATA (Structures)

...for 32 bit SP_DEVINFO_DATA.cbSize=28, for 64Bit SP_DEVINFO_DATA.cbSize=(28+4)=32...

How to know in run time if i'm on x86 or x64 mode in c#

...You can check whether IntPtr.Size is 4 or 8...

Edited by cgeier

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.