Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / January 2005



Tip: Looking for answers? Try searching our database.

Changing TCP/IP Settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim in Arizona - 24 Jan 2005 18:44 GMT
Is there anyway in VB6 to access and modify Windows 2K/XP TCP/IP Properties?

I need to make a little program that, when the user runs the program and
selects one of two options (radio button:?), they set the TCP/IP properties
to either "Obtain IP address automatically via DHCP" or set a specific
IP/Gateway/DNS/WINS, ect.

I don't know if VB can do this or not. If not, what about vb script (WMI?).

I'm hoping someone can point me in the right direction.

Thanks.
Jim
Compu-Pikachu - 24 Jan 2005 21:25 GMT
>Is there any way in VB6 to access and modify Windows 2K/XP TCP/IP
>Properties?

Use Application Programming Interface?
Jim in Arizona - 24 Jan 2005 22:13 GMT
> >Is there any way in VB6 to access and modify Windows 2K/XP TCP/IP
> >Properties?
>
> Use Application Programming Interface?

I'm a newbie and need a little more help. What object would I use and could
you give me a coding example?
Compu-Pikachu - 25 Jan 2005 01:44 GMT
>I'm a newbie and need a little more help.

I am just as clueless about this issue as you are.

>What object would I use, and could you give me a coding example?

Application Programming Interface (API) is not an object but a set of
protocols, routines, and tools for developing programs.

A majority of operating systems such as Windows provide an Application
Programming Interface so that programs can be consistent with those systems.

In Windows, Application Programming Interface involves declaring functions
and/or subroutines contained within dynamic linking libraries.

An almost comprehensive list of Windows' Application Programming Interface
functions and subroutines is available at
www.mentalis.org/apilist/apilist.php.
Jim in Arizona - 26 Jan 2005 15:27 GMT
> >Is there any way in VB6 to access and modify Windows 2K/XP TCP/IP
> >Properties?
>
> Use Application Programming Interface?

I ended up using a combination of VB Script and VB6. I got some VB Script
code from Microsoft (brought to my attention by another individual in
another newsgroup)
http://www.microsoft.com/technet/scriptcenter/scripts/network/client/modify/defa
ult.mspx
.
I used portions from four different scripts from that page then put them
into a VB6 form with two radio buttons and a command button. Here's that
code:
==========================================

Private Sub Command1_Click()
      Shape1.Visible = False
      Shape2.Visible = False
      Label1.Visible = False
      Option1.Visible = False
      Option2.Visible = False
      Command1.Visible = False
      Label2.Visible = False
      Label3.Visible = True
If Option1 = True Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
   ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("192.168.6.180")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.6.1")
strGatewaymetric = Array(1)
arrDNSServers = Array("192.168.1.10", "192.168.3.16")

For Each objNetAdapter In colNetAdapters
   strPrimaryServer = "192.168.1.15"
   strSecondaryServer = "192.168.3.15"
   objNetAdapter.SetWINSServer strPrimaryServer, strSecondaryServer

   errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
   errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
   errDNSServers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)

   If errEnable = 0 Then
      Shape1.Visible = False
      Shape2.Visible = False
      Label3.Visible = False
      Label1.Visible = False
      Option1.Visible = False
      Option2.Visible = False
      Command1.Visible = False
      Label2.Visible = True
   Else
      Shape1.Visible = False
      Shape2.Visible = False
      Label3.Visible = False
      Label1.Visible = False
      Option1.Visible = False
      Option2.Visible = False
      Command1.Visible = False
      Label2.Font.Size = 14
      Label2.Caption = "There Was An Error. Please Restart This Program."
      Label2.Visible = True
   End If
Next

Else
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
   ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
   errEnable = objNetAdapter.EnableDHCP()
Next
      Shape1.Visible = False
      Shape2.Visible = False
      Label3.Visible = False
      Label1.Visible = False
      Option1.Visible = False
      Option2.Visible = False
      Command1.Visible = False
      Label2.Caption = "Cottonwood Settings Are In Effect"
      Label2.Visible = True
