Request of "Getmacid function"

Discussions about CSEntry
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Request of "Getmacid function"

Post 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,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Request of "Getmacid function"

Post 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);
Attachments
getmac.zip
(2.22 KiB) Downloaded 449 times
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Request of "Getmacid function"

Post 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,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Request of "Getmacid function"

Post by Gregory Martin »

The code that I posted will also work in CSEntry.
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Request of "Getmacid function"

Post by htuser »

Thanks.
G.VOLNY, a CSProuser from Haiti, since 2004
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Request of "Getmacid function"

Post 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.
Last edited by htuser on August 14th, 2013, 3:09 pm, edited 1 time in total.
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Request of "Getmacid function"

Post 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: ")];
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Request of "Getmacid function"

Post 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,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Request of "Getmacid function"

Post 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.
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Request of "Getmacid function"

Post 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
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply