Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default User Name via 1. API, 2. Enviornment, 3. WScript.Network

All,

I have reviewed the several ways of retrieving a User Name from various
postings here. I have listed 3 below. Are the results of each is coming
from different places? Can someone tell me from where each is pulling the
UserName info?

I am currently assuming that the API & WScript are coming from the same
place since I rec'd the same answer (until someone tells me otherwise). Are
there pros/cons of using the WScript vs. API function?

Thank your for any assistance.
MSweetG222




Option Explicit
'================================================= ==
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Function UserNameWindows()
Dim lngLen As Long
Dim strBuffer As String
Const dhcMaxUserName = 255
strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then
UserNameWindows = Left$(strBuffer, lngLen - 1)
Else
UserNameWindows = ""
End If
End Function
'================================================= ==
Function UserName()
Dim wsnet
Set wsnet = CreateObject("wscript.network")
UserName = wsnet.UserName
End Function
'================================================= ==
Function EnvironUserName()
EnvironUserName = Environ("USERNAME")
End Function
'================================================= ==
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default User Name via 1. API, 2. Enviornment, 3. WScript.Network

I would assume that they all get the answer from the same place, just use
different (more accessible) methods of extracting it. They should all return
the same value, they do on my box(es).

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"MSweetG222" wrote in message
...
All,

I have reviewed the several ways of retrieving a User Name from various
postings here. I have listed 3 below. Are the results of each is coming
from different places? Can someone tell me from where each is pulling the
UserName info?

I am currently assuming that the API & WScript are coming from the same
place since I rec'd the same answer (until someone tells me otherwise).

Are
there pros/cons of using the WScript vs. API function?

Thank your for any assistance.
MSweetG222




Option Explicit
'================================================= ==
Private Declare Function GetUserName Lib "advapi32.dll" Alias

"GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long

Function UserNameWindows()
Dim lngLen As Long
Dim strBuffer As String
Const dhcMaxUserName = 255
strBuffer = Space(dhcMaxUserName)
lngLen = dhcMaxUserName
If CBool(GetUserName(strBuffer, lngLen)) Then
UserNameWindows = Left$(strBuffer, lngLen - 1)
Else
UserNameWindows = ""
End If
End Function
'================================================= ==
Function UserName()
Dim wsnet
Set wsnet = CreateObject("wscript.network")
UserName = wsnet.UserName
End Function
'================================================= ==
Function EnvironUserName()
EnvironUserName = Environ("USERNAME")
End Function
'================================================= ==



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default User Name via 1. API, 2. Enviornment, 3. WScript.Network

Bob - thanks for responding.

On my system, the API & WScript return the same answer.
The Environ returns nothing.
I checked "Set" in Dos and sure enough, there is not a UserName variable.

Thx
MSweetG222


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default User Name via 1. API, 2. Enviornment, 3. WScript.Network

I have heard a couple of different ideas on environ vs API. One is that
Environ was not uspported by Windows 98 / ME. The other is that the API
returns the network login, while environ returns the windows login (which
although not normally differnent can be). I am not too sure if or what is
true. I always just use environ.
--
HTH...

Jim Thomlinson


"MSweetG222" wrote:

Bob - thanks for responding.

On my system, the API & WScript return the same answer.
The Environ returns nothing.
I checked "Set" in Dos and sure enough, there is not a UserName variable.

Thx
MSweetG222


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
user cannot access his share workbook after opening network path. phil Excel Discussion (Misc queries) 0 September 26th 06 04:48 PM
user cannot access his share workbook on network drive. Phil Excel Worksheet Functions 0 September 26th 06 04:30 PM
using WScript.CreateObject("Wscript.Shell John Keith[_2_] Excel Programming 3 August 30th 05 07:20 PM
Multi-user macro on network drive? xangelusx Excel Discussion (Misc queries) 3 July 25th 05 10:05 PM
Finding the Username of a user who has a shared Network file open. Ken[_23_] Excel Programming 1 September 10th 04 12:35 PM


All times are GMT +1. The time now is 12:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"