[RESOLVED] Problems with Win32_NetworkAdapterConfiguration in Vista
I have used the code on the following page in a program I wrote. WMI Tasks: Networking
It works fine in XP but when I tested the code in Vista it doesn't work. For example, the ReleaseDHCPLease function (shown below) returns error code 83 which is "Unable to Release". Every MSDN article I've read regarding this code and the other Win32_Network AdapterConfiguration functions says it works in Vista. What am I missing? :confused:
Code:
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")
For Each objNetCard In colNetCards
Debug.Print objNetCard.ReleaseDHCPLease
Next
Re: Problems with Win32_NetworkAdapterConfiguration in Vista
I've been troubleshooting this and I believe it does not work because the code is not running with elevated priviledges in Vista. I've been told to look at something called a manifest (which I have never heard of before now). My quick research on these manifests looks like they are for XP and that they are for making your application look like the XP theme/style. How could this make my program run with elevated priviledges in Vista?
Am I on the right track?
Re: Problems with Win32_NetworkAdapterConfiguration in Vista
This is an exeample of a manifest file that will request the elevation of permissions.
A manifest file can do many other things then just link the common controls for xp theming.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="EXENAME"
type="win32"/>
<description>elevate execution level</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Re: Problems with Win32_NetworkAdapterConfiguration in Vista
Okay. I've got this fixed. The problem is that Vista does require elevated admin priviledges to use the Win32_NetworkAdapterConfiguration calls but only the ones that make changes to your network settings; though it can read the network settings without the elevated priviledge.
Thanks to RobDog888's last post, I was able to solve this problem. So here is what I did.
First I copied RobDog888's manifest code above and pasted it into a file which I called myfile.exe.manifest.
Next I compiled by VB6 program and called it myfile.exe.
Then I downloaded MT.exe from Software Development Kit for Windows Vistaâ„¢ and .NET Framework 3.0 Runtime Components here. This was a huge install that took a long time just to simply get the MT.exe file.
Finally I moved all three files (the manifest, myfile.exe, and MT.exe) into the same folder and ran this command line,
Code:
mt -nologo -manifest myfile.exe.manifest -outputresource:myfile.exe;1
That embedded the manifest into my myfile.exe. Now each time I run myfile.exe, Vista asks me to elevate priviledges and all the Win32_NetworkAdapterConfiguration works. I also tested the new myfile.exe on XP and I found no problems there either.
Re: [RESOLVED] Problems with Win32_NetworkAdapterConfiguration in Vista
You can embed your manifest file into your vb 6 exe withoutusing the mt utility. There are other tricks you can use with resource files in VB 6 to embed the manifest file.