SetupDiRemoveDevice fails only on Vista with Invalid Handle,...

Posted: 11-01-2008, 08:01 AM
Hi,

i have some interessting Situation here. I started to port my Application
to Windows Vista32/64 and i have some strange Situation there: On Windows
2000 and XP based System the call to SetupDiRemoveDevice(....) works just
fine, but on Windows Vista based System i get a INVALID_HANDLE Error
and the call fails. What i want to know is, to wich part this Error Code
belongs and
to what Parameter. The First Parameter is a handle to a device information
set
and the second is a pointer to SP_DEVINFO_DATA structure. Both Information
"seems" to be valid, since it hold data and no NULL or Zero Info or
something
weird. Since the first parameter is a handle, at first you will think:"Ok
thats it,
backtrack the variable", but the second pointer to SP_DEVINFO_DATA holds
a so called "opaque handle (DWORD)", a handle to a device instance. So which
one is invalid? Is there a simple way to check this, to check which one is
invalid?

The Application asks (while starting) for Elevation and accepts only a
"real"
administrator and wont start another way. So this is excluded. Addtionally
it
enables all possible privileges the User Token has, so this is also
excluded.

Maybe important to know is that the application calls everything from the
..NET
PInvoke Layer, but i had no problems so far,...it started on Vista (like
many many
other problems solved so far). The first thing that comes to mind is that
some sort
of security restriction breaks my design, but i think i would get a
ACCESS_DENIED or
something like YOU_ARE_NOT_ALLOWED_TO_USE_THIS_ERROR_CODE. Its just
a INVALID_HANDLE,...

Any help would be really great!

Regards

Kerem

--
--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

Reply With Quote

Responses to "SetupDiRemoveDevice fails only on Vista with Invalid Handle,..."

Maxim S. Shatskih
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-01-2008, 10:16 PM
> Maybe important to know is that the application calls everything from the
> .NET
> PInvoke Layer
..NET is evil. :-)

Try writing a tiny command-line app in unmanaged C which will do the same.

--
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

Reply With Quote
Kerem Gümrükcü
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 05:29 AM
Hi Maxim,
>.NET is evil. :-)
I dont know, but why none here likes .NET? .NET is not
evil, its just fine,...as long as you dont need any assembly
involved. One restriction of the application i am working
on is, that it is not allowed to have any external stuff, it
just has to be one big binary. So "tiny" console or "one
shot" binaries are not allowed.

Why does the application work on Windows 2000 and
XP, but fails on Windows Vista? Do you have any suggestions.
To be honest, i dont think thats an .NET (Layer) issue here,
since it work on prior windows version just fine!

Any ideas,...?

Regards

Kerem


"Maxim S. Shatskih" <maxim@storagecraft.com.no.spam> schrieb im Newsbeitrag
news:ubtjPcGPJHA.728@TK2MSFTNGP05.phx.gbl...
>> Maybe important to know is that the application calls everything from the
>> .NET
>> PInvoke Layer
>
> .NET is evil. :-)
>
> Try writing a tiny command-line app in unmanaged C which will do the same.
>
> --
> Maxim S. Shatskih
> Windows DDK MVP
> maxim@storagecraft.com
> http://www.storagecraft.com
>
Reply With Quote
Kerem Gümrükcü
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 06:25 AM
Well,

i finally found it and it was not what i expected. A colleague wrote
some parts of the application, some classes plain to speak and he
was using some undocumented functions including the
SetupDiGetClassDevsEx(...)
which is undocumented i found. Switching to the SetupDiGetClassDevs(...)
made
everything just work fine.

But SetupDiGetClassDevsEx(...) works on W2K and XP just fine, but fails
with a INVALID_HANDLE_VALUE on Windows Vista. But now it has been
solved. Maybe they changed internals,...obvious they did,...

Thats why i always "try to avoid undocumented stuff,....!

BTW:

Is CM_Uninstall_DevNode(Ex)(...) the same as SetupDiRemoveDevice(...)?
Do you know anything,...?

Regards

Kerem

Reply With Quote
Alexander Grigoriev
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 03:06 PM
What was MachineName argument of ClassDevsEx?

