- 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;
- for($i=0;$i -lt $NetName.Count;$i++){
- if($NetName.ifName[$i] -notlike "WiFi*"){$Name=$NetName.Name[$i];break;}
- }
- 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#>
复制代码 不是所有的连接都叫本地连接。我的就叫lan和wlan。 |