Trying to find a 32 and 64 bit compatible method to get logged in user's information.

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Happy New Year!

I am trying to determine if the command : CreateObject("WSCript.Network").username is compatible with both the 32 and 64bit versions of office or is there a better way to get the logged in username?

Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I know somebody who used to use that function and had to re-write a lot of stuff when it stopped working. Sorry I cannot recall why; likely some sort of IS modification to the network. I've also read elsewhere how others found it wonky. There is an easy to use API call that MANY use, for which I've never heard or read of any issues and it's been around for a long, long time. API: Get Login name
You might also want to check out Declare PtrSafe for declaring 32 bit calls safe for 64 bit platforms. My new syntax for calling this function will be
Code:
#If VBA7 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
 
Last edited:
Upvote 0
I know somebody who used to use that function and had to re-write a lot of stuff when it stopped working. Sorry I cannot recall why; likely some sort of IS modification to the network. I've also read elsewhere how others found it wonky. There is an easy to use API call that MANY use, for which I've never heard or read of any issues and it's been around for a long, long time. API: Get Login name
You might also want to check out Declare PtrSafe for declaring 32 bit calls safe for 64 bit platforms. My new syntax for calling this function will be
Code:
#If VBA7 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If

Ok thank I will look into this when I have fresh eyes...
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,242
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top