本帖最后由 WHY 于 2020-11-8 20:02 编辑
PowerShell 脚本,保存为 Test.ps1
执行方法:
1.在 cmd 命令行窗口输入:PowerShell -exec Bypass -File "脚本路径"
2.或者,右键单击脚本,选择使用 PowerShell 运行- function Get-FileMD5($file){
- $stream = [System.IO.File]::Open($file, [IO.FileMode]::Open, [IO.FileAccess]::Read);
- $objMD5 = [System.Security.Cryptography.MD5]::Create('MD5');
- $strMD5 = [BitConverter]::ToString($objMD5.ComputeHash($stream));
- $stream.Close();
- return $strMD5.Replace('-', '');
- }
-
- if( $args[0] -eq $null ){
- start PowerShell -Args ('-Exec Bypass -file "' + $MyInvocation.MyCommand.Path + '" ARG') -Verb RunAs;
- } else {
- gwmi Win32_LogicalDisk -Filter "DriveType='5'" | forEach {
- $file1 = $_.Name + '\setup.exe';
- $file2 = $_.Name + '\configuration.xml';
- if( [IO.File]::Exists($file1) -and [IO.File]::Exists($file2) ){
- $MD5 = Get-FileMD5 $file1;
- if( $MD5 -eq 'C1A8D182A940E751F1C9A506ADA22FE8' ){
- start $file1 -Args ('/configure "' + $file2 + '"') -Wait;
- }
- }
- }
- echo 'Done';
- [Console]::ReadKey();
- }
复制代码
|