|
I need to code where I can change the IP address to a static IP address and then to DHCP based on users choice.
Any code in VB.NET to do this?
The DOS command is
netsh interface ip set address local static 192.168.1.99 255.255.255.0
and
netsh interface ip set address local dhcp
TIA
|
|
|
|
|
You can run console commands via the Diagnostics.Process[^] class.
Dim arguments As String = "interface ip set address local static 192.168.1.99 255.255.255.0"
System.Diagnostics.Process.Start("netsh", arguments)
|
|
|
|
|
following code uses system.management classes(WMI)
CODE TO SET STATIC IP:
Sub IPchange()
Try
Dim inPar, outPar As ManagementBaseObject
Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo As ManagementObject In moc
If DirectCast(mo("IPEnabled"), Boolean) Then
inPar = mo.GetMethodParameters("EnableStatic")
inPar("IPAddress") = New String() {txtIP.Text}
inPar("SubnetMask") = New String() {txtSubnet.Text}
outPar = mo.InvokeMethod("EnableStatic", inPar, Nothing)
flag = True
MsgBox("IP Address successfully changed!!!", MsgBoxStyle.Information, "IP Changed")
Exit For
End If
Next
Catch ex As Exception
MsgBox("Error:" & ex.Message, MsgBoxStyle.Critical, "Error")
txtIP.Enabled = True
txtSubnet.Enabled = True
flag = False
End Try
CODE TO SET DHCP
Try
Dim t As Single
Dim objWMIService, objComputer As Object
objWMIService = GetObject("Winmgmts:root\cimv2")
objComputer = objWMIService.InstancesOf("Win32_NetworkAdapterConfiguration")
' Call always gets only one Win32_ComputerSystem object.
For Each objComputer In objWMIService.InstancesOf("Win32_NetworkAdapterConfiguration")
t = objComputer.EnableDHCP()
If t <> 0 Then
'MsgBox("Error!!! Cann't enable DHCP at this time.", MsgBoxStyle.Critical, "Error")
Else
MsgBox("DHCP Enabled!!!", MsgBoxStyle.Information, "Enable DHCP")
End If
Next
Catch ex As Exception
End Try
BYE!
Lxcite's Planet
... the ultimate solution
|
|
|
|
|
Thanks for the response and the code. All I can say is wow! I need more books on this stuff to catch up. Going through the IPchange() I get ManagementObjectCollection is not defined and the same for ManagementObject. I also get flag is not declared.
Where is it actually changing the IP address?
|
|
|
|
|
|
sell
netsh -f d:\ipchange\working.txt
pushd interface
reset all
popd
pushd interface ipv6
uninstall
popd
pushd interface ipv6 isatap
popd
pushd interface ipv6 6to4
reset
popd
pushd interface portproxy
reset
popd
pushd interface ip
set address name="本地连接" source=static addr=132.110.77.116 mask=255.255.255.0
set address name="本地连接" gateway=132.110.77.1 gwmetric=0
set dns name="本地连接" source=static addr=202.96.128.68 register=PRIMARY
set wins name="本地连接" source=static addr=10.16.6.88
popd
asfd
|
|
|
|
|
is this?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi all!
How can i lock Ctrl+Alt+Del Keys (do not show task manager) ? And how can i hide my desktop screen (such as screensaver) by my program ? Thanks!
|
|
|
|
|
groupitvn wrote: How can i lock Ctrl+Alt+Del Keys (do not show task manager) ?
You can't.
And how can i hide my desktop screen (such as screensaver) by my program ?
What do you mean? Do you want to keep the screen saver from starting? Or whatever you want to hide, what do you want to show instead?
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: You can't.
Actually, you can.
See: http://www.codeproject.com/win32/AntonioWinLock.asp[^]
Ctrl+Alt+Del
There are several ways to disable this key combination:
1. Disable Task Manager. This doesn't trap the key combination, it simply disables the application (Task Manager) that pops up when this key combination is pressed. See below how to do this.
2. Trap the keys using a keyboard device driver. For this, you need the DDK installed. I will not describe this method here.
3. Write a GINA stub. GINA is the DLL that Winlogon uses to perform user authentication. I'm not going to discuss this method here, but you can find out how to do it here [16].
4. Subclass the SAS window of the Winlogon process. For this, you must inject code into the Winlogon process and then subclass its Window Procedure. Two techniques for doing this are described later.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
I stand corrected. I truly believed that this wasn't possible, for security reasons.
---
b { font-weight: normal; }
|
|
|
|
|
Oh come on!! In Guffa's defense, there is no REASONABLE way to do it.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: there is no REASONABLE way to do it
Disabling Ctrl+alt+Del is unreasonable, sure. But changing a single registry setting so that the task manager cannot come up is quite simple.
Original Question: How can i lock Ctrl+Alt+Del Keys (do not show task manager) ?
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr
But hey, I'm still a freshman compared to you and Guffa - so forgive me if I take every opportunity to correct my superiors.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
EricDV wrote: Disabling Ctrl+alt+Del is unreasonable, sure. But changing a single registry setting so that the task manager cannot come up is quite simple.
I was just commenting on disabling Ctrl-Alt-Del, nothing more.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: I was just commenting on disabling Ctrl-Alt-Del, nothing more.
:->
I understand. I'm new to the developer forums, so I'm just figuring out how things work.
I've seen your posts, and I'm impressed with your knowledge. I hope my etiquette has not been rude or inappropriate.
I just wanna be friends.
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
EricDV wrote: I hope my etiquette has not been rude or inappropriate.
Nope, not at all.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
I am working in MDI environment. The problem is on click on MDI close box. I am asking user. "if he is sure to close the application " yes or no.. now the child forms which are open also triggers the closing event even before the MDI closing event no matter user say "he dont want to close the application ". So the code on the closing of child executes which I dont want to execute until unless it is really closing.
Note: Child form does not close if user selected to continue with app. but code on closing is executed.
Regards
Rizwan Bashir
|
|
|
|
|
Assuming you are working with Visual Studio 2005, have you looked at the value of the CloseReason property in the MDI childrens FormClosing events? Maybe if the value is MDIFormClosing or FormOwnerClosing you can have conditional code to skip the FormClosing event code unless you know the MDI form has really closed (via some flag).
|
|
|
|
|
Sorry I forgot to mention 2003.
Regards
Rizwan Bashir
|
|
|
|
|
Hello
I want to upload a pdf file for my help page. i'm able to upload the pdf file but the problem is that how would i show the contents of pdf file in a page.
help file extension will be .html.
hope to get some Reply
bye
|
|
|
|
|
|
how can i read and add items from notepad and print them to listview in form vb.net
kilany
|
|
|
|
|
You mean how can you read a text file ? Notepad has nothing to do with it, it's just a program that reads text file. System.IO.File.ReadAllText is the easiest way to read a file.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i send message from vb.net to another application .. the send operation is done successfully but the problem is some times the message change by adding a character or repeat character such as if :
dim s as string ="42945:dn"
send.sendwait(s)
the message will print as 42945:dn but some time will print in the another application 442945:dn and some time 442294::dn really i dont know why ...
some friend advice me to use Trim function but i dont know if it will do as i want or no...
please this is the 15 time that i ask you to help me and give me the function that keep the string as i defined it before send it to another application but unfortunatlly no answer ..
keep me in ur mind.
kilany
|
|
|
|