ID of current process (Windows)
qadwjoh
created: 2004-06-16 09:40:45
Hi,

I need to verify the user ID my Perl script is running under - is this what is returned by Win32::LoginName()?

Also I have general Windows scripting question: my Perl script is being launched in a .bat file (by an automated system) - will it be run under the same ID as the .bat file is?

thanks,
Q
Re: ID of current process (Windows)
created: 2004-06-16 09:56:47

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

Re^2: ID of current process (Windows)
created: 2004-06-16 11:10:11

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.

Re: ID of current process (Windows)
created: 2004-06-16 09:59:45
Yes, your perl script will run under the same user account as your batch file. To get the username, you can use $ENV{USERDOMAIN} and $ENV{USERNAME} or Win32::LoginName()

perlmonks.org content © perlmonks.org and data64, meetraz, qadwjoh, roju

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03