- if ($true){}# == ($true){}# goto ___yiwuyun
- <#BeginBatOperation#
- :___yiwuyun
- @echo off&setlocal&cls
- if "%~1"=="true" (
- (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$false&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
- call :MainBatOperation
- ) else (
- (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$true&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
- )
- exit/b 0
-
- :MainBatOperation
- echo 以管理员权限运行的批处理操作
-
- exit/b 0
-
- #EndBatOperation#>
-
-
- <#StartPowerShell#>
-
- Function RunAsAdmin{
- $AdminPrivilege=New-Object -ComObject "Shell.Application";
- $AdminPrivilege.ShellExecute("cmd.exe","/c $yiwuyun_fileName true",0,"runas",1);
- }
-
- Function RunMainProgram{
- $NetName=Get-NetAdapter -Physical;
- $Name=$NetName|%{if($_.ifName -notlike "WiFi*"){$_.Name;}}
- netsh interface ipv4 set address name=$Name source=dhcp
- netsh interface ipv4 set dnsservers name=$Name source=dhcp register=primary
- }
-
- if($BoolAdmin){
- RunAsAdmin;
- }else{
- RunMainProgram;
- }
-
-
- <#EndPowerShell#>
复制代码
|