in reply to ID of current process (Windows)

$ENV{'USERNAME'} gives me the username of the current user account on Win2K and WinXP. Not sure about Win9X.

Replies are listed 'Best First'.
Re^2: ID of current process (Windows)
by roju (Friar) on Jun 16, 2004 at 15:10 UTC

    Incidently, this assumes that you can trust the current environment. I'm not sure about his application, but someone could just do a set USERNAME=fake_name, and foobar his code. Not to mention if he's using RunAs or somesuch, I have no idea how the Windows environment handles that.

    His use of Win32::LoginName() appears to have been correct.

    From the Win32 pod:

    Win32::LoginName() Returns the username of the owner of the current perl process.

    Tested on Windows XP here, it does what it claims. So yeah, I'd say Win32::LoginName() is what he's looking for.

    Update:Converted pre tags to code tages.