/build/static/layout/Breadcrumb_cap_w.png

Scripting - %username% in batch files

Hi,

I'm using a script where i'm piping a command to a text file on around 1000 pc's so for easy individual results i'm piping the command to %username%.txt in a batch file. This works without a problem if I run the command manually on a machine but when I put the command in to a Kace script i just get files generated called .txt instead of bob.txt, mary.txt, jim.txt etc

I understand this is probably due to the command running as the local system account instead of the user logged in.

Any idea on how I can get around this little problem?

Thanks!

Ben.

0 Comments   [ + ] Show comments

Answers (3)

Posted by: airwolf 14 years ago
Red Belt
0
You could write an AutoIt script to perform a RunAs or select a username from a logged on session that isn't the local SYSTEM account. I don't think there is any way you can accomplish your goal using KBOX scripting. Scripts will all run as SYSTEM, and the %username% variable is dependent on the profile the script is run in. You could try using the machine name instead of the username, but if you want the username you'll need to write some VBS or AutoIt to poll logged on users from active sessions.
Posted by: airwolf 14 years ago
Red Belt
0
If you're interested in going the AutoIt route, I've found a function created by an AutoIt user to return the username of the console session (i.e. the person logged on directly to the machine).

http://www.autoitscript.com/forum/index.php?showtopic=102764
Posted by: bwarren33 14 years ago
Senior Yellow Belt
0
%computername% was good enough for me! excellent! thanks!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