执行批处理文件以启动WiFi热点作为管理员 [英] Execute batch-file to start wifi hotspot as admin

查看:466
本文介绍了执行批处理文件以启动WiFi热点作为管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Windows 10,我经常必须从 cmd 手动启动一个WiFi热点。所以,我想可能我可以写一些代码,使我不必一次又一次地写命令,但我没有.bat文件的经验。

I'm using windows 10 and I often have to start a wifi hotspot manually from cmd. So, I was thinking maybe I could write some code so that I don't have to write the commands again and again but I have no experience with .bat files.

这是我如何启动热点:


  1. 以管理员身份打开 cmd >
  2. netsh wlan set hostednetwork mode = allow ssid = AdHoc key = password

  3. netsh wlan start hostednetwork

  1. Open cmd as administrator
  2. netsh wlan set hostednetwork mode=allow ssid=AdHoc key=password
  3. netsh wlan start hostednetwork


推荐答案

是将.bat文件作为管理员自动运行,甚至无法右键单击它。您需要将此代码另存为.bat文件:

The hardest part of this is to run a .bat file as admin automatically, without even right-clicking on it. You need to save this code as a .bat file:

@ECHO OFF
:: this tests if the file is running as admin
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (GOTO askAdmin)
GOTO gotAdmin
:askAdmin
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
::from this point you can execute your command as admin
netsh wlan set hostednetwork mode=allow ssid=AdHoc key=password
netsh wlan start hostednetwork

请注意,这会显示以管理员身份运行此程序?在没有管理权限的情况下启动时提示,但是如果您右键单击此批处理文件并选择以管理员身份运行,则应立即执行要执行的命令

Note that this does show the "Run this program as admin?" prompt when started without administrative priviliges, but if you right-click this batch-file and choose run as admin it should immediately execute the command you want it to execute

这篇关于执行批处理文件以启动WiFi热点作为管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