Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Get Windows (system) variable %USERNAME%

Get Windows (system) variable %USERNAME%

Get Windows (system) variable %USERNAME%

Basically, what I want to do is get a system variable %USERNAME% into javascript...!

I started this in another forum and realised it should have been in here!

I have set up a HTA that displays training modules for users WITHIN my office.

The problem I have is finding out what modules each person has actually attempted (even viewing a second of it would suffice!).

Using login scripts, I can place shortcuts (on everyones desktop and/or start menu) to the HTA file.

The HTA file consists of 2 frames:

| Module 1   |                        |
| Module 2   |                        |
| Module 3   |  This is where the     |
| Module 4   |  module loads and      |
|            |  is a video clip       |
|            |  using swf             |
|            |                        |
|            |                        |

When the user clicks on say Module 1, the swf file is loaded into the right frame.

I also want it to write to a file. It doesn't really matter how the files are saved, be it:

| FileName   |  Contents       |
| Aubs.txt   | Module1         |
|            | Module2         |
| Andrew.txt | Module2         |
|            | Module3         |


| FileName   |  Contents       |
| log.txt    | Aubs-Module1    |
|            | Andrew-Module2  |
|            | Andrew-Module3  |
|            | Aubs-Module2    |

I have found this:


    <SCRIPT LANGUAGE='JavaScript'>
      function WriteToFile() {
        try {
          var fso, s;
          fso = new ActiveXObject("Scripting.FileSystemObject");
          s = fso.OpenTextFile("C:\\test.txt" , 8, 1, -2);
          s.writeline("This is a test");
          var strErr = 'Error:';
          strErr += '\nNumber:' + err.number;
          strErr += '\nDescription:' + err.description;
...which writes a file fine.

With batch files, this would be easy, by simply:
echo %USERNAME% - Module 1 >> \\server\folder\log.txt
or even:
echo Completed >> "\\server\folder\%USERNAME% - Module 1.txt"

Great news!

Basically, what I want to do is get a system variable %USERNAME% into javascript...!

Any ideas?



RE: Get Windows (system) variable %USERNAME%


Modulo equal security issue as fso, it is this.

var wshshell=new ActiveXObject("wscript.shell");
var username=wshshell.ExpandEnvironmentStrings("%username%");

regards - tsuji

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close