加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl获取当前系统用户名以及其他

发布时间:2020-12-16 00:20:23 所属栏目:大数据 来源:网络整理
导读:http://hi.baidu.com/study_cs/item/03d6ce26d8b58e4247996223 在perl中获取当前登陆的用户名,要求在windows和linux下都可用.通过读取系统的环境变量实现,在xp和linux下测试通过,代码如下:? ? ? my $Sys_name = $^O; ? ? if ($Sys_name =~ /MSWin32/){ ? ?

http://hi.baidu.com/study_cs/item/03d6ce26d8b58e4247996223

在perl中获取当前登陆的用户名,要求在windows和linux下都可用.通过读取系统的环境变量实现,在xp和linux下测试通过,代码如下:?
? ? my $Sys_name = $^O;
? ? if ($Sys_name =~ /MSWin32/){
? ? ? ? print $ENV{'USERNAME'},"n";
? ? }
? ? else {
? ? ? ? if($Sys_name =~ /linux/){
? ? ? ? ? ? print $ENV{'USER'},STHeiti; font-size:14px; line-height:21px">? ? ? ? }?
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? print "Unknown";
? ? ? ? }
? ? }

摘自:http://rainbird.blog.51cto.com/211214/149961

?

其他:http://www.cnblogs.com/royenhome/archive/2010/07/21/1782019.html

1、获取操作系统版本信息
? ? ?use Win32;
? ? ?use strict;
? ? ?($OS_string,$OS_major,$OS_minor,$OS_build,$OS_id) = Win32::GetOSVersion(); ?
2、获取系统目录
? ? ?my $systemdir= Win32::GetFolderPath(0x0025) if(Win32::GetFolderPath(0x0025));
? ? 在xp系统下$systemdir的变量值为C:WindowsSystem32
3、获取Windows目录
? ? our $windir = Win32::GetFolderPath(0x0024) if(Win32::GetFolderPath(0x0025));
? ? xp系统下$windir的变量值为C:WINDOWS
4、获取系统所在的磁盘驱动号

? ? ?our $rootdir= $ENV{SYSTEMDRIVE} if($ENV{SYSTEMDRIVE}); ? ? ?xp系统下$rootdir的变量值为C:,因为我机器操作系统装在C盘 5、获取执行程序当前目录 ? ? ?our $currentdir = Win32::GetCwd() if(Win32::GetCwd); 6、获取用户的document文件夹 ? ? ?our $alldocuments = Win32::GetFolderPath(0x002e) if(Win32::GetFolderPath(0x002e)); ? ? ?xp系统下,$documents的变量值为C:Documents and SettingsAll UsersDocuments 7、获取临时文件夹目录 ? ? ?our $tempdir = $ENV{TEMP} if($ENV{TEMP}); 8、获取当前用户启动文件夹目录 ? ? our $mystartup = Win32::GetFolderPath(0x0007) if(Win32::GetFolderPath(0x0007)); 9、获取所用用户启动文件夹目录 ? ? ?our $allstartup = Win32::GetFolderPath(0x0018) if(Win32::GetFolderPath(0x0018)); 10、获取Program Files文件夹目录 ? ? ?our $programdir = Win32::GetFolderPath(0x0026) if(Win32::GetFolderPath(0x0026)); 11、获取AppData文件夹目录 ? ? ? our $myappdata = Win32::GetFolderPath(0x001a) if(Win32::GetFolderPath(0x001a)); 12、获取Desktop文件夹目录 ? ? ?our $mydesktop = Win32::GetFolderPath(0x0010) if(Win32::GetFolderPath(0x0010)); 13、获取当前用户Favorite文件夹目录 ? ? ?our $myfavorites = Win32::GetFolderPath(0x0006) if(Win32::GetFolderPath(0x0006)); 14、获取所有用户的Favorite文件夹目录 ? ? ?our $allfavorites = Win32::GetFolderPath(0x001f) if(Win32::GetFolderPath(0x001f)); 15、获取启动菜单文件夹目录 ? ? our $mystartmenu = Win32::GetFolderPath(0x000b) if(Win32::GetFolderPath(0x000b)); 16、获取计算机名称 ? ? our $computername = Win32::NodeName() if(Win32::NodeName()); 17.、获取当前系统登录用户名 ? ? our $username = Win32::LoginName() if(Win32::LoginName());

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读