Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get OS- Infos? Environ- Function? 3

Status
Not open for further replies.

webstony

Technical User
Jan 29, 2001
19
0
0
DE
Hi everybody,

vba is totally new to me, so my question might be very simple.
I work with VBA in Word and I need some operating system informations (my OS is WIN NT 4), like which user 's logged in ... Can I use the Environ- Function? And if, how do I get information with it. The help-system of VBA does not contain the Names of the environment variables.

I hope you can help me,

Greetings from Europe, Sebastian
 
I just found this at the web:

Private Sub ListEnviron()
Dim new_value As String
Dim txt As String
Dim i As Integer

i = 1
Do
new_value = Environ$(i)
If Len(new_value) = 0 Then Exit Do
txt = txt & new_value & vbCrLf
i = i + 1
Loop
MsgBox txt
End Sub

It lists all environment-variables in a message box, very helpful!!
 
Some of these are in the Application object.

For example:

Application.OperatingSystem
Application.UserName

have a look at the help for the Application Object.
 
Webstony,

I've been looking for some way to list all the environment variables and found your post.

Thanks for putting the code up. Very useful.

Keng
 
Also,

I use environ("username") quite often. Pretty useful. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) _
As Long

Function strNetworkUserName() As String
' [This procedure uses the Win32API function GetUserName ]
' [to return the name of the user currently logged on to ]
' [this machine. The Declare statement for the API function]
' [is located in the Declarations section of this module ]

Dim strBuffer As String
Dim lngSize As Long

strBuffer = String(100, " ")
lngSize = Len(strBuffer)

If GetUserName(strBuffer, lngSize) = 1 Then
'strip off trailing null
strNetworkUserName = Left$(strBuffer, lngSize - 1)
Else
strNetworkUserName = "NW/UID unknown"
End If

End Function

M :)
 
Mossoft's code above is the Ticket!!!

Can anyone point me to similar code that grabs the network computer name (and other helpful network environment variables)?

Thanks.
 
Have a look at Allapi.net - ~900 API calls to get all sorts of info about the computer - the one above is also listed on that site Rgds
~Geoff~
 
Hi leuchtag
webstony's own (2nd) post should do this, though I haven't tried it!

Another way is to open a DOS window and type SET | more then <enter>. The middle symbol is the 'pipe' character (shift+\ usually) and you need this as the list may be too long for one window - unless you have win2k!

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Allapi.net completely answers this issue & I found the code for computer name & already created a working module in Access.

Apparently with some networks and/or Access setups &quot;environ&quot; is worthless (gives about 12 autoexec dos variables).

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top