Solved

INI FILE FOR VB5

Posted on 1998-11-17
2
316 Views
Last Modified: 2010-05-03
I am tring to put a vb app on 18 pc's in a network.
I need to know how to get the computer network name
and the domain name using vb code.
Each pc requires specific code to run the app with the proper data from an access database.
If i cant get the network name or domain name , is there a way to use an " ini " file ???
Thanks
     Diamondp

0
Comment
Question by:DIAMONDP
2 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 1445345
What kind of specific code and how would you use the INI file?  Would it be one INI file in a central location that each one would see or would it be on each machine?

What are you trying to do?
0
 

Accepted Solution

by:
theseowgroup earned 100 total points
ID: 1445346
There are standard APIs to get the network and domain info that you need.  Your talk on INI confused me some as you do not need that. Anyhow, here is an extract from a Kb article. Try this and see:

Using the Win32 application programming interface (API), you can retrieve
network information, such as the user name, workgroup, domain, and computer
name, about the currently running computer when you are running Microsoft
Windows NT or Microsoft Windows 95.
 
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
 
MORE INFORMATION
================
 
NetWkstaGetInfo(), a Windows API, takes advantage of the Windows NT
security model and returns the computer, workgroup, and domain. Windows
95, however, can get the current user name with the network independent
function call WNetGetUser and can get the current computer name with the
function GetComputerName(). The code samples demonstrate the use of all
three.
 
The following example shows how to use Visual Basic and the Win32 API to
retrieve network information:
 
1. Create a module and type the following lines in the Declarations
   section:
 
   NOTE: You may have some Microsoft Windows API functions defined in an
   existing Microsoft Access library; therefore, your declarations may be
   duplicates. If you receive a duplicate procedure name error message,
   remove or comment out the declarations statement in your code.
 
   NOTE: All Declare statements must be typed exactly as shown, including
   capitalization, because Win32 names are case-sensitive. To help
   eliminate errors by you or others who use your Declare statements,
   create Alias clauses for Declare statements that do not have an existing
   Alias. As long as the Alias is correctly spelled and capitalized, it
   does not matter how the function name is capitalized.
 
   NOTE: Make sure to click the Compile All command on the Run menu to
   verify that you do not receive any compilation errors.
 
      Option Explicit
      Type WKSTA_INFO_101
         wki101_platform_id As Long
         wki101_computername As Long
         wki101_langroup As Long
         wki101_ver_major As Long
         wki101_ver_minor As Long
         wki101_lanroot As Long
      End Type
 
      Type WKSTA_USER_INFO_1
         wkui1_username As Long
         wkui1_logon_domain As Long
         wkui1_logon_server As Long
         wkui1_oth_domains As Long
      End Type
 
      Declare Function WNetGetUser& Lib "Mpr" Alias "WNetGetUserA" _
         (lpName As Any, ByVal lpUserName$, lpnLength&)
      Declare Function NetWkstaGetInfo& Lib "Netapi32" _
         (strServer As Any, ByVal lLevel&, pbBuffer As Any)
      Declare Function NetWkstaUserGetInfo& Lib "Netapi32" _
         (reserved As Any, ByVal lLevel&, pbBuffer As Any)
      Declare Sub lstrcpyW Lib "Kernel32" (dest As Any, ByVal src As Any)
      Declare Sub lstrcpy Lib "Kernel32" (dest As Any, ByVal src As Any)
      Declare Sub RtlMoveMemory Lib "Kernel32" _
         (dest As Any, src As Any, ByVal size&)
      Declare Function NetApiBufferFree& Lib "Netapi32" (ByVal buffer&)
 
2. Type the following procedure:
 
      Function GetWorkstationInfo()
         Dim ret As Long, buffer(512) As Byte, i As Integer
         Dim wk101 As WKSTA_INFO_101, pwk101 As Long
         Dim wk1 As WKSTA_USER_INFO_1, pwk1 As Long
         Dim cbusername As Long, username As String
         Dim computername As String, langroup As String, logondomain As _
            String
 
         ' Clear all of the display values.
         computername = "": langroup = "": username = "": logondomain = ""
 
         ' Windows 95 or NT - call WNetGetUser to get the name of the user.
         username = Space(256)
         cbusername = Len(username)
         ret = WNetGetUser(ByVal 0&, username, cbusername)
         If ret = 0 Then
            ' Success - strip off the null.
            username = Left(username, InStr(username, Chr(0)) - 1)
         Else
            username = ""
         End If
 
      '================================================================
      ' The following section works only under Windows NT
      '================================================================
 
         'NT only - call NetWkstaGetInfo to get computer name and lan group
         ret = NetWkstaGetInfo(ByVal 0&, 101, pwk101)
         RtlMoveMemory wk101, ByVal pwk101, Len(wk101)
         lstrcpyW buffer(0), wk101.wki101_computername
         ' Get every other byte from Unicode string.
         i = 0
         Do While buffer(i) <> 0
            computername = computername & Chr(buffer(i))
            i = i + 2
         Loop
         lstrcpyW buffer(0), wk101.wki101_langroup
         i = 0
         Do While buffer(i) <> 0
            langroup = langroup & Chr(buffer(i))
            i = i + 2
         Loop
         ret = NetApiBufferFree(pwk101)
 
         ' NT only - call NetWkstaUserGetInfo.
         ret = NetWkstaUserGetInfo(ByVal 0&, 1, pwk1)
         RtlMoveMemory wk1, ByVal pwk1, Len(wk1)
         lstrcpyW buffer(0), wk1.wkui1_logon_domain
         i = 0
         Do While buffer(i) <> 0
            logondomain = logondomain & Chr(buffer(i))
            i = i + 2
         Loop
         ret = NetApiBufferFree(pwk1)
 
      '================================================================
      'End NT-specific section
      '================================================================
 
         debug.print computername, langroup, username, logondomain
      End Function
 
3. To test this function, type the following line in the Debug window,
   and then press ENTER:
 
      GetWorkstationInfo
 
   Note that your data is printed in the Debug Window.
 
The following example shows how to use Visual Basic and the Win32 API to
retrieve the current computer name under Windows 95:
 
1. Create a module and type the following lines in the Declarations
   section:
 
       Option Explicit
       Private Declare Function GetComputerName _
       Lib "kernel32" Alias "GetComputerNameA" ( _
       ByVal lpBuffer As String, nSize As Long) As Long
 
       Private Const MAX_COMPUTERNAME_LENGTH As Long = 15&
 
2. Type the following procedure:
 
       Public Function CurrentMachineName() As String
       Dim lSize As Long
       Dim sBuffer As String
       sBuffer = Space$(MAX_COMPUTERNAME_LENGTH + 1)
       lSize = Len(sBuffer)
 
          If GetComputerName(sBuffer, lSize) Then
              CurrentMachineName = Left$(sBuffer, lSize)
          End If
 
       End Function
 
3. To test this function, type the following line in the Debug window, and
   then press ENTER:
 
       ?CurrentMachineName()
 
   Note that your data is printed to the Debug Window.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now