Thank you very much, you gave me the Right idea to create a macro based on your Suggestion to fit my Needs.
Command to use it:
CALL GetInfoViaCMD($RETURN_VALUE, "computername")
Functions.inc
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to get Windows Informations with the help of a batch command
// INFO: https://de.wikibooks.org/wiki/Batch-Programmierung:_Batch-Befehle
// IDEA: https://forums.autodesk.com/t5/powermill-forum/variable-command-to-get-hostname/td-p/8989217
//CALL GetInfoViaCMD($RETURN_VALUE, "computername")
FUNCTION GetInfoViaCMD(
OUTPUT STRING ret_info
STRING type
){
//Set paths for temporary files
STRING parentfolder = "C:\Windows\Temp\" //Alternativ: macro_path(0), but in my case its contect is empty/undefined
STRING path_bat = $parentfolder + "temp_GetInfosViaCMD.bat" //batch file which contains the Commands for the questioned informations
STRING path_bat_done= $parentfolder + "temp_GetInfosViaCMD.DONE"//will be created after Batch file commands have been processed, this is needed that our macro waits for the batch file to be processed complety
STRING path_result = $parentfolder + "temp_GetInfosViaCMD.txt" //consists Results exported during Batch Commands
//Delete temporary file, in case it already exists
IF file_exists($path_bat) {
DELETE FILE $path_bat
}
IF file_exists($path_bat_done) {
DELETE FILE $path_bat_done
}
IF file_exists($path_result) {
DELETE FILE $path_result
}
//create Batch Command
//Batch has several lines and will look like:
// (
// ECHO %computername%
// ECHO %username%
// ECHO %userprofile%
// ) > "C:\Windows\Temp\... .txt"
STRING $cmd_lines = '(' +crlf+ 'ECHO %computername%' +crlf+ 'ECHO %username%' +crlf+ 'ECHO %userprofile%' +crlf+ ') > ' + '"'+$path_result+'"'
STRING $cmd_bat_done = 'ECHO BATCH_FILE_DONE > ' + '"'+$path_bat_done+'"'
//create .bat File with the command lines and start batch
FILE OPEN $path_bat FOR WRITE AS "output"
FILE WRITE $cmd_lines TO "output"
FILE WRITE $cmd_bat_done TO "output"
FILE CLOSE "output"
OLE FILEACTION "OPEN" $path_bat
//Open result File written from batch commands and read into internal variable
STRING LIST HostTextList = {}
//wait for Batch processed and creates the .txt File
WHILE NOT file_exists($path_bat_done) {
//wait for .bat file is executed and .DONE file is created as signal to go ahead
}
FILE OPEN $path_result FOR READ AS "results"
FILE READ $HostTextList FROM "results"
FILE CLOSE "results"
//Delete Temporary files:
DELETE FILE $path_bat
DELETE FILE $path_bat_done
DELETE FILE $path_result
//set results from internal variable to output variable depending on type
SWITCH type {
CASE "hostnameANDusername"
$ret_info = "Hostname: " + $HostTextList[0] + " | Username: " + $HostTextList[1]
BREAK
CASE "computername"
CASE "hostname"
CASE "HostName"
$ret_info = $HostTextList[0]
BREAK
CASE "username"
Case "user"
//Alternative exists inside PowerMill: user_id()
$ret_info = $HostTextList[1]
BREAK
CASE "userprofile"
$ret_info = $HostTextList[2]
BREAK
DEFAULT
$ret_info = "error"
BREAK
}
//Close Function
}
- - - - - - - - - - - - - - - - - - - - - - - - - -
kind regards Stefan,
Milling robot integrator | Germany