End If
End Sub

Private Sub Form_Load()
Label2.Visible = False
Label3.Visible = False
End Sub

=============================================================

It turned out to be exactly what I had envisioned.

I did run into a little problem. I haven't used VB6 in a long time and even
when I did, I wasn't too involved in it as I'm a newbie still. I was unable
to change the font color on the command button. I couldn't find any way to
do it; not in the GUI properties area or code (ie: command1.font.color (no
such thing). Any ideas?

Thanks,
Jim
btpanek09@yahoo.com - 26 Jan 2005 16:31 GMT
You are right, you can't change the color of the Font on a command
button.  Instead use an Option button and change the Style to
Graphical.  Now you can change the Forecolor of this which does change
to Font color.  It still acts like an Option button and will remain
pressed in like an Option control would...so you need to add some code
to pop it back out like a command button would.

> > >Is there any way in VB6 to access and modify Windows 2K/XP TCP/IP
> > >Properties?
[quoted text clipped - 3 lines]
> I ended up using a combination of VB Script and VB6. I got some VB Script
> code from Microsoft (brought to my attention by another individual in

> another newsgroup)

http://www.microsoft.com/technet/scriptcenter/scripts/network/client/modify/defa
ult.mspx

.
> I used portions from four different scripts from that page then put them
> into a VB6 form with two radio buttons and a command button. Here's that
[quoted text clipped - 96 lines]
> Thanks,
> Jim
Jim in Arizona - 26 Jan 2005 16:47 GMT
> You are right, you can't change the color of the Font on a command
> button.  Instead use an Option button and change the Style to
> Graphical.  Now you can change the Forecolor of this which does change
> to Font color.  It still acts like an Option button and will remain
> pressed in like an Option control would...so you need to add some code
> to pop it back out like a command button would.

Have any idea what kind of code would raise or keep it raised? When a form
loads with a single graphical option button, it is selected and therefor
appears pushed in. I tried this:

Sub Form_Load
Option1.Value = False
End Sub

But that didn't do it.

Also, once I push the button in, how would it pop back out when the person
let go of the mouse button?

Thanks for the idea. I didn't know an option radio button could go graphical
like that.
Randy Birch - 26 Jan 2005 17:11 GMT
http://vbnet.mvps.org/code/intrinsic/buttoncolorcheck.htm

Signature

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

: > You are right, you can't change the color of the Font on a command
: > button.  Instead use an Option button and change the Style to
[quoted text clipped - 18 lines]
: Thanks for the idea. I didn't know an option radio button could go graphical
: like that.
Jim in Arizona - 26 Jan 2005 22:54 GMT
> http://vbnet.mvps.org/code/intrinsic/buttoncolorcheck.htm

<------SNIP------>

I looked at both methods of changing the forecolor for 'buttons' and I liked
the check box way of doing it the best. The final code, and all that I
needed, was:

Private Sub Check1_Click()
  If Check1.Value = vbChecked Then
     Check1.Value = vbUnchecked
     'Action Coding Here
  End If
End Sub

Thanks for everyone's help and input.

Jim
Compu-Pikachu - 26 Jan 2005 16:57 GMT
[BTPANEK09] You can't change the color of the font on a command button.

[COMPU-PIKACHU] Your informing me of that interestingly surprising tidbit is
appreciated.  Would you happen to also know why buttons lack ForeColor
properties?
Jim in Arizona - 26 Jan 2005 20:58 GMT
> [BTPANEK09] You can't change the color of the font on a command button.
>
> [COMPU-PIKACHU] Your informing me of that interestingly surprising tidbit
> is appreciated.  Would you happen to also know why buttons lack ForeColor
> properties?
[Jim In Arizona] I would like to know!
Bob O`Bob - 31 Jan 2005 21:43 GMT
>>[BTPANEK09] You can't change the color of the font on a command button.
>>
[quoted text clipped - 3 lines]
>
> [Jim In Arizona] I would like to know!

OMG it's contagious!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.