473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Enabling / Disabling network card exception

Below is my code which enables and disables all network cards in my PC.

It works fine but when I execute this code on a normal User Account, i get the exception " Unable to read beyond the end of the stream" .

Im also aware that as a normal user, one will not be able to enable and disable network cards. I tried changing the settings in gpedit.msc bt it still doesnt work.

How do I grant permission to the user so that he wud b able to disable and enable the network card using the code below?

Expand|Select|Wrap|Line Numbers
  1.  Dim strComputer As String
  2.         Dim coladapters As Object
  3.         strComputer = "."
  4.         objWmiService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  5.         coladapters = objWmiService.Execquery("Select * from Win32_NetworkAdapter Where NetEnabled='false'")
  6.         For Each Adapter In coladapters
  7.             Adapter.enable()
  8.         Next
  9.  
  10.  
  11.  
Aug 2 '09 #1
5 7172
Plater
7,872 Expert 4TB
You might be able to change the user you use to get into the WMI calls.
(Is there a reason you are not using the .NET WMI implimentation for this?
Aug 5 '09 #2
ok im kinda lost.. i thought i was? lol

mind showing me how it'll be like if i were to use the .net wmi?
Aug 5 '09 #3
Plater
7,872 Expert 4TB
Def not. Take a look at the System.Management namespace. (You will have to add the assembly reference, it doesn't come added)

I threw this together from what I read on msdn:
Expand|Select|Wrap|Line Numbers
  1. Public Shared Function DoStuff() As Integer
  2.     Try
  3.         Dim classInstance As New ManagementObject("root\CIMV2","Win32_NetworkAdapter",Nothing)
  4.  
  5.         Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("Enable", Nothing, Nothing)
  6.         'Dim outParams As ManagementBaseObject = classInstance.InvokeMethod("Disable", Nothing, Nothing)
  7.  
  8.         ' List outParams
  9.         Console.WriteLine("Out parameters:")
  10.         Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))
  11.  
  12.     Catch err As ManagementException
  13.         MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message)
  14.     End Try
  15. End Function
  16.  
Aug 5 '09 #4
nice.. ill give tht a try. thx alot. yr help is much appreciated. =)
Aug 6 '09 #5
Plater
7,872 Expert 4TB
I also recommend the "WMI Code Creator" for fiddling with WMI. It has a little gui that creates the code for you, let you see how it all works.
Aug 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
0
by: Baihao Yuan | last post by:
Hello, I have a machine, which has two network cards, network card 1 and network card 2, they are on different subnetworks. The IP address of network card 1 is 192.0.0.1, the IP address of...
0
by: Dennis | last post by:
Can I enable or disable the network adapter using system.management classes? Thanks, Dennis
0
by: Alphamacaroon | last post by:
All, I'm wondering if anyone can help me with a strange problem I'm having. First off, here's what I'm trying to do: I'm developing a UDP network application that should allow the end user to...
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
4
by: Raj | last post by:
Hi, I have set of exposed web method (C#, framework). Now set of retailer uses these methods and they are identified by their retailer ids. Question is, Is there any way to disable a few...
1
by: pankajk | last post by:
Hai , will anyone tell me regarding how to disable and enable network interface card using JAVA programming on windows platform ........
2
by: Salad | last post by:
If I work on my app on my standalone, things are always fast. If I have an non-split app on the network it runs fast. If I split the app and have both the front end and backend on the network...
0
by: nancylife | last post by:
When developing web report, many developers use VMware to simulate different operating systems on a same server. Then, they can realize cross-platform deployment and debug of web report. According to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.