|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CurrentUserDeclare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, ByRef nSize As Integer) As Integer Public Function GetUserName() As String Dim iReturn As Integer Dim userName As String userName = New String(CChar(" "), 50) iReturn = GetUserName(userName, 50) GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) End Function reidarT Show quoteHide quote "reidarT" <rei***@eivon.no> skrev i melding news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... > How do I get current user logged in with vb.net code? > reidarT > Environment.UserName
regards Michel Posseth [MCP] Show quoteHide quote "reidarT" wrote: > > Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" > (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer > > Public Function GetUserName() As String > Dim iReturn As Integer > Dim userName As String > userName = New String(CChar(" "), 50) > iReturn = GetUserName(userName, 50) > GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) > End Function > > reidarT > > "reidarT" <rei***@eivon.no> skrev i melding > news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... > > How do I get current user logged in with vb.net code? > > reidarT > > > > > Or: My.User.Name
Michel Posseth [MCP] wrote: Show quoteHide quote > > Environment.UserName > > regards > > Michel Posseth [MCP] > > > "reidarT" wrote: > >> Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" >> (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer >> >> Public Function GetUserName() As String >> Dim iReturn As Integer >> Dim userName As String >> userName = New String(CChar(" "), 50) >> iReturn = GetUserName(userName, 50) >> GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) >> End Function >> >> reidarT >> >> "reidarT" <rei***@eivon.no> skrev i melding >> news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... >>> How do I get current user logged in with vb.net code? >>> reidarT >>> >> >> I use the following code.
Public Shared Function CurrentUser() As String Static user As String = "" If user = "" Then Dim WindowsUser As System.Security.Principal.WindowsIdentity = _ System.Security.Principal.WindowsIdentity.GetCurrent user = WindowsUser.Name.ToUpper Dim i As Integer = InStrRev(user, "\") If i > 0 Then user = Mid$(user, i + 1) End If Return user End Function Mike Ober. Show quoteHide quote "Theo Verweij" <tverw***@xs4all.nl> wrote in message news:e4svNPJwGHA.724@TK2MSFTNGP05.phx.gbl... > Or: My.User.Name > > Michel Posseth [MCP] wrote: >> >> Environment.UserName >> >> regards >> >> Michel Posseth [MCP] "reidarT" wrote: >> >>> Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" >>> (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer >>> >>> Public Function GetUserName() As String >>> Dim iReturn As Integer >>> Dim userName As String >>> userName = New String(CChar(" "), 50) >>> iReturn = GetUserName(userName, 50) >>> GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) >>> End Function >>> >>> reidarT >>> >>> "reidarT" <rei***@eivon.no> skrev i melding >>> news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... >>>> How do I get current user logged in with vb.net code? >>>> reidarT >>>> >>> >>> no they are not the same :-)
on a computer in a domain Environment.UserName returns the username ( "Michel") while My.User.Name returns ("domainName\Michel" ofcourse you could split this but why would you ? if there is an alternative :-) regardsMichel Posseth Show quoteHide quote "Theo Verweij" wrote: > Or: My.User.Name > > Michel Posseth [MCP] wrote: > > > > Environment.UserName > > > > regards > > > > Michel Posseth [MCP] > > > > > > "reidarT" wrote: > > > >> Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" > >> (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer > >> > >> Public Function GetUserName() As String > >> Dim iReturn As Integer > >> Dim userName As String > >> userName = New String(CChar(" "), 50) > >> iReturn = GetUserName(userName, 50) > >> GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) > >> End Function > >> > >> reidarT > >> > >> "reidarT" <rei***@eivon.no> skrev i melding > >> news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... > >>> How do I get current user logged in with vb.net code? > >>> reidarT > >>> > >> > >> > Your are right.
My.User.Name = Environment.UserDomain & "\"& Environment.UserName But both are much simpler than using an API call :-) regards, Theo Verweij Michel Posseth [MCP] wrote: Show quoteHide quote > no they are not the same :-) > > on a computer in a domain > > Environment.UserName returns the username ( "Michel") > > while My.User.Name returns ("domainName\Michel" > > ofcourse you could split this but why would you ? if there is an alternative > :-) > > regards > > Michel Posseth > > > > "Theo Verweij" wrote: > >> Or: My.User.Name >> >> Michel Posseth [MCP] wrote: >>> Environment.UserName >>> >>> regards >>> >>> Michel Posseth [MCP] >>> >>> >>> "reidarT" wrote: >>> >>>> Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" >>>> (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer >>>> >>>> Public Function GetUserName() As String >>>> Dim iReturn As Integer >>>> Dim userName As String >>>> userName = New String(CChar(" "), 50) >>>> iReturn = GetUserName(userName, 50) >>>> GetUserName = userName.Substring(0, userName.IndexOf(Chr(0))) >>>> End Function >>>> >>>> reidarT >>>> >>>> "reidarT" <rei***@eivon.no> skrev i melding >>>> news:etAJeEGwGHA.4460@TK2MSFTNGP04.phx.gbl... >>>>> How do I get current user logged in with vb.net code? >>>>> reidarT >>>>> >>>>
Waiting for process end , how?
Ctype Viewing machine data source names Label changes not being reflected until loop is done Fill up string array with random characters? Dim DBh as new DBhandler vb.net 2.0 question Draw Line in a specific picturebox hard drive type HelpWriter Forcing page.ispostback to run... |
|||||||||||||||||||||||