"Kerem Gümrükcü" <kareem114@hotmail.com> wrote in message
news:ei25NPLPJHA.2312@TK2MSFTNGP03.phx.gbl...
> Well,
>
> i finally found it and it was not what i expected. A colleague wrote
> some parts of the application, some classes plain to speak and he
> was using some undocumented functions including the
> SetupDiGetClassDevsEx(...)
> which is undocumented i found. Switching to the SetupDiGetClassDevs(...)
> made
> everything just work fine.
>
> But SetupDiGetClassDevsEx(...) works on W2K and XP just fine, but fails
> with a INVALID_HANDLE_VALUE on Windows Vista. But now it has been
> solved. Maybe they changed internals,...obvious they did,...
>
> Thats why i always "try to avoid undocumented stuff,....!
>
> BTW:
>
> Is CM_Uninstall_DevNode(Ex)(...) the same as SetupDiRemoveDevice(...)?
> Do you know anything,...?
>
> Regards
>
> Kerem

Reply With Quote
Kerem Gümrükcü
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 05:26 PM
Hi,
>What was MachineName argument of ClassDevsEx?
It was something like "\\MACHINAME". I know these
backslasches are sometimes really necesssary. But the
function did not return any error codes, thas the strange
thing here!

Regards

Kerem


Reply With Quote
Stefan Kuhr
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 07:00 PM
Kerem,

Kerem Gümrükcü wrote:
> Well,
>
> i finally found it and it was not what i expected. A colleague wrote
> some parts of the application, some classes plain to speak and he
> was using some undocumented functions including the
> SetupDiGetClassDevsEx(...)
> which is undocumented i found.
Nope, SetupDiGetClassDevsEx is documented. IIRC I used it already at W2K
times.

--
Stefan
Reply With Quote
Alexander Grigoriev
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 08:20 PM
Did you actually need to call this function for a specific machine? Or it
was always a current machine?

"Kerem Gümrükcü" <kareem114@hotmail.com> wrote in message
news:%23FmcrARPJHA.2312@TK2MSFTNGP03.phx.gbl...
> Hi,
>
>>What was MachineName argument of ClassDevsEx?
>
> It was something like "\\MACHINAME". I know these backslasches are
> sometimes really necesssary. But the
> function did not return any error codes, thas the strange
> thing here!
>
> Regards
>
> Kerem
>
>

Reply With Quote
Kerem Gümrükcü
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-02-2008, 08:29 PM
Well,

the application mostly uses the Ex-Variants of the Functions
for future remote usage,...

Regards

Kerem

"Alexander Grigoriev" <alegr@earthlink.net> schrieb im Newsbeitrag
news:ezydvhSPJHA.4708@TK2MSFTNGP06.phx.gbl...
> Did you actually need to call this function for a specific machine? Or it
> was always a current machine?
>
> "Kerem Gümrükcü" <kareem114@hotmail.com> wrote in message
> news:%23FmcrARPJHA.2312@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>>>What was MachineName argument of ClassDevsEx?
>>
>> It was something like "\\MACHINAME". I know these backslasches are
>> sometimes really necesssary. But the
>> function did not return any error codes, thas the strange
>> thing here!
>>
>> Regards
>>
>> Kerem
>>
>>
>
>
Reply With Quote
Maxim S. Shatskih
Guest
Posts: n/a
 
Re: SetupDiRemoveDevice fails only on Vista with Invalid Handle,...
Posted: 11-03-2008, 07:46 AM
> involved. One restriction of the application i am working
> on is, that it is not allowed to have any external stuff, it
> just has to be one big binary
Yet another evil and silly requirement. Add a native unmanaged DLL there, which will wrap around the non-.NET friendly SetupDi stuff.

--
Maxim S. Shatskih
Windows DDK MVP
maxim@storagecraft.com
http://www.storagecraft.com

Reply With Quote
 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid handle ebI Windows Vista Performance & Maintenance 1 05-03-2008 05:59 AM
Invalid HANDLE was specified Eagle Windows XP Accessibility 2 12-24-2004 02:45 AM
Invalid Handle Specified Mrs. T Windows XP Performance & Maintenance 1 01-25-2004 07:15 AM
The Handle is Invalid Rick Windows XP Security & Administration 5 01-06-2004 02:36 AM
Invalid handle brazero Windows XP Printers / Scanners / Fax 0 10-25-2003 02:35 PM