Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code with API functions below is working perfectly almost on all
computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ...... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& ..... |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Alex, You need to be more specific about what problems you are experiencing and also include the operating systems that the code does and does not run on. What API error you are encountering and which API call has failed. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=507815 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I assume there is some sort of a problem with
msgbox environ("UserName") ??? -- HTH... Jim Thomlinson "Alex" wrote: The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code only works on 32 bit machines. Ok, there are not many 16 bit
machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Also, "netapi32.dll" may not exist or it may not be available. I'm not sure
if it has to be registered or just in a specific folder or any folder within the path statement. Start by making sure it is in the same folder as the other computers (Mine is in C:\Windows\System32) -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "AnExpertNovice" wrote in message ... The code only works on 32 bit machines. Ok, there are not many 16 bit machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for the responses.
Trying to asnwer your questions, Leith: There is Win XP on all computers. The error message is the Run time error whether it's excel or MS Access. If I'm taking off this module it's working. As I said before it's not working only on the few computers. There is some opinion that the netapi32.dll and advapi32.dll probably are not registered there. But, I used search and found these dll files inside the C:Windows\System32 folder. But, when I tried to register them I've got "the file was loaded. DllRegisterServer entry wasn't found. File cannot be registered." Probably they're already registered there and I'm not so comfortable to experiment further on the dll registration. "Leith Ross" wrote: Hello Alex, You need to be more specific about what problems you are experiencing and also include the operating systems that the code does and does not run on. What API error you are encountering and which API call has failed. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=507815 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Alex, My suspecion is this is a server problem. These API call require some adjustment as to which server they are run on. There are differences in Windows 2000, Windows 2003, and the NT 4.0 server. If your code hasn't been designed to automatically adjust to the server being used, it will require making adjustments to the code for the users having problems. This can become a problem again if they port the code to another machine using a different server. In the world of API, one call doesn't do it all. You should talk with your network admin about possible conflicts as well. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=507815 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why not engineer this problem away?
In excel set a reference to the windows script host object model - c:\winnt\system32\wshom.ocx. Then this will get the user name Sub dd() Dim a As WshNetwork MsgBox "username is " & a.UserName End Sub As a general rule, most things that you'd think require an API call have been wrapped up in a nicer COM dll, it's just a case of finding it. Note the "most"... Good luck -- www.alignment-systems.com "Alex" wrote: On my machine I have these DLLs in the System32 and in the I386 folders but on the not working machines there is no I386 folder. However, the username can be the case as well. On the not working machine the username exists but it's a group username without actual full name. Thanks everybody. I'll research it further. "AnExpertNovice" wrote: Also, "netapi32.dll" may not exist or it may not be available. I'm not sure if it has to be registered or just in a specific folder or any folder within the path statement. Start by making sure it is in the same folder as the other computers (Mine is in C:\Windows\System32) -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "AnExpertNovice" wrote in message ... The code only works on 32 bit machines. Ok, there are not many 16 bit machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On my machine I have these DLLs in the System32 and in the I386 folders but
on the not working machines there is no I386 folder. However, the username can be the case as well. On the not working machine the username exists but it's a group username without actual full name. Thanks everybody. I'll research it further. "AnExpertNovice" wrote: Also, "netapi32.dll" may not exist or it may not be available. I'm not sure if it has to be registered or just in a specific folder or any folder within the path statement. Start by making sure it is in the same folder as the other computers (Mine is in C:\Windows\System32) -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "AnExpertNovice" wrote in message ... The code only works on 32 bit machines. Ok, there are not many 16 bit machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, John.
It looks good. Please, advise how to define this 'a' or set up reference. Dim a As WshNetwork "John.Greenan" wrote: Why not engineer this problem away? In excel set a reference to the windows script host object model - c:\winnt\system32\wshom.ocx. Then this will get the user name Sub dd() Dim a As WshNetwork MsgBox "username is " & a.UserName End Sub As a general rule, most things that you'd think require an API call have been wrapped up in a nicer COM dll, it's just a case of finding it. Note the "most"... Good luck -- www.alignment-systems.com "Alex" wrote: On my machine I have these DLLs in the System32 and in the I386 folders but on the not working machines there is no I386 folder. However, the username can be the case as well. On the not working machine the username exists but it's a group username without actual full name. Thanks everybody. I'll research it further. "AnExpertNovice" wrote: Also, "netapi32.dll" may not exist or it may not be available. I'm not sure if it has to be registered or just in a specific folder or any folder within the path statement. Start by making sure it is in the same folder as the other computers (Mine is in C:\Windows\System32) -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "AnExpertNovice" wrote in message ... The code only works on 32 bit machines. Ok, there are not many 16 bit machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
John, I did it. It returns a login id but not a full user name.
Set WshNetwork = CreateObject("WScript.Network") MsgBox "Domain = " & WshNetwork.UserDomain MsgBox "Computer Name = " & WshNetwork.ComputerName MsgBox "User Name = " & WshNetwork.UserName It looks like identical to the strUser = Environ$("username") The API functions that I'm using are able to return a full user name not just a login. Please, correct if I'm wrong. Thanks "Alex" wrote: Thanks, John. It looks good. Please, advise how to define this 'a' or set up reference. Dim a As WshNetwork "John.Greenan" wrote: Why not engineer this problem away? In excel set a reference to the windows script host object model - c:\winnt\system32\wshom.ocx. Then this will get the user name Sub dd() Dim a As WshNetwork MsgBox "username is " & a.UserName End Sub As a general rule, most things that you'd think require an API call have been wrapped up in a nicer COM dll, it's just a case of finding it. Note the "most"... Good luck -- www.alignment-systems.com "Alex" wrote: On my machine I have these DLLs in the System32 and in the I386 folders but on the not working machines there is no I386 folder. However, the username can be the case as well. On the not working machine the username exists but it's a group username without actual full name. Thanks everybody. I'll research it further. "AnExpertNovice" wrote: Also, "netapi32.dll" may not exist or it may not be available. I'm not sure if it has to be registered or just in a specific folder or any folder within the path statement. Start by making sure it is in the same folder as the other computers (Mine is in C:\Windows\System32) -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "AnExpertNovice" wrote in message ... The code only works on 32 bit machines. Ok, there are not many 16 bit machines left and I don't know of any 64 bit, but still, it is a nit pick that had to be plucked. There will be no user name if there is no such environment variable. Check in a DOS Command prompt by typing "Set Username". If the message says it is not defined then it needs to be created. Of course, this is an opportunity to fix the code so that it works when the Username variable doesn't exist. -- My handle should tell you enough about me. I am not an MVP, expert, guru, etc. but I do like to help. "Alex" wrote in message ... The code with API functions below is working perfectly almost on all computers but on a few ones is not working. It's from the code to get a full user name. What could be the cause of this? Thanks ..... Private Declare Function apiNetGetDCName _ Lib "netapi32.dll" Alias "NetGetDCName" _ (ByVal servername As Long, _ ByVal DomainName As Long, _ bufptr As Long) As Long ' function frees the memory that the NetApiBufferAllocate ' function allocates. Private Declare Function apiNetAPIBufferFree _ Lib "netapi32.dll" Alias "NetApiBufferFree" _ (ByVal buffer As Long) _ As Long ' Retrieves the length of the specified wide string. Private Declare Function apilstrlenW _ Lib "kernel32" Alias "lstrlenW" _ (ByVal lpString As Long) _ As Long Private Declare Function apiNetUserGetInfo _ Lib "netapi32.dll" Alias "NetUserGetInfo" _ (servername As Any, _ UserName As Any, _ ByVal level As Long, _ bufptr As Long) As Long ' moves memory either forward or backward, aligned or unaligned, ' in 4-byte blocks, followed by any remaining bytes Private Declare Sub sapiCopyMem _ Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, _ Source As Any, _ ByVal Length As Long) Private Declare Function apiGetUserName Lib _ "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) _ As Long Private Const MAXCOMMENTSZ = 256 Private Const NERR_SUCCESS = 0 Private Const ERROR_MORE_DATA = 234& Private Const MAX_CHUNK = 25 Private Const ERROR_SUCCESS = 0& .... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Multiple functions, conditional functions | Excel Worksheet Functions | |||
How to convert cell formula functions to code functions | Excel Discussion (Misc queries) | |||
efficiency: database functions vs. math functions vs. array formula | Excel Discussion (Misc queries) | |||
Looking for a site with functions that substitute the ATP functions | Excel Worksheet Functions | |||
excel functions and User defined functions | Excel Programming |