[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. if ($true){}# == ($true){}# goto ___yiwuyun
  2. <#BeginBatOperation#
  3. :___yiwuyun
  4. @echo off&setlocal&cls
  5. if "%~1"=="true" (
  6. (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$false&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  7. call :MainBatOperation
  8. ) else (
  9. (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$true&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  10. )
  11. exit/b 0
  12. :MainBatOperation
  13. echo 以管理员权限运行的批处理操作
  14. exit/b 0
  15. #EndBatOperation#>
  16. <#StartPowerShell#>
  17. Function RunAsAdmin{
  18. $AdminPrivilege=New-Object -ComObject "Shell.Application";
  19. $AdminPrivilege.ShellExecute("cmd.exe","/c $yiwuyun_fileName true",0,"runas",1);
  20. }
  21. Function RunMainProgram{
  22. $NetName=Get-NetAdapter -Physical;
  23. for($i=0;$i -lt $NetName.Count;$i++){
  24.    if($NetName.ifName[$i] -notlike "WiFi*"){$Name=$NetName.Name[$i];break;}
  25. }
  26. netsh interface ipv4 set address name=$Name source=dhcp
  27. netsh interface ipv4 set dnsservers name=$Name source=dhcp register=primary
  28. }
  29. if($BoolAdmin){
  30. RunAsAdmin;
  31. }else{
  32. RunMainProgram;
  33. }
  34. <#EndPowerShell#>
复制代码
不是所有的连接都叫本地连接。我的就叫lan和wlan。

TOP

  1. if ($true){}# == ($true){}# goto ___yiwuyun
  2. <#BeginBatOperation#
  3. :___yiwuyun
  4. @echo off&setlocal&cls
  5. if "%~1"=="true" (
  6. (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$false&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  7. call :MainBatOperation
  8. ) else (
  9. (echo $yiwuyun_fileName="%~f0"&echo $BoolAdmin=$true&echo $strPath="%~dp0"&type "%~f0")|powershell -command -
  10. )
  11. exit/b 0
  12. :MainBatOperation
  13. echo 以管理员权限运行的批处理操作
  14. exit/b 0
  15. #EndBatOperation#>
  16. <#StartPowerShell#>
  17. Function RunAsAdmin{
  18. $AdminPrivilege=New-Object -ComObject "Shell.Application";
  19. $AdminPrivilege.ShellExecute("cmd.exe","/c $yiwuyun_fileName true",0,"runas",1);
  20. }
  21. Function RunMainProgram{
  22. $NetName=Get-NetAdapter -Physical;
  23. $Name=$NetName|%{if($_.ifName -notlike "WiFi*"){$_.Name;}}
  24. netsh interface ipv4 set address name=$Name source=dhcp
  25. netsh interface ipv4 set dnsservers name=$Name source=dhcp register=primary
  26. }
  27. if($BoolAdmin){
  28. RunAsAdmin;
  29. }else{
  30. RunMainProgram;
  31. }
  32. <#EndPowerShell#>
复制代码

TOP

返回列表