Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: VisualBasic, Created At: 10/24/2016 8:03:14 PMViews:

HTML view:
Copy Source | Copy HTML
  1. ' Declare for call to mpr.dll.
  2.    Declare Function WNetGetUser Lib "mpr.dll" _
  3.       Alias "WNetGetUserA" (ByVal lpName As String, _
  4.       ByVal lpUserName As String, lpnLength As Long) As Long
  5.    Const NoError = 0 'The Function call was successful
  6.    Sub GetUserName()
  7.       ' Buffer size for the return string.
  8.       Const lpnLength As Integer = 255
  9.       ' Get return buffer space.
  10.       Dim status As Integer
  11.       ' For getting user information.
  12.       Dim lpName, lpUserName As String
  13.       ' Assign the buffer size constant to lpUserName.
  14.       lpUserName = Space$(lpnLength + 1)
  15.       ' Get the log-on name of the person using product.
  16.       status = WNetGetUser(lpName, lpUserName, lpnLength)
  17.       ' See whether error occurred.
  18.       If status = NoError Then
  19.          ' This line removes the null character. Strings in C are null-
  20.          ' terminated. Strings in Visual Basic are not null-terminated.
  21.          ' The null character must be removed from the C strings to be used
  22.          ' cleanly in Visual Basic.
  23.          lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
  24.       Else
  25.          ' An error occurred.
  26.          MsgBox "Unable to get the name."
  27.          End
  28.       End If
  29.       ' Display the name of the person logged on to the machine.
  30.       MsgBox "The person logged on this machine is: " & lpUserName
  31.    End Sub

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017