Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Attempting to disable networking on a WM5 device

4 views
Skip to first unread message

Marc Oden

unread,
Nov 4, 2009, 8:31:40 AM11/4/09
to
I am trying to find a way to disable networking on a WM5 device. I found a
code sample at
http://devwince.blogspot.com/2008/09/controlling-ethernet-adapter-using.html
that seems to do this. However, when I implement it I have found that the
CreateFile function:

hNdisPwr = CreateFile((PTCHAR)NDISPWR_DEVICE_NAME,
0x00,0x00,NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
(HANDLE)INVALID_HANDLE_VALUE);

returns INVALID_HANDLE_VALUE. Calling GetLastError returns 6.

Any help would be appreciated.

r_z_...@pen_fact.com

unread,
Nov 4, 2009, 4:32:54 PM11/4/09
to
On Wed, 4 Nov 2009 07:31:40 -0600, "Marc Oden" <mo...@avioninc.com>
wrote:

>I am trying to find a way to disable networking on a WM5 device. I found a
>code sample at
>http://devwince.blogspot.com/2008/09/controlling-ethernet-adapter-using.html
>that seems to do this. However, when I implement it I have found that the
>CreateFile function:
>
>hNdisPwr = CreateFile((PTCHAR)NDISPWR_DEVICE_NAME,

I don't recognize NDISPWR_DEVICE_NAME and you didn't include a
definition. But my hunch is that it's char, so you used a cast to
eliminate the compiler error. That won't work. More specifically, you
need to declare a WCHAR array, use MultibyteToWideChar to convert, and
then pass the WCHAR array. If I'm right, then the more general issue
is that you really need to take time to understand UNICODE, or you'll
waste a lot of your time tracking down odd errors like this.


> 0x00,0x00,

Why 0x00 rather than 0? They evaluate to the same value, so it makes
no real difference. But I, at least, found 0x00 distracting.


NULL,
> OPEN_EXISTING,
> FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,

I'm pretty sure FILE_FLAG_OVERLAPPED is not supported for Windows CE,
and thus platforms (like Windows Mobile) based on it. Check your
documentation for the function.


> (HANDLE)INVALID_HANDLE_VALUE);
>
>returns INVALID_HANDLE_VALUE. Calling GetLastError returns 6.
>
>Any help would be appreciated.
>
>

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com

Paul G. Tobey [ eMVP ]

unread,
Nov 4, 2009, 5:05:03 PM11/4/09
to
Error 6 seems a little strange. Do you actually have any network devices?
If there are no active network devices, it's possible that the driver doesn't
load. You can see if the power driver is present by looking in the device
registry branch HKEY_LOCAL_MACHINE\Drivers\Active for an entry with the
device name you're trying to open.

Paul T.

Marc Oden

unread,
Nov 5, 2009, 1:16:02 PM11/5/09
to
Thank for your replies. I found that the
[HKLM\Comm\NdisPower\<Adapter_Name>] registry structure does not exist on my
development device, so I doubt this method of disabling networking will work
in my case. I modified the code the code to interate through all the NDIS
devices on the mobile device using the following functions:

hNdis = ::CreateFile(DD_NDIS_DEVICE_NAME, GENERIC_READ
|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,0,
(HANDLE)INVALID_HANDLE_VALUE);

BOOL ret = DeviceIoControl(hNdis, IOCTL_NDIS_GET_ADAPTER_NAMES, NULL, 0,
pvNameBuf, sizeof(Buffer), &dwRet ,NULL);

I was then able to disable the devices using the DeviceIoControl and
SetDevicePower functions.


"Marc Oden" <mo...@avioninc.com> wrote in message
news:0EA24C7C-03A2-45E9...@microsoft.com...

0 new messages