Kbase P17565: How to access the computer name using DOS NET OS-COMMAND?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  30/01/2003 |
|
Status: Unverified
GOAL:
How to access the computer name using DOS NET OS-COMMAND?
FIX:
The DOS NET command returns the computer name, the user name and a few other bits of information in the form of separate lines. These lines, if not blank, will each consist of a property, value pair. Any of these properties and/or values may be extracted via slight modifications to the Progress 4GL code below.
In this code the output of the NET command is sent to a temporary file where it will be read and processed one line at a time.
Since only the computer name is of interest in this case, the line beginning with "Computer name" is processed by truncating the string "Computer name" and trimming the resulting string to obtain the computer name as desired.
/* Sample code */
DEFINE VARIABLE cTempFilename AS CHARACTER NO-UNDO.
DEFINE VARIABLE cComputerName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPropertyName AS CHARACTER NO-UNDO.
OS-COMMAND SILENT "net config workstation > cNetConfig.txt".
ASSIGN
cTempFilename = "cNetConfig.txt"
cPropertyName = "Computer name".
INPUT FROM VALUE( cTempFilename ) NO-ECHO.
REPEAT:
IMPORT UNFORMATTED cComputerName.
IF cComputerName BEGINS cPropertyName THEN
DO:
cComputerName = TRIM(SUBSTRING(cComputerName,INDEX(cComputerName,cPropertyName) + LENGTH(cPropertyName))).
MESSAGE cComputerName
VIEW-AS ALERT-BOX INFO BUTTONS OK.
LEAVE.
END.
END.