home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / howtor_1 / frmapica.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-24  |  12.8 KB  |  327 lines

  1. VERSION 5.00
  2. Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TabCtl32.OCX"
  3. Begin VB.Form frmAPICalls 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "API Demonstration"
  6.    ClientHeight    =   4380
  7.    ClientLeft      =   4920
  8.    ClientTop       =   4605
  9.    ClientWidth     =   7110
  10.    Icon            =   "frmAPICalls.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4380
  15.    ScaleWidth      =   7110
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin TabDlg.SSTab TabAPICalls 
  18.       Height          =   3975
  19.       Left            =   120
  20.       TabIndex        =   0
  21.       Top             =   240
  22.       Width           =   6855
  23.       _ExtentX        =   12091
  24.       _ExtentY        =   7011
  25.       _Version        =   393216
  26.       Tabs            =   4
  27.       Tab             =   3
  28.       TabsPerRow      =   2
  29.       TabHeight       =   520
  30.       TabCaption(0)   =   "PING"
  31.       TabPicture(0)   =   "frmAPICalls.frx":0442
  32.       Tab(0).ControlEnabled=   0   'False
  33.       Tab(0).Control(0)=   "cmdPingExecute"
  34.       Tab(0).Control(1)=   "txtSystemName"
  35.       Tab(0).Control(2)=   "lblSystemName"
  36.       Tab(0).Control(3)=   "lblPingInstructions"
  37.       Tab(0).ControlCount=   4
  38.       TabCaption(1)   =   "Reboot/Shutdown"
  39.       TabPicture(1)   =   "frmAPICalls.frx":045E
  40.       Tab(1).ControlEnabled=   0   'False
  41.       Tab(1).Control(0)=   "cmdShutdown"
  42.       Tab(1).Control(1)=   "cmdReboot"
  43.       Tab(1).Control(2)=   "lblRebootInstructions"
  44.       Tab(1).ControlCount=   3
  45.       TabCaption(2)   =   "User/Computer Name"
  46.       TabPicture(2)   =   "frmAPICalls.frx":047A
  47.       Tab(2).ControlEnabled=   0   'False
  48.       Tab(2).Control(0)=   "cmdComputerName"
  49.       Tab(2).Control(1)=   "cmdUserName"
  50.       Tab(2).Control(2)=   "lblUserComputerName"
  51.       Tab(2).ControlCount=   3
  52.       TabCaption(3)   =   "NT Services Manager"
  53.       TabPicture(3)   =   "frmAPICalls.frx":0496
  54.       Tab(3).ControlEnabled=   -1  'True
  55.       Tab(3).Control(0)=   "lblNTServices"
  56.       Tab(3).Control(0).Enabled=   0   'False
  57.       Tab(3).Control(1)=   "lblComputerName"
  58.       Tab(3).Control(1).Enabled=   0   'False
  59.       Tab(3).Control(2)=   "lblServiceName"
  60.       Tab(3).Control(2).Enabled=   0   'False
  61.       Tab(3).Control(3)=   "txtComputerName"
  62.       Tab(3).Control(3).Enabled=   0   'False
  63.       Tab(3).Control(4)=   "txtServiceName"
  64.       Tab(3).Control(4).Enabled=   0   'False
  65.       Tab(3).Control(5)=   "fraService"
  66.       Tab(3).Control(5).Enabled=   0   'False
  67.       Tab(3).Control(6)=   "cmdService"
  68.       Tab(3).Control(6).Enabled=   0   'False
  69.       Tab(3).ControlCount=   7
  70.       Begin VB.CommandButton cmdService 
  71.          Caption         =   "Execute Command"
  72.          Enabled         =   0   'False
  73.          Height          =   255
  74.          Left            =   2040
  75.          TabIndex        =   7
  76.          Top             =   3480
  77.          Width           =   1575
  78.       End
  79.       Begin VB.Frame fraService 
  80.          Caption         =   "Command Choices"
  81.          Height          =   1335
  82.          Left            =   3960
  83.          TabIndex        =   21
  84.          Top             =   2520
  85.          Width           =   2655
  86.          Begin VB.OptionButton optService 
  87.             Caption         =   "STOP SERVICE"
  88.             Height          =   255
  89.             Index           =   3
  90.             Left            =   120
  91.             TabIndex        =   6
  92.             Top             =   960
  93.             Width           =   1575
  94.          End
  95.          Begin VB.OptionButton optService 
  96.             Caption         =   "PAUSE SERVICE"
  97.             Height          =   255
  98.             Index           =   2
  99.             Left            =   120
  100.             TabIndex        =   5
  101.             Top             =   720
  102.             Width           =   1575
  103.          End
  104.          Begin VB.OptionButton optService 
  105.             Caption         =   "START SERVICE"
  106.             Height          =   255
  107.             Index           =   1
  108.             Left            =   120
  109.             TabIndex        =   4
  110.             Top             =   480
  111.             Width           =   1575
  112.          End
  113.          Begin VB.OptionButton optService 
  114.             Caption         =   "GET STATUS"
  115.             Height          =   255
  116.             Index           =   0
  117.             Left            =   120
  118.             TabIndex        =   3
  119.             Top             =   240
  120.             Width           =   1575
  121.          End
  122.       End
  123.       Begin VB.TextBox txtServiceName 
  124.          Height          =   285
  125.          Left            =   1680
  126.          TabIndex        =   2
  127.          Top             =   3000
  128.          Width           =   2175
  129.       End
  130.       Begin VB.TextBox txtComputerName 
  131.          Height          =   285
  132.          Left            =   1680
  133.          TabIndex        =   1
  134.          Top             =   2640
  135.          Width           =   2175
  136.       End
  137.       Begin VB.CommandButton cmdComputerName 
  138.          Caption         =   "COMPUTER"
  139.          Height          =   375
  140.          Left            =   -71160
  141.          TabIndex        =   17
  142.          Top             =   3060
  143.          Width           =   1215
  144.       End
  145.       Begin VB.CommandButton cmdUserName 
  146.          Caption         =   "USER"
  147.          Height          =   375
  148.          Left            =   -73560
  149.          TabIndex        =   16
  150.          Top             =   3060
  151.          Width           =   1215
  152.       End
  153.       Begin VB.CommandButton cmdShutdown 
  154.          Caption         =   "SHUTDOWN"
  155.          Height          =   375
  156.          Left            =   -71160
  157.          TabIndex        =   14
  158.          Top             =   3060
  159.          Width           =   1215
  160.       End
  161.       Begin VB.CommandButton cmdReboot 
  162.          Caption         =   "REBOOT"
  163.          Height          =   375
  164.          Left            =   -73560
  165.          TabIndex        =   13
  166.          Top             =   3060
  167.          Width           =   1215
  168.       End
  169.       Begin VB.CommandButton cmdPingExecute 
  170.          Caption         =   "PING"
  171.          Default         =   -1  'True
  172.          Height          =   375
  173.          Left            =   -72120
  174.          TabIndex        =   12
  175.          Top             =   3420
  176.          Width           =   975
  177.       End
  178.       Begin VB.TextBox txtSystemName 
  179.          Height          =   285
  180.          Left            =   -72600
  181.          TabIndex        =   10
  182.          Text            =   "www.yahoo.com"
  183.          Top             =   2700
  184.          Width           =   3855
  185.       End
  186.       Begin VB.Label lblServiceName 
  187.          Caption         =   "Service Name:"
  188.          Height          =   255
  189.          Left            =   240
  190.          TabIndex        =   20
  191.          Top             =   3000
  192.          Width           =   1215
  193.       End
  194.       Begin VB.Label lblComputerName 
  195.          Caption         =   "Computer Name:"
  196.          Height          =   255
  197.          Left            =   240
  198.          TabIndex        =   19
  199.          Top             =   2640
  200.          Width           =   1215
  201.       End
  202.       Begin VB.Label lblNTServices 
  203.          BackColor       =   &H00E0E0E0&
  204.          Height          =   1575
  205.          Left            =   120
  206.          TabIndex        =   18
  207.          Top             =   960
  208.          Width           =   6495
  209.       End
  210.       Begin VB.Label lblUserComputerName 
  211.          BackColor       =   &H00E0E0E0&
  212.          Height          =   1575
  213.          Left            =   -74880
  214.          TabIndex        =   15
  215.          Top             =   900
  216.          Width           =   6495
  217.       End
  218.       Begin VB.Label lblRebootInstructions 
  219.          BackColor       =   &H00E0E0E0&
  220.          Height          =   1575
  221.          Left            =   -74880
  222.          TabIndex        =   11
  223.          Top             =   900
  224.          Width           =   6495
  225.       End
  226.       Begin VB.Label lblSystemName 
  227.          Caption         =   "Enter NetBIOS, DNS or IP:"
  228.          Height          =   255
  229.          Left            =   -74880
  230.          TabIndex        =   9
  231.          Top             =   2700
  232.          Width           =   2055
  233.       End
  234.       Begin VB.Label lblPingInstructions 
  235.          BackColor       =   &H00E0E0E0&
  236.          Height          =   1575
  237.          Left            =   -74880
  238.          TabIndex        =   8
  239.          Top             =   900
  240.          Width           =   6495
  241.       End
  242.    End
  243.    Begin VB.Menu mnuFile 
  244.       Caption         =   "&File"
  245.       Begin VB.Menu mnuExit 
  246.          Caption         =   "E&xit"
  247.       End
  248.    End
  249. Attribute VB_Name = "frmAPICalls"
  250. Attribute VB_GlobalNameSpace = False
  251. Attribute VB_Creatable = False
  252. Attribute VB_PredeclaredId = True
  253. Attribute VB_Exposed = False
  254. Private Sub cmdComputerName_Click()
  255.     MsgBox "The computer name is:  " & ComputerName, vbOKOnly, "GETCOMPUTERNAME API"
  256. End Sub
  257. Private Sub cmdPingExecute_Click()
  258.     'Disable Command Button to prevent multiple clicks by user
  259.     cmdPingExecute.Enabled = False
  260.     'Actual PING code calls
  261.     Dim PING As ICMP, Result As Boolean
  262.     Set PING = New ICMP
  263.     Result = PING.DoPing(txtSystemName.Text)
  264.     MsgBox "IP Address:  " & PING.LastIP, vbInformation, "PING Results"
  265.     'Re-enable Command Button
  266.     cmdPingExecute.Enabled = True
  267. End Sub
  268. Private Sub cmdReboot_Click()
  269. '-----Must adjust security token for Windows NT Systems-----
  270.     If glngWhichWindows32 = mlngWindowsNT Then AdjustToken
  271.     ExitWindowsEx EWX_REBOOT, 0
  272.     Unload Me
  273. End Sub
  274. Private Sub cmdService_Click()
  275.     Dim x As Integer
  276.     '-----I know there is an easier way to determine the-----
  277.     '-----option button that is clicked - I'm having a brain lapse-----
  278.     For x = 0 To optService.Count - 1
  279.         If optService.Item(x) = True Then
  280.             Exit For
  281.         End If
  282.     Next x
  283.     Select Case x
  284.         Case 0 'Get Service Status
  285.             MsgBox "Current Status: " & ServiceStatus(txtComputerName.Text, txtServiceName.Text), vbOKOnly, "SERVICE STATUS"
  286.         
  287.         Case 1 'Start Service
  288.             ServiceStart txtComputerName.Text, txtServiceName.Text
  289.             
  290.         Case 2 'Pause Service
  291.             ServicePause txtComputerName.Text, txtServiceName.Text
  292.             
  293.         Case 3 'Stop Service
  294.             ServiceStop txtComputerName.Text, txtServiceName.Text
  295.     End Select
  296. End Sub
  297. Private Sub cmdShutdown_Click()
  298. '-----Must adjust security token for Windows NT Systems-----
  299.     If glngWhichWindows32 = mlngWindowsNT Then AdjustToken
  300.     ExitWindowsEx EWX_SHUTDOWN, 0
  301.     Unload Me
  302. End Sub
  303. Private Sub cmdUserName_Click()
  304.     MsgBox "The logged on user is:  " & UserName, vbOKOnly, "GETUSERNAME API"
  305. End Sub
  306. Private Sub Form_Load()
  307.     '-----Set the Instructions for each tab-----
  308.     lblPingInstructions.Caption = "PING(Packet InterNet Groper0) allows the user to determine if a remote system is online.  Enter a NetBIOS computer name(if you are on a network) like MYSERVERNAME or a DNS Name(if you are on the Internet) like www.yahoo.com OR you can enter the IP address of the computer 141.10.3.132 for example." & vbCrLf & vbCrLf & "This program will return the IP address if the system is online or an error message such as 'Unable to Locate Host' if offline."
  309.     lblRebootInstructions.Caption = "This tab allows you to Reboot or Shutdown your computer using a single button click.  You will notice a lot of code is used to adjust security token privileges for Windows NT.  If you are using only Windows 95/98 that code portion can be removed.  Using the complete module listed here, this program will work for Windows NT and Windows 95/98." & vbCrLf & vbCrLf & "WARNING:  Save ALL data before using these commands!!!!"
  310.     lblUserComputerName.Caption = "These buttons will use the GetComputerName and the GetUserName API calls.  For Windows 95/98 systems without a logon prompt, the GetUserName API may be blank.  For Windows 95/98 systems without a network connection, the GetComputerName API may be blank."
  311.     lblNTServices.Caption = "This section will allow you to get the current status of NT SERVICES and START/STOP/PAUSE them.  Keep in mind that you must have a user account with privileges to change the status of services." & vbCrLf & vbCrLf & "A full-version is available that lists the services for you.  E-mail Shane.Hage@Roche.com to request it." & vbCrLf & "For the LOCAL MACHINE, DO NOT enter any Computer Name in."
  312.     '-----Determine the version of Windows running-----
  313.     Dim lngVersion As Long
  314.     lngVersion = GetVersion()
  315.     If ((lngVersion And &H80000000) = 0) Then
  316.         glngWhichWindows32 = mlngWindowsNT
  317.     Else
  318.         glngWhichWindows32 = mlngWindows95
  319.     End If
  320. End Sub
  321. Private Sub mnuExit_Click()
  322.     End
  323. End Sub
  324. Private Sub optService_Click(Index As Integer)
  325.     cmdService.Enabled = True
  326. End Sub
  327.