Using execsystem to Retrieve a Computer's Username

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Using execsystem to Retrieve a Computer's Username

Post 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));
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Using execsystem to Retrieve a Computer's Username

Post by Gregory Martin »

Now with CSPro 4.1.002 out, you can use the getusername function instead of using the code above.
Post Reply