Page 1 of 2
Request of "Getmacid function"
Posted: May 10th, 2013, 11:40 pm
by htuser
Dear Gregory,
I would like to know if it's possible to copy the result of the Getmac command line from Dos and use it inside the Cspro's programming language?
If no, it's possible to create a such function(Getmacid) inside the Cspro's programming language?
I think, it'll be very useful instead of Getusername function in the control of data entry using Tablet PC.
Sincerely yours,
Re: Request of "Getmacid function"
Posted: May 11th, 2013, 12:36 pm
by Gregory Martin
You can do this. Redirect the output of the getmac command to a file and then read it in CSPro. See attached for an example.
My batch command is this:
getmac /fo list > getmac.txt
Then the CSPro code is:
PROC GLOBAL
alpha (100) str;
file inputFile;
PROC GETMAC_FF
preproc
execsystem("getm.bat",wait);
setfile(inputFile,"getmac.txt");
while fileread(inputFile,str) do
if pos("Physical Address: ",str) then
errmsg("MAC Address: %s",str[length("Physical Address: ")]);
endif;
enddo;
close(inputFile);
Re: Request of "Getmacid function"
Posted: May 11th, 2013, 2:14 pm
by htuser
Thanks for this so precious help.But, i would like to know if it's possible to read and store it in Csentry.
Sincerely yours,
Re: Request of "Getmacid function"
Posted: May 25th, 2013, 1:12 pm
by Gregory Martin
The code that I posted will also work in CSEntry.
Re: Request of "Getmacid function"
Posted: May 27th, 2013, 1:17 pm
by htuser
Thanks.
Re: Request of "Getmacid function"
Posted: August 14th, 2013, 12:24 pm
by htuser
Since my request, it's the first time i need to use the logic above in a real situation. The code is used in Csentry and that's ok. It display the Mac adresses in the Warning/error window. But, i would like to store the mac adress in a Csentry's field/item.
Please help me again.
Thanks in advance.
Re: Request of "Getmacid function"
Posted: August 14th, 2013, 1:54 pm
by Gregory Martin
If the above code successfully displays a message, simply assign that string to a field:
MAC_ADDRESS_STRING = str[length("Physical Address: ")];
Re: Request of "Getmacid function"
Posted: August 14th, 2013, 3:03 pm
by htuser
Thanks. You always have good solutions.
But, it store only one mac adress, the last. Can you help me to store two or more?
Regards,
Re: Request of "Getmacid function"
Posted: August 14th, 2013, 4:55 pm
by Gregory Martin
You could write a function to loop through the text file and check if the text "Physical Address" exists using the pos function. Then you could parse those lines of code to extract multiple MAC addresses.
Re: Request of "Getmacid function"
Posted: August 15th, 2013, 12:15 pm
by htuser
Dear Gregory,
Thanks for your precious help. Meanwhile, i'm trying to use code inside Cspro to write a batch.
I create him, but, i can't write the dos code inside, please, can you help me?
Code: Select all
filecreate("\mac_adress\getcode.bat");
filewrite(getcode, "getmac /fo list > getcode.txt");
execsystem("getcode.bat",wait);
setfile(inputFile,"getcode.txt");
while fileread(inputFile,str) do
if pos("Physical Address: ",str) then
errmsg("Le Code est:%s",str[length("Physical Address: ")]);
MAC_ADRESS = str[length("Physical Address: ")];
endif;
enddo;
close(inputFile);
Thanks in advance