Results 1 to 9 of 9

Thread: embarisingly easly i think

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Suffolk. UK
    Posts
    162

    embarisingly easly i think

    What is the vb constant for the current user name?

    Is there 1, i cant fid a reference to it?


    thanks in advance.

  2. #2
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    VB Code:
    1. 'This project needs a timer
    2. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    3. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    4. Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
    5. Private Sub Form_Load()
    6.     'KPD-Team 1998
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Timer1.Interval = 100
    10.     Timer1.Enabled = True
    11.     Dim strTemp As String, strUserName As String
    12.     'Create a buffer
    13.     strTemp = String(100, Chr$(0))
    14.     'Get the temporary path
    15.     GetTempPath 100, strTemp
    16.     'strip the rest of the buffer
    17.     strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)
    18.  
    19.     'Create a buffer
    20.     strUserName = String(100, Chr$(0))
    21.     'Get the username
    22.     GetUserName strUserName, 100
    23.     'strip the rest of the buffer
    24.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    25.  
    26.     'Show the temppath and the username
    27.     MsgBox "Hello " + strUserName + Chr$(13) + "The temp. path is " + strTemp
    28. End Sub
    29. Private Sub Timer1_Timer()
    30.     Dim Boo As Boolean
    31.     'Check if this form is minimized
    32.     Boo = IsIconic(Me.hwnd)
    33.     'Update the form's caption
    34.     Me.Caption = "Form minimized: " + Str$(Boo)
    35. End Sub

    Regards...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Suffolk. UK
    Posts
    162
    Thanks, look

    cheers

  4. #4
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Another cool example from API Guide 3.6

    VB Code:
    1. 'Add this code to a module and set the Project's Startup Object to 'Sub Main'
    2. '    (-> Project Menu -> Project Properties -> General Tab)
    3. Private Const RESOURCE_CONNECTED As Long = &H1&
    4. Private Const RESOURCE_GLOBALNET As Long = &H2&
    5. Private Const RESOURCE_REMEMBERED As Long = &H3&
    6. Private Const RESOURCEDISPLAYTYPE_DIRECTORY& = &H9
    7. Private Const RESOURCEDISPLAYTYPE_DOMAIN& = &H1
    8. Private Const RESOURCEDISPLAYTYPE_FILE& = &H4
    9. Private Const RESOURCEDISPLAYTYPE_GENERIC& = &H0
    10. Private Const RESOURCEDISPLAYTYPE_GROUP& = &H5
    11. Private Const RESOURCEDISPLAYTYPE_NETWORK& = &H6
    12. Private Const RESOURCEDISPLAYTYPE_ROOT& = &H7
    13. Private Const RESOURCEDISPLAYTYPE_SERVER& = &H2
    14. Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
    15. Private Const RESOURCEDISPLAYTYPE_SHAREADMIN& = &H8
    16. Private Const RESOURCETYPE_ANY As Long = &H0&
    17. Private Const RESOURCETYPE_DISK As Long = &H1&
    18. Private Const RESOURCETYPE_PRINT As Long = &H2&
    19. Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF&
    20. Private Const RESOURCEUSAGE_ALL As Long = &H0&
    21. Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
    22. Private Const RESOURCEUSAGE_CONTAINER As Long = &H2&
    23. Private Const RESOURCEUSAGE_RESERVED As Long = &H80000000
    24. Private Const NO_ERROR = 0
    25. Private Const ERROR_MORE_DATA = 234                        'L    // dderror
    26. Private Const RESOURCE_ENUM_ALL As Long = &HFFFF
    27. Private Type NETRESOURCE
    28.     dwScope As Long
    29.     dwType As Long
    30.     dwDisplayType As Long
    31.     dwUsage As Long
    32.     pLocalName As Long
    33.     pRemoteName As Long
    34.     pComment As Long
    35.     pProvider As Long
    36. End Type
    37. Private Type NETRESOURCE_REAL
    38.     dwScope As Long
    39.     dwType As Long
    40.     dwDisplayType As Long
    41.     dwUsage As Long
    42.     sLocalName As String
    43.     sRemoteName As String
    44.     sComment As String
    45.     sProvider As String
    46. End Type
    47. Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    48. Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
    49. Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As NETRESOURCE, lpBufferSize As Long) As Long
    50. Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
    51. Private Declare Function VarPtrAny Lib "vb40032.dll" Alias "VarPtr" (lpObject As Any) As Long
    52. Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (lpTo As Any, lpFrom As Any, ByVal lLen As Long)
    53. Private Declare Sub CopyMemByPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, ByVal lLen As Long)
    54. Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
    55. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
    56. Private Declare Function getusername Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    57. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    58. Public strUserName As String
    59. Public strMachinerName As String
    60. Sub main()
    61.     'KPD-Team 2000
    62.     'URL: [url]http://www.allapi.net/[/url]
    63.     'E-Mail: [email][email protected][/email]
    64.     '-> This sample was created by Donald Grover
    65.     Const MAX_RESOURCES = 256
    66.     Const NOT_A_CONTAINER = -1
    67.     Dim bFirstTime As Boolean
    68.     Dim lReturn As Long
    69.     Dim hEnum As Long
    70.     Dim lCount As Long
    71.     Dim lMin As Long
    72.     Dim lLength As Long
    73.     Dim l As Long
    74.     Dim lBufferSize As Long
    75.     Dim lLastIndex As Long
    76.     Dim uNetApi(0 To MAX_RESOURCES) As NETRESOURCE
    77.     Dim uNet() As NETRESOURCE_REAL
    78.     bFirstTime = True
    79.     Do
    80.         If bFirstTime Then
    81.             lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, ByVal 0&, hEnum)
    82.             bFirstTime = False
    83.         Else
    84.             If uNet(lLastIndex).dwUsage And RESOURCEUSAGE_CONTAINER Then
    85.                 lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, uNet(lLastIndex), hEnum)
    86.             Else
    87.                 lReturn = NOT_A_CONTAINER
    88.                 hEnum = 0
    89.             End If
    90.             lLastIndex = lLastIndex + 1
    91.         End If
    92.         If lReturn = NO_ERROR Then
    93.             lCount = RESOURCE_ENUM_ALL
    94.             Do
    95.                 lBufferSize = UBound(uNetApi) * Len(uNetApi(0)) / 2
    96.                 lReturn = WNetEnumResource(hEnum, lCount, uNetApi(0), lBufferSize)
    97.                 If lCount > 0 Then
    98.                     ReDim Preserve uNet(0 To lMin + lCount - 1) As NETRESOURCE_REAL
    99.                     For l = 0 To lCount - 1
    100.                         'Each Resource will appear here as uNet(i)
    101.                         uNet(lMin + l).dwScope = uNetApi(l).dwScope
    102.                         uNet(lMin + l).dwType = uNetApi(l).dwType
    103.                         uNet(lMin + l).dwDisplayType = uNetApi(l).dwDisplayType
    104.                         uNet(lMin + l).dwUsage = uNetApi(l).dwUsage
    105.                         If uNetApi(l).pLocalName Then
    106.                             lLength = lstrlen(uNetApi(l).pLocalName)
    107.                             uNet(lMin + l).sLocalName = Space$(lLength)
    108.                             CopyMem ByVal uNet(lMin + l).sLocalName, ByVal uNetApi(l).pLocalName, lLength
    109.                         End If
    110.                         If uNetApi(l).pRemoteName Then
    111.                             lLength = lstrlen(uNetApi(l).pRemoteName)
    112.                             uNet(lMin + l).sRemoteName = Space$(lLength)
    113.                             CopyMem ByVal uNet(lMin + l).sRemoteName, ByVal uNetApi(l).pRemoteName, lLength
    114.                         End If
    115.                         If uNetApi(l).pComment Then
    116.                             lLength = lstrlen(uNetApi(l).pComment)
    117.                             uNet(lMin + l).sComment = Space$(lLength)
    118.                             CopyMem ByVal uNet(lMin + l).sComment, ByVal uNetApi(l).pComment, lLength
    119.                         End If
    120.                         If uNetApi(l).pProvider Then
    121.                             lLength = lstrlen(uNetApi(l).pProvider)
    122.                             uNet(lMin + l).sProvider = Space$(lLength)
    123.                             CopyMem ByVal uNet(lMin + l).sProvider, ByVal uNetApi(l).pProvider, lLength
    124.                         End If
    125.                     Next l
    126.                 End If
    127.                 lMin = lMin + lCount
    128.             Loop While lReturn = ERROR_MORE_DATA
    129.         End If
    130.         If hEnum Then
    131.             l = WNetCloseEnum(hEnum)
    132.         End If
    133.     Loop While lLastIndex < lMin
    134.  
    135.     If UBound(uNet) > 0 Then
    136.         username
    137.         Dim filNum As Integer
    138.         filNum = FreeFile
    139.         Open App.Path & "\" & LCase(App.EXEName) & ".txt" For Output Shared As #filNum
    140.         'Open "d:\" & App.EXEName & ".txt" For Output Shared As #filNum
    141.         Print #filNum, "Date: " & Format(Now, "Long date")
    142.         Print #filNum, ""
    143.         Print #filNum, "UserName:      " & strUserName
    144.         Print #filNum, "Computer Name: " & strMachinerName
    145.         For l = 0 To UBound(uNet)
    146.             Select Case uNet(l).dwDisplayType
    147.                 Case RESOURCEDISPLAYTYPE_DIRECTORY&
    148.                     Debug.Print "Directory...",
    149.                     Print #filNum, "Directory...",
    150.                 Case RESOURCEDISPLAYTYPE_DOMAIN
    151.                     Debug.Print "Domain...",
    152.                     Print #filNum, "Domain...",
    153.                 Case RESOURCEDISPLAYTYPE_FILE
    154.                     Debug.Print "File...",
    155.                     Print #filNum, "File...",
    156.                 Case RESOURCEDISPLAYTYPE_GENERIC
    157.                     Debug.Print "Generic...",
    158.                     Print #filNum, "Generic...",
    159.                 Case RESOURCEDISPLAYTYPE_GROUP
    160.                     Debug.Print "Group...",
    161.                     Print #filNum, "Group...",
    162.                 Case RESOURCEDISPLAYTYPE_NETWORK&
    163.                     Debug.Print "Network...",
    164.                     Print #filNum, "Network...",
    165.                 Case RESOURCEDISPLAYTYPE_ROOT&
    166.                     Debug.Print "Root...",
    167.                     Print #filNum, "Root...",
    168.                 Case RESOURCEDISPLAYTYPE_SERVER
    169.                     Debug.Print "Server...",
    170.                     Print #filNum, "Server...",
    171.                 Case RESOURCEDISPLAYTYPE_SHARE
    172.                     Debug.Print "Share...",
    173.                     Print #filNum, "Share...",
    174.                 Case RESOURCEDISPLAYTYPE_SHAREADMIN&
    175.                     Debug.Print "ShareAdmin...",
    176.                     Print #filNum, "ShareAdmin...",
    177.             End Select
    178.             Debug.Print uNet(l).sRemoteName, uNet(l).sComment
    179.             Print #filNum, uNet(l).sRemoteName, uNet(l).sComment
    180.         Next l
    181.     End If
    182.     Close #filNum
    183.     MsgBox "File " + App.Path & "\" & LCase(App.EXEName) & ".txt created" + vbCrLf + "Open it in a text editor to see the results", vbInformation
    184. End Sub
    185. Private Sub username()
    186.   On Error Resume Next
    187.     'Create a buffer
    188.     strUserName = String(255, Chr$(0))
    189.     'Get the username
    190.     getusername strUserName, 255
    191.     'strip the rest of the buffer
    192.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    193.      'Create a buffer
    194.     strMachinerName = String(255, Chr$(0))
    195.     GetComputerName strMachinerName, 255
    196.     'remove the unnecessary chr$(0)'s
    197.     strMachinerName = Left$(strMachinerName, InStr(1, strMachinerName, Chr$(0)) - 1)
    198. End Sub
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2.  
    3. Private UserAccount As String
    4.  
    5. Private Sub GetUserAccount()
    6.  
    7.     Dim sBuffer As String
    8.     Dim lSize As Long
    9.    
    10.     sBuffer = Space$(255)
    11.     lSize = Len(sBuffer)
    12.     Call GetUserName(sBuffer, lSize)
    13.     If lSize > 0 Then
    14.         UserAccount = Left$(sBuffer, lSize - 1)
    15.     Else
    16.         UserAccount = vbNullString
    17.     End If
    18.    
    19. End Sub

  6. #6
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593

    Re: Another cool example from API Guide 3.6

    Originally posted by zuperman
    VB Code:
    1. 'Add this code to a module and set the Project's Startup Object to 'Sub Main'
    2. '    (-> Project Menu -> Project Properties -> General Tab)
    3. Private Const RESOURCE_CONNECTED As Long = &H1&
    4. Private Const RESOURCE_GLOBALNET As Long = &H2&
    5. Private Const RESOURCE_REMEMBERED As Long = &H3&
    6. Private Const RESOURCEDISPLAYTYPE_DIRECTORY& = &H9
    7. Private Const RESOURCEDISPLAYTYPE_DOMAIN& = &H1
    8. Private Const RESOURCEDISPLAYTYPE_FILE& = &H4
    9. Private Const RESOURCEDISPLAYTYPE_GENERIC& = &H0
    10. Private Const RESOURCEDISPLAYTYPE_GROUP& = &H5
    11. Private Const RESOURCEDISPLAYTYPE_NETWORK& = &H6
    12. Private Const RESOURCEDISPLAYTYPE_ROOT& = &H7
    13. Private Const RESOURCEDISPLAYTYPE_SERVER& = &H2
    14. Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
    15. Private Const RESOURCEDISPLAYTYPE_SHAREADMIN& = &H8
    16. Private Const RESOURCETYPE_ANY As Long = &H0&
    17. Private Const RESOURCETYPE_DISK As Long = &H1&
    18. Private Const RESOURCETYPE_PRINT As Long = &H2&
    19. Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF&
    20. Private Const RESOURCEUSAGE_ALL As Long = &H0&
    21. Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
    22. Private Const RESOURCEUSAGE_CONTAINER As Long = &H2&
    23. Private Const RESOURCEUSAGE_RESERVED As Long = &H80000000
    24. Private Const NO_ERROR = 0
    25. Private Const ERROR_MORE_DATA = 234                        'L    // dderror
    26. Private Const RESOURCE_ENUM_ALL As Long = &HFFFF
    27. Private Type NETRESOURCE
    28.     dwScope As Long
    29.     dwType As Long
    30.     dwDisplayType As Long
    31.     dwUsage As Long
    32.     pLocalName As Long
    33.     pRemoteName As Long
    34.     pComment As Long
    35.     pProvider As Long
    36. End Type
    37. Private Type NETRESOURCE_REAL
    38.     dwScope As Long
    39.     dwType As Long
    40.     dwDisplayType As Long
    41.     dwUsage As Long
    42.     sLocalName As String
    43.     sRemoteName As String
    44.     sComment As String
    45.     sProvider As String
    46. End Type
    47. Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
    48. Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
    49. Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As NETRESOURCE, lpBufferSize As Long) As Long
    50. Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
    51. Private Declare Function VarPtrAny Lib "vb40032.dll" Alias "VarPtr" (lpObject As Any) As Long
    52. Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (lpTo As Any, lpFrom As Any, ByVal lLen As Long)
    53. Private Declare Sub CopyMemByPtr Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpTo As Long, ByVal lpFrom As Long, ByVal lLen As Long)
    54. Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
    55. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
    56. Private Declare Function getusername Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    57. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    58. Public strUserName As String
    59. Public strMachinerName As String
    60. Sub main()
    61.     'KPD-Team 2000
    62.     'URL: [url]http://www.allapi.net/[/url]
    63.     'E-Mail: [email][email protected][/email]
    64.     '-> This sample was created by Donald Grover
    65.     Const MAX_RESOURCES = 256
    66.     Const NOT_A_CONTAINER = -1
    67.     Dim bFirstTime As Boolean
    68.     Dim lReturn As Long
    69.     Dim hEnum As Long
    70.     Dim lCount As Long
    71.     Dim lMin As Long
    72.     Dim lLength As Long
    73.     Dim l As Long
    74.     Dim lBufferSize As Long
    75.     Dim lLastIndex As Long
    76.     Dim uNetApi(0 To MAX_RESOURCES) As NETRESOURCE
    77.     Dim uNet() As NETRESOURCE_REAL
    78.     bFirstTime = True
    79.     Do
    80.         If bFirstTime Then
    81.             lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, ByVal 0&, hEnum)
    82.             bFirstTime = False
    83.         Else
    84.             If uNet(lLastIndex).dwUsage And RESOURCEUSAGE_CONTAINER Then
    85.                 lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, uNet(lLastIndex), hEnum)
    86.             Else
    87.                 lReturn = NOT_A_CONTAINER
    88.                 hEnum = 0
    89.             End If
    90.             lLastIndex = lLastIndex + 1
    91.         End If
    92.         If lReturn = NO_ERROR Then
    93.             lCount = RESOURCE_ENUM_ALL
    94.             Do
    95.                 lBufferSize = UBound(uNetApi) * Len(uNetApi(0)) / 2
    96.                 lReturn = WNetEnumResource(hEnum, lCount, uNetApi(0), lBufferSize)
    97.                 If lCount > 0 Then
    98.                     ReDim Preserve uNet(0 To lMin + lCount - 1) As NETRESOURCE_REAL
    99.                     For l = 0 To lCount - 1
    100.                         'Each Resource will appear here as uNet(i)
    101.                         uNet(lMin + l).dwScope = uNetApi(l).dwScope
    102.                         uNet(lMin + l).dwType = uNetApi(l).dwType
    103.                         uNet(lMin + l).dwDisplayType = uNetApi(l).dwDisplayType
    104.                         uNet(lMin + l).dwUsage = uNetApi(l).dwUsage
    105.                         If uNetApi(l).pLocalName Then
    106.                             lLength = lstrlen(uNetApi(l).pLocalName)
    107.                             uNet(lMin + l).sLocalName = Space$(lLength)
    108.                             CopyMem ByVal uNet(lMin + l).sLocalName, ByVal uNetApi(l).pLocalName, lLength
    109.                         End If
    110.                         If uNetApi(l).pRemoteName Then
    111.                             lLength = lstrlen(uNetApi(l).pRemoteName)
    112.                             uNet(lMin + l).sRemoteName = Space$(lLength)
    113.                             CopyMem ByVal uNet(lMin + l).sRemoteName, ByVal uNetApi(l).pRemoteName, lLength
    114.                         End If
    115.                         If uNetApi(l).pComment Then
    116.                             lLength = lstrlen(uNetApi(l).pComment)
    117.                             uNet(lMin + l).sComment = Space$(lLength)
    118.                             CopyMem ByVal uNet(lMin + l).sComment, ByVal uNetApi(l).pComment, lLength
    119.                         End If
    120.                         If uNetApi(l).pProvider Then
    121.                             lLength = lstrlen(uNetApi(l).pProvider)
    122.                             uNet(lMin + l).sProvider = Space$(lLength)
    123.                             CopyMem ByVal uNet(lMin + l).sProvider, ByVal uNetApi(l).pProvider, lLength
    124.                         End If
    125.                     Next l
    126.                 End If
    127.                 lMin = lMin + lCount
    128.             Loop While lReturn = ERROR_MORE_DATA
    129.         End If
    130.         If hEnum Then
    131.             l = WNetCloseEnum(hEnum)
    132.         End If
    133.     Loop While lLastIndex < lMin
    134.  
    135.     If UBound(uNet) > 0 Then
    136.         username
    137.         Dim filNum As Integer
    138.         filNum = FreeFile
    139.         Open App.Path & "\" & LCase(App.EXEName) & ".txt" For Output Shared As #filNum
    140.         'Open "d:\" & App.EXEName & ".txt" For Output Shared As #filNum
    141.         Print #filNum, "Date: " & Format(Now, "Long date")
    142.         Print #filNum, ""
    143.         Print #filNum, "UserName:      " & strUserName
    144.         Print #filNum, "Computer Name: " & strMachinerName
    145.         For l = 0 To UBound(uNet)
    146.             Select Case uNet(l).dwDisplayType
    147.                 Case RESOURCEDISPLAYTYPE_DIRECTORY&
    148.                     Debug.Print "Directory...",
    149.                     Print #filNum, "Directory...",
    150.                 Case RESOURCEDISPLAYTYPE_DOMAIN
    151.                     Debug.Print "Domain...",
    152.                     Print #filNum, "Domain...",
    153.                 Case RESOURCEDISPLAYTYPE_FILE
    154.                     Debug.Print "File...",
    155.                     Print #filNum, "File...",
    156.                 Case RESOURCEDISPLAYTYPE_GENERIC
    157.                     Debug.Print "Generic...",
    158.                     Print #filNum, "Generic...",
    159.                 Case RESOURCEDISPLAYTYPE_GROUP
    160.                     Debug.Print "Group...",
    161.                     Print #filNum, "Group...",
    162.                 Case RESOURCEDISPLAYTYPE_NETWORK&
    163.                     Debug.Print "Network...",
    164.                     Print #filNum, "Network...",
    165.                 Case RESOURCEDISPLAYTYPE_ROOT&
    166.                     Debug.Print "Root...",
    167.                     Print #filNum, "Root...",
    168.                 Case RESOURCEDISPLAYTYPE_SERVER
    169.                     Debug.Print "Server...",
    170.                     Print #filNum, "Server...",
    171.                 Case RESOURCEDISPLAYTYPE_SHARE
    172.                     Debug.Print "Share...",
    173.                     Print #filNum, "Share...",
    174.                 Case RESOURCEDISPLAYTYPE_SHAREADMIN&
    175.                     Debug.Print "ShareAdmin...",
    176.                     Print #filNum, "ShareAdmin...",
    177.             End Select
    178.             Debug.Print uNet(l).sRemoteName, uNet(l).sComment
    179.             Print #filNum, uNet(l).sRemoteName, uNet(l).sComment
    180.         Next l
    181.     End If
    182.     Close #filNum
    183.     MsgBox "File " + App.Path & "\" & LCase(App.EXEName) & ".txt created" + vbCrLf + "Open it in a text editor to see the results", vbInformation
    184. End Sub
    185. Private Sub username()
    186.   On Error Resume Next
    187.     'Create a buffer
    188.     strUserName = String(255, Chr$(0))
    189.     'Get the username
    190.     getusername strUserName, 255
    191.     'strip the rest of the buffer
    192.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    193.      'Create a buffer
    194.     strMachinerName = String(255, Chr$(0))
    195.     GetComputerName strMachinerName, 255
    196.     'remove the unnecessary chr$(0)'s
    197.     strMachinerName = Left$(strMachinerName, InStr(1, strMachinerName, Chr$(0)) - 1)
    198. End Sub
    With all due respect: zuperman, shouldn't such a long code example be supplied as a ZIP file for download? I mean, you code listing wasn't exactly short.

  7. #7
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033

    Re: Re: Another cool example from API Guide 3.6

    Originally posted by HaxSoft


    With all due respect: zuperman, shouldn't such a long code example be supplied as a ZIP file for download? I mean, you code listing wasn't exactly short.
    With all due respect:HaxSoft, i thought this way it would be easier to copy/paste, but im sorry for this long code...
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    zuperman, HaxSoft: All Ping asked for was "What is the vb constant for the current user name?", i.e, who is currently logged into this machine.

    The routines the two of you have posted are very cool, and give a lot of neat information, but, in my humble opinion, exceed the original request.

  9. #9
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    Originally posted by Hack
    zuperman, HaxSoft: All Ping asked for was "What is the vb constant for the current user name?", i.e, who is currently logged into this machine.

    The routines the two of you have posted are very cool, and give a lot of neat information, but, in my humble opinion, exceed the original request.
    You are right, only that I was enthusiastic with the examples of API-GUIDE and wanted to share them with all... sorry again
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width