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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here is a quickie

Status
Not open for further replies.

Mike Gagnon

Programmer
Apr 6, 2002
8,067
CA
To get the computer name

Code:
Shell = CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
MESSAGEBOX(compname)



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
Is that really easier than
Code:
messagebox(GETENV("COMPUTERNAME"))
Note: Not all OSs set a COMPUTERNAME environment variable!

Rick

 
Rick

I always try to use FoxPro outside of the regular everyday usage. You are right that ther is an internal function that does similar things, but its always nice to know that there are other ways.. Here are more values to retrieve.
Code:
Shell = CreateObject("WScript.Shell")
lcStr = "Computer name: "+Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")+CHR(13)
lcStr=lcStr+ "OS: "+Shell.ExpandEnvironmentStrings("%OS%")+CHR(13)
lcStr=lcStr+ "Paths :" +Shell.ExpandEnvironmentStrings("%PATH%")+CHR(13)
lcStr=lcStr+ "Home Path: "+Shell.ExpandEnvironmentStrings("%HOMEPATH%")+CHR(13)
lcStr=lcStr+ "ClientName : "+Shell.ExpandEnvironmentStrings("%CLIENTNAME%")+CHR(13)
lcStr=lcStr+ "Temp directory :" +Shell.ExpandEnvironmentStrings("%TMP%")+CHR(13)
MESSAGEBOX(lcStr)




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
One more:

Code:
CompName = UPPER(ALLTRIM(LEFT(SYS(0),AT("#",SYS(0))-1)))

Issuing SYS(0) alone will give you computer name AND current user name.

Gerardo Czajkowski
ltc.jpg
 
While we're at it:

Code:
o=CREATEOBJECT("mswinsock.winsock")
ComputerName = o.LocalHostName

Andy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top