home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / WinNT / Computer / App / Computer.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-03-17  |  11.4 KB  |  384 lines

  1. VERSION 5.00
  2. Begin VB.Form frmComputer 
  3.    Caption         =   "Computer"
  4.    ClientHeight    =   7755
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   7590
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   7755
  10.    ScaleWidth      =   7590
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Refresh 
  13.       Caption         =   "Refresh"
  14.       Height          =   345
  15.       Left            =   3165
  16.       TabIndex        =   27
  17.       Top             =   6390
  18.       Width           =   1290
  19.    End
  20.    Begin VB.CommandButton cmdClose 
  21.       Caption         =   "Close"
  22.       Default         =   -1  'True
  23.       Height          =   360
  24.       Left            =   3285
  25.       TabIndex        =   26
  26.       Top             =   7260
  27.       Width           =   1185
  28.    End
  29.    Begin VB.Frame Frame2 
  30.       Caption         =   "Resource"
  31.       Height          =   2580
  32.       Left            =   5100
  33.       TabIndex        =   24
  34.       Top             =   4260
  35.       Width           =   2400
  36.       Begin VB.ListBox lstResource 
  37.          Height          =   1620
  38.          Left            =   180
  39.          TabIndex        =   25
  40.          Top             =   285
  41.          Width           =   1980
  42.       End
  43.    End
  44.    Begin VB.Frame Frame5 
  45.       Caption         =   "Session"
  46.       Height          =   2580
  47.       Left            =   2625
  48.       TabIndex        =   22
  49.       Top             =   4275
  50.       Width           =   2400
  51.       Begin VB.ListBox lstSession 
  52.          Height          =   1620
  53.          Left            =   180
  54.          TabIndex        =   23
  55.          Top             =   285
  56.          Width           =   1980
  57.       End
  58.    End
  59.    Begin VB.CommandButton cmdShare 
  60.       Caption         =   "New..."
  61.       Height          =   345
  62.       Left            =   630
  63.       TabIndex        =   19
  64.       Top             =   6375
  65.       Width           =   1290
  66.    End
  67.    Begin VB.Frame Frame4 
  68.       Caption         =   "Shares"
  69.       Height          =   2580
  70.       Left            =   90
  71.       TabIndex        =   20
  72.       Top             =   4275
  73.       Width           =   2400
  74.       Begin VB.ListBox lstShare 
  75.          Height          =   1620
  76.          Left            =   165
  77.          TabIndex        =   21
  78.          Top             =   285
  79.          Width           =   1980
  80.       End
  81.    End
  82.    Begin VB.TextBox txtProcessorCount 
  83.       BackColor       =   &H8000000F&
  84.       Height          =   315
  85.       Left            =   4005
  86.       TabIndex        =   17
  87.       Top             =   3285
  88.       Width           =   2445
  89.    End
  90.    Begin VB.TextBox txtOSVersion 
  91.       BackColor       =   &H8000000F&
  92.       Height          =   315
  93.       Left            =   3990
  94.       TabIndex        =   8
  95.       Top             =   2055
  96.       Width           =   2445
  97.    End
  98.    Begin VB.TextBox txtProcessor 
  99.       BackColor       =   &H8000000F&
  100.       Height          =   315
  101.       Left            =   3990
  102.       TabIndex        =   7
  103.       Top             =   2865
  104.       Width           =   2445
  105.    End
  106.    Begin VB.TextBox txtOwner 
  107.       BackColor       =   &H8000000F&
  108.       Height          =   315
  109.       Left            =   3990
  110.       TabIndex        =   6
  111.       Top             =   2460
  112.       Width           =   2445
  113.    End
  114.    Begin VB.TextBox txtOS 
  115.       BackColor       =   &H8000000F&
  116.       Height          =   315
  117.       Left            =   3990
  118.       TabIndex        =   4
  119.       Top             =   1650
  120.       Width           =   2445
  121.    End
  122.    Begin VB.CommandButton cmdChange 
  123.       Caption         =   "Change..."
  124.       Height          =   345
  125.       Left            =   3570
  126.       TabIndex        =   3
  127.       Top             =   240
  128.       Width           =   1365
  129.    End
  130.    Begin VB.TextBox txtDomain 
  131.       BackColor       =   &H8000000F&
  132.       ForeColor       =   &H80000012&
  133.       Height          =   315
  134.       Left            =   1155
  135.       TabIndex        =   2
  136.       Top             =   255
  137.       Width           =   2265
  138.    End
  139.    Begin VB.TextBox txtDivision 
  140.       BackColor       =   &H8000000F&
  141.       Height          =   285
  142.       Left            =   3990
  143.       TabIndex        =   1
  144.       Top             =   1275
  145.       Width           =   2445
  146.    End
  147.    Begin VB.ListBox lstComputer 
  148.       Height          =   2985
  149.       Left            =   225
  150.       TabIndex        =   0
  151.       Top             =   1065
  152.       Width           =   2010
  153.    End
  154.    Begin VB.Frame Frame1 
  155.       Caption         =   "Properties"
  156.       Height          =   3045
  157.       Left            =   2535
  158.       TabIndex        =   9
  159.       Top             =   930
  160.       Width           =   4935
  161.       Begin VB.Label Label5 
  162.          Caption         =   "Processor Count"
  163.          Height          =   240
  164.          Left            =   150
  165.          TabIndex        =   18
  166.          Top             =   2370
  167.          Width           =   1320
  168.       End
  169.       Begin VB.Label Label4 
  170.          Caption         =   "Processor"
  171.          Height          =   210
  172.          Left            =   180
  173.          TabIndex        =   14
  174.          Top             =   1965
  175.          Width           =   1110
  176.       End
  177.       Begin VB.Label Label3 
  178.          Caption         =   "Owner"
  179.          Height          =   225
  180.          Left            =   180
  181.          TabIndex        =   13
  182.          Top             =   1560
  183.          Width           =   1080
  184.       End
  185.       Begin VB.Label lblSvcType 
  186.          Caption         =   "OS Version"
  187.          Height          =   195
  188.          Left            =   165
  189.          TabIndex        =   12
  190.          Top             =   1155
  191.          Width           =   1125
  192.       End
  193.       Begin VB.Label Label7 
  194.          Caption         =   "OS"
  195.          Height          =   165
  196.          Left            =   180
  197.          TabIndex        =   11
  198.          Top             =   765
  199.          Width           =   810
  200.       End
  201.       Begin VB.Label DisplayName 
  202.          Caption         =   "Division"
  203.          Height          =   210
  204.          Left            =   165
  205.          TabIndex        =   10
  206.          Top             =   375
  207.          Width           =   1485
  208.       End
  209.    End
  210.    Begin VB.Frame Frame3 
  211.       Caption         =   "Domain"
  212.       Height          =   735
  213.       Left            =   195
  214.       TabIndex        =   15
  215.       Top             =   15
  216.       Width           =   7215
  217.       Begin VB.Label Label1 
  218.          Caption         =   "Name:"
  219.          Height          =   270
  220.          Left            =   255
  221.          TabIndex        =   16
  222.          Top             =   270
  223.          Width           =   750
  224.       End
  225.    End
  226.    Begin VB.Label Label2 
  227.       Caption         =   "Computer:"
  228.       Height          =   240
  229.       Left            =   285
  230.       TabIndex        =   5
  231.       Top             =   780
  232.       Width           =   1275
  233.    End
  234. Attribute VB_Name = "frmComputer"
  235. Attribute VB_GlobalNameSpace = False
  236. Attribute VB_Creatable = False
  237. Attribute VB_PredeclaredId = True
  238. Attribute VB_Exposed = False
  239. '----------------------------------------------------------------------------
  240. '  Microsoft Active Directory 2.5 Sample Code
  241. '  Copyright (C) Microsoft Corporation, 1996 - 1999
  242. '  File:       frmComputer.frm
  243. '  Contents:   Main Computer Form
  244. '----------------------------------------------------------------------------
  245. Dim cont As IADsContainer
  246. Dim lanSvc As IADsFileService
  247. Public usrName As String
  248. Public usrPassword As String
  249. Private Sub cmdChange_Click()
  250.   ShowConnectDlg
  251.   PopulateComputer frmConnect.GetUserName, frmConnect.GetPassword
  252. End Sub
  253. Private Sub ShowConnectDlg()
  254.   frmConnect.Show vbModal, Me
  255.   If (frmConnect.Tag = "") Then
  256.     txtDomain = ""
  257.  Else
  258.     txtDomain = frmConnect.Tag
  259.  End If
  260. End Sub
  261. Private Sub PopulateComputer(user As String, password As String)
  262. Dim o As IADsOpenDSObject
  263. lstComputer.Clear
  264. 'Assign the varibles
  265. usrName = user
  266. usrPassword = password
  267. domain = txtDomain
  268. '-------------------------------------------
  269. '- Open based on the credentials supplied
  270. '--------------------------------------------
  271. Set cont = BindObject("WinNT://" & domain)
  272. '--------------------------------------------------------
  273. ' Computer is specified eg, dc01,computer
  274. ' then get the computer's parent ( which is a domain )
  275. '----------------------------------------------------------
  276. If InStr(txtDomain, ",computer") > 0 Then
  277.   lstComputer.AddItem cont.Name
  278.   'If domain was specified, enumerate all computers in that domain
  279.   cont.Filter = Array("Computer")
  280.   For Each comp In cont
  281.      lstComputer.AddItem comp.Name
  282.   Next
  283. End If
  284. End Sub
  285. Private Function BindObject(adsPath As String) As IADs
  286. Dim o As IADsOpenDSObject
  287. If (usrName <> "") Then
  288.    Set o = GetObject("WinNT:")
  289.    Set BindObject = o.OpenDSObject(adsPath, usrName, usrPassword, 1)
  290.    Set BindObject = GetObject(adsPath)
  291. End If
  292. End Function
  293. Private Function GetCurrentComputer() As IADsComputer
  294.  If (lstComputer.Text = "") Then
  295.     Set GetCurrentComputer = Nothing
  296.     Exit Function
  297.  End If
  298.  'If it is already computer object, set the computer
  299.  If (cont.Class = "Computer") Then
  300.     Set GetCurrentComputer = cont
  301.  Else
  302.     Set GetCurrentComputer = cont.GetObject("computer", lstComputer.Text)
  303.  End If
  304. End Function
  305. Private Sub cmdRestart_Click()
  306. Dim op As IADsComputerOperations
  307. Set op = GetCurrentComputer()
  308. '-- ShutDown is NOT IMPLEMENTED in ADSI 2.5
  309. 'op.Shutdown (True)
  310. End Sub
  311. Private Sub cmdClose_Click()
  312. End Sub
  313. Private Sub cmdShare_Click()
  314. Dim newShare As String
  315. Dim fileShare As IADsFileShare
  316. '-- Get the information
  317. frmShare.Show vbModal, Me
  318. newShare = frmShare.txtNewShare
  319. '--- Now create the share
  320. If (newShare <> "") Then
  321.    If (IsEmpty(lanSvc) = False) Then
  322.       Set fileShare = lanSvc.Create("fileShare", newShare)
  323.       fileShare.Path = frmShare.txtPath
  324.       fileShare.SetInfo
  325.       RefreshShare
  326.    End If
  327. End If
  328. End Sub
  329. Private Sub cmdShutdown_Click()
  330. Dim op As IADsComputerOperations
  331. Set op = GetCurrentComputer()
  332. op.Shutdown (False)
  333. End Sub
  334. Private Sub Form_Load()
  335.  usrName = ""
  336.  usrPassword = ""
  337.  Set lanSvc = Nothing
  338.  '-----------------------------------------------------
  339.  ' Call cmdChange to force the user to select computer
  340.  '------------------------------------------------------
  341.  cmdChange_Click
  342. End Sub
  343. Private Sub lstComputer_Click()
  344. Dim cmp As IADsComputer
  345. Dim fileShare As IADsFileShare
  346. Dim rsc As IADsResource
  347. Dim session As IADsSession
  348. Set cmp = GetCurrentComputer()
  349. txtDivision = cmp.Division
  350. txtOS = cmp.OperatingSystem
  351. txtOSVersion = cmp.OperatingSystemVersion
  352. txtOwner = cmp.Owner
  353. txtProcessor = cmp.Processor
  354. txtProcessorCount = cmp.ProcessorCount
  355. 'Populate File Shares
  356. Set lanSvc = BindObject(cmp.adsPath & "/" & "LanmanServer")
  357. RefreshResource
  358. RefreshSession
  359. RefreshShare
  360. End Sub
  361. Sub RefreshResource()
  362. On Error Resume Next
  363. lstResource.Clear
  364. For Each rsc In lanSvc.Resources
  365.     lstResource.AddItem rsc.Path
  366. End Sub
  367. Sub RefreshSession()
  368. lstSession.Clear
  369. If (IsEmpty(lanSvc) = False) Then
  370.     For Each session In lanSvc.Sessions
  371.       lstSession.AddItem session.Name
  372.     Next
  373. End If
  374. End Sub
  375. Sub RefreshShare()
  376. On Error Resume Next
  377. lstShare.Clear
  378. For Each fileShare In lanSvc
  379.   lstShare.AddItem fileShare.Name
  380. End Sub
  381. Private Sub Refresh_Click()
  382.   RefreshSession
  383. End Sub
  384.