home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / DMNPASS2 / PASS_SRC.ZIP / PASSWORD.BAS < prev    next >
BASIC Source File  |  1994-06-21  |  7KB  |  189 lines

  1.  
  2. 'PASSWORD.BAS
  3. '============
  4. Dim user10a() As user_info_10
  5.  
  6. Function FileExists (path$) As Integer
  7. '----------------------------------------------------------
  8. ' Check for the existence of a file by attempting an OPEN.
  9. '----------------------------------------------------------
  10.  
  11.     x = FreeFile
  12.  
  13.     On Error Resume Next
  14.     Open path$ For Input As x
  15.     If Err = 0 Then
  16.         FileExists = True
  17.     Else
  18.         FileExists = False
  19.     End If
  20.     Close x
  21.  
  22. End Function
  23.  
  24. Function Getserver% ()
  25. ' Set CurrentServer to the domain controller for
  26. ' the CurrentDomain.
  27.     Dim result%
  28.     Dim ErrMsg$, newsvr$, svr$
  29.     svr = ""
  30.     newsvr = Space$(CNLEN + 3)   ' must be big enough to contain domain name
  31.     Do
  32.         result = NetGetDCName(svr, CurrentDomain, ByVal newsvr, Len(newsvr))
  33.         If result <> 0 Then
  34.             If CurrentDomain <> LogonDomain Then
  35.                 ErrMsg$ = "Error retrieving domain controller for domain " + CurrentDomain + ". Domain name will be set to the logon domain " + LogonDomain + "." + Chr$(13) + Chr$(13)
  36.                 ErrMsg$ = ErrMsg$ + "Error <" + Format$(result) + "> : " + LMError$(result)
  37.                 MsgBox ErrMsg$, MB_ICONEXCLAMATION, "Error Retrieving Domain Controller"
  38.                 CurrentDomain = LogonDomain  ' set currently selected domain to logon domain
  39.             Else
  40.                 ErrMsg$ = "Error retrieving domain controller." + Chr$(13) + Chr$(13)
  41.                 ErrMsg$ = ErrMsg$ + "Error <" + Format$(result) + "> : " + LMError$(result)
  42.                 MsgBox ErrMsg$, MB_ICONEXCLAMATION, "Error Retrieving Domain Controller"
  43.                 newsvr = ""
  44.                 Exit Do
  45.             End If
  46.         End If
  47.     Loop While result <> 0
  48.     newsvr = LTrim$(newsvr)
  49.     If newsvr <> "" Then
  50.         CurrentServer = Mid$(newsvr, 1, InStr(newsvr, Chr$(0)) - 1)
  51.     Else
  52.         CurrentServer = ""
  53.     End If
  54.     Getserver = result
  55. End Function
  56.  
  57. Function GetWindowsSysDir () As String
  58. '---------------------------------------------------------
  59. ' Calls the windows API to get the windows\SYSTEM directory
  60. '---------------------------------------------------------
  61.     temp$ = String$(145, 0)                 ' Size Buffer
  62.     x = GetSystemDirectory(temp$, 145)      ' Make API Call
  63.     temp$ = Left$(temp$, x)                 ' Trim Buffer
  64.  
  65.     If Right$(temp$, 1) <> "\" Then         ' Add \ if necessary
  66.         GetWindowsSysDir$ = temp$ + "\"
  67.     Else
  68.         GetWindowsSysDir$ = temp$
  69.     End If
  70.  
  71. End Function
  72.  
  73. Function LMNetWkstaGetInfo_L10% (Server$, VB_WkstaInfo As wksta_info_10)
  74.  
  75. ' Declare Function NetWkstaGetInfo% Lib "NETAPI.DLL" (ByVal pszServer$, ByVal sLevel%, ByVal pbBuffer&, ByVal cbBuffer%, pcbTotalAvail%)
  76.                                         'NetWkstaGetInfo(Server, Level, BufferPointer, BufferSize, TotalBytesAvail)
  77.  
  78. ' Wrapper:  LMNetWkstaGetInfo_L10
  79. '    File:  WKSTA.BAS
  80. ' Purpose:  Returns information about the configuration
  81. '           elements for a workstation.
  82.  
  83. '   Data Structure:  wksta_info_10
  84. '            Level:  10
  85. ' Associated Files:  WKSTA.TXT
  86. '                    VBLANMAN.TXT
  87.  
  88. ' Parameters:  Server - the name of the server on which to execute the
  89. '                       command. A NULL string specifies the local computer.
  90.  
  91. '              VB_WkstaInfo - wksta_info structure in which to store the
  92. '                       returned data.
  93.  
  94.  
  95. ' Variables used in the NetWkstaGetInfo API call
  96.     Dim Level As Integer                        ' information level
  97.     Dim BufferPointer As Long                   ' pointer to LM buffer
  98.     Dim BufferSize As Integer                   ' buffer size
  99.     Dim TotalBytesAvail As Integer              ' total bytes available
  100.  
  101. ' Other variables
  102.     Dim result As Integer          ' return value for API call
  103.  
  104.                                                                
  105.     Level = 10  ' designates information level, cannot just change this
  106.                 ' value to change info level - structure name and constant
  107.                 ' name must also be changed (wksta_info_10 and
  108.                 ' FMT_wksta_info_10).  The function name
  109.                 ' (LMNetWkstaGetInfo_L10) should also be changed.
  110.  
  111. ' Create LM buffer and get size in BufferSize
  112.     BufferPointer = CreateLMBuffer(FMT_wksta_info_10, 1, BufferSize)
  113.  
  114.     If BufferPointer = 0& Then      ' error, unable to allocate buffer
  115.         LMNetWkstaGetInfo_L10 = -1
  116.         Exit Function
  117.     End If
  118.  
  119. ' Call LM API function NetWkstaGetInfo to get data
  120.     result = NetWkstaGetInfo(Server, Level, BufferPointer, BufferSize, TotalBytesAvail)
  121. ' check for error return
  122.  
  123.     If result <> NERR_Success Then       ' error occurred
  124.         LMNetWkstaGetInfo_L10 = result          ' set return for function
  125.         result = FreeLMBuffer(BufferPointer)    ' free LM buffer
  126.         Exit Function
  127.     End If
  128.  
  129. ' Copy data from LM buffer to wksta_info structure
  130.     result = BufferToVBType(VB_WkstaInfo, Len(VB_WkstaInfo), BufferPointer, BufferSize, FMT_wksta_info_10)
  131.     
  132. ' check if error
  133.     If result = NERR_Success Then    ' return OK
  134.         LMNetWkstaGetInfo_L10 = FreeLMBuffer(BufferPointer)  ' free memory for LM buffer
  135.     Else                ' error occurred, set return value
  136.         LMNetWkstaGetInfo_L10 = result
  137.         result = FreeLMBuffer(BufferPointer)  ' free memory for LM buffer
  138.     End If
  139.  
  140. End Function
  141.  
  142. Function MultiNetGetUser (UserName$) As Integer
  143.  
  144. ' The following function determines the logged-in user in Windows for
  145.    ' Workgroups:
  146.  
  147.       Dim hNetDrv As Integer
  148.       Dim wRetEnum As Integer, ret As Integer
  149.       Dim wRetGetUser As Integer
  150.       Dim cb As Integer
  151.       Dim Found As Integer
  152.  
  153.       Found = False
  154.       ' Grab the 1st network:
  155.       hNetDrv = 0
  156.       wRetEnum = MNetNetworkEnum(hNetDrv)
  157.  
  158.       ' Loop while there are installed networks:
  159.       While (wRetEnum = 0) And Not Found
  160.          wfwUser$ = Space$(255)
  161.          cb = Len(wfwUser$)
  162.  
  163.          ' Make sure correct network is accessed in next WNetGetUser call:
  164.          ret = MNetSetNextTarget(hNetDrv)
  165.  
  166.          ' Get the user:
  167.          wRetGetUser = WNetGetUser(wfwUser$, cb)
  168.  
  169.          ' Check for success:
  170.          If wRetGetUser = 0 Then
  171.             ' Just grab the relevant characters:
  172.             UserName$ = Left$(wfwUser$, cb - 1)
  173.             'MsgBox UserName$, , "WNetGetUser"
  174.             Found = True
  175.          End If
  176.  
  177.          ' Get the next network:
  178.          wRetEnum = MNetNetworkEnum(hNetDrv)
  179.       Wend
  180.       If Not Found Then
  181.          MsgBox "WNetGetUser not supported on any of the Multinet subnets"
  182.       End If
  183.       wfwUser$ = Left$(wfwUser$, cb - 1)
  184.       MultiNetGetUser = Found
  185.  
  186.    
  187. End Function
  188.  
  189.