【发布时间】:2014-02-27 01:53:30
【问题描述】:
我需要以管理员身份在命令提示符下运行命令。我平时使用system()命令发送命令在命令提示符下运行时,我没有Administrator级别的提升。
如何获得管理员级别的权限来运行我的指令?
我可以右键单击 cmd.exe 并选择“以管理员身份运行”以在管理员模式下手动打开命令提示符。
谢谢!
编辑
如果未安装 7-Zip,我正在尝试安装 7-Zip。 (您需要安装“wget”命令(*来自 Cygwin 或 GnuWin32)才能运行下面的代码片段)
use Cwd;
use File::Spec;
my $cwd = getcwd();
my $winpath = File::Spec->catdir($cwd);
if (!(-e "C:\\Program Files\\7-Zip")){
print "\n 7-Zip is not installed. Downloading ... \n";
system("wget http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.20/7z920.exe?r=&ts=1392082197&use_mirror=softlayer-dal"); # SourceForge Mirror
print "\n Installing.. \n\n";
#print "\n Press \"install\" to install the 7-Zip installer on your pC\n\n";
if(-e $winpath."\\7z920.exe"){
system($winpath."\\7z920.exe");
}
}
【问题讨论】:
-
这种检查 7-Zip 的方法有点脆弱 - 如果它安装在其他地方怎么办?更健壮的方法是在 PATH 中搜索它。
-
更强大的是,如果您想要压缩功能,可以使用
Archive::Zip之类的库 - 请参阅 metacpan.org/search?q=zip
标签: windows perl command-prompt perl-module