Page 1 of 1

Using execsystem to Retrieve a Computer's Username

Posted: June 29th, 2011, 1:14 am
by Gregory Martin
An example of when this could be useful is if you want to create a PFF file with the data file named after the login ID of the keyer who has logged onto that machine.
PROC GLOBAL

alpha (20) tempFilename = "tempusername.txt";
alpha (300) str;
FILE inputFile;

alpha (50) username;

PROC EXAMPLE

execsystem(maketext('cmd /c "set username > %s"',strip(tempFilename)),wait);

setfile(inputFile,strip(tempFilename));
fileread(inputFile,str);
close(inputFile);

filedelete(strip(tempFilename));

// str looks like this: USERNAME=pedro

username = str[
poschar("=",str) + 1];

errmsg("Computer username is %s",strip(username));

Re: Using execsystem to Retrieve a Computer's Username

Posted: December 19th, 2011, 11:56 pm
by Gregory Martin
Now with CSPro 4.1.002 out, you can use the getusername function instead of using the code above.