Torben.Busk
2009-08-17 12:08:01 UTC
Hi Forum.
I have written code to create a new power scheme on Windows Vista. After
duplicating an existing power scheme, I set the name and description of the
new scheme. This works fine on Vista, but not on Windows 7 (RTM).
The API call returns ERROR_SUCCESS, but the new scheme shows up in "Powercfg
-L" without a name.
Here's the code;
Dim ptrGuid As IntPtr
Dim ptrName As IntPtr
Dim BufferSize As UInt32 = 0
Dim res As UInt32 = 0
Try
ptrGuid = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
Marshal.StructureToPtr(inGuid, ptrGuid, True)
BufferSize = (Name.Length * 2) + 1
ptrName = Marshal.StringToBSTR(Name)
res = PowerWriteFriendlyName(IntPtr.Zero, ptrGuid, IntPtr.Zero,
IntPtr.Zero, ptrName, BufferSize)
If res = 0 Then
Return True
End If
Catch ex As Exception
Finally
Marshal.FreeHGlobal(ptrGuid)
Marshal.FreeBSTR(ptrName)
End Try
The code I use to set the description is almost identical (different API
call though) and works without problems on both Windows Vista and Windows 7.
Any help is appreciated.
/Torben Busk
I have written code to create a new power scheme on Windows Vista. After
duplicating an existing power scheme, I set the name and description of the
new scheme. This works fine on Vista, but not on Windows 7 (RTM).
The API call returns ERROR_SUCCESS, but the new scheme shows up in "Powercfg
-L" without a name.
Here's the code;
Dim ptrGuid As IntPtr
Dim ptrName As IntPtr
Dim BufferSize As UInt32 = 0
Dim res As UInt32 = 0
Try
ptrGuid = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
Marshal.StructureToPtr(inGuid, ptrGuid, True)
BufferSize = (Name.Length * 2) + 1
ptrName = Marshal.StringToBSTR(Name)
res = PowerWriteFriendlyName(IntPtr.Zero, ptrGuid, IntPtr.Zero,
IntPtr.Zero, ptrName, BufferSize)
If res = 0 Then
Return True
End If
Catch ex As Exception
Finally
Marshal.FreeHGlobal(ptrGuid)
Marshal.FreeBSTR(ptrName)
End Try
The code I use to set the description is almost identical (different API
call though) and works without problems on both Windows Vista and Windows 7.
Any help is appreciated.
/Torben Busk