perl获取当前系统用户名以及其他
http://hi.baidu.com/study_cs/item/03d6ce26d8b58e4247996223 在perl中获取当前登陆的用户名,要求在windows和linux下都可用.通过读取系统的环境变量实现,在xp和linux下测试通过,代码如下:? 摘自:http://rainbird.blog.51cto.com/211214/149961 ? 其他:http://www.cnblogs.com/royenhome/archive/2010/07/21/1782019.html 1、获取操作系统版本信息 ? ? ?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()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |