[英]Allow Win 10 user to reset network adaptor via PS script without UAC
Firstly: I have found a number of questions answered that do everything but allow me to bypass UAC.首先:我发现了许多问题的答案,它们可以做任何事情,但允许我绕过 UAC。 I am IT for a small business, but it is not my primary responsibility.
我是一家小型企业的 IT,但这不是我的主要职责。
I have two machines in my domain that on startup often fail to correctly connect to the domain network.我的域中有两台机器在启动时经常无法正确连接到域网络。 Restarting the network adapter fixes the issue until the machine restarts.
重新启动网络适配器可修复该问题,直到机器重新启动。 Unfortunately, one of the machines is used by a non-admin, and a technically illiterate one at that.
不幸的是,其中一台机器由非管理员使用,并且是技术文盲。
I hoped to use a powershell script to do this.我希望使用 powershell 脚本来做到这一点。 Using this website, I created script and batch files to solve the issue.
使用这个网站,我创建了脚本和批处理文件来解决这个问题。 Since the computer only has one network adaptor, I went simple: internet.ps1
由于电脑只有一个网卡,我就简单了:internet.ps1
Get-NetAdapter | Restart-NetAdapter
internet.cmd网络命令
@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%internet.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";
Unfortunately, I don't fully understand the last command in the batch file.不幸的是,我不完全理解批处理文件中的最后一个命令。 As such I struggle to research the command to pass some form of user credential.
因此,我努力研究传递某种形式的用户凭据的命令。 This environment is not very secure.
这种环境不是很安全。 But I don't want to give this user domain admin permissions generally, or provide them with some admin credentials which would end up on a sticky note.
但我一般不想给这个用户域管理员权限,或者向他们提供一些最终会出现在便利贴上的管理员凭据。 Either option is just inviting trouble from my older, technically illiterate colleagues.
任何一种选择都只会给我那些技术文盲的年长同事带来麻烦。 And going over to punch in credentials every day is time consuming.
每天都过去打卡凭据非常耗时。
I am looking for a script that cycles the network adaptor and provides the necessary credentials to make that change so a non-admin user can fix their domain and internet access without having admin credentials on a post-it note.我正在寻找一个脚本来循环网络适配器并提供必要的凭据来进行更改,以便非管理员用户可以修复他们的域和 Internet 访问,而无需在便利贴上提供管理员凭据。
You could schedule a task using the Task Scheduler in Windows.您可以使用 Windows 中的任务计划程序来安排任务。 When scheduling a task, you can specify credentials for the task to use when it runs.
计划任务时,您可以指定任务运行时要使用的凭据。 You can add a trigger for this task to have it run when the computer starts, or you can simply allow the user to manually start it.
您可以为此任务添加触发器以使其在计算机启动时运行,或者您可以简单地允许用户手动启动它。
If you decide to go this route, there is a check box you can check that runs the program with the highest possible privileges.如果您决定走这条路线,您可以选中一个复选框,该复选框以尽可能高的权限运行程序。 The entire point of that last line is to start a new PowerShell window that runs as administrator so it actually has permission to restart the adapter.
最后一行的重点是启动一个以管理员身份运行的新 PowerShell 窗口,因此它实际上有权重新启动适配器。 This means that you can get rid of almost your entire script, and just keep the part that actually restarts the adapter.
这意味着您几乎可以去掉整个脚本,而只保留实际重新启动适配器的部分。
For example, when you go to create a new task in Task Scheduler, under the Actions tab, you can create a new action and enter the following:例如,当您在任务计划程序中创建新任务时,在操作选项卡下,您可以创建新操作并输入以下内容:
Program/script:程序/脚本:
PowerShell
Add arguments:添加参数:
-Command "Get-NetAdapter | Restart-NetAdapter"
Start-Sleep
command.
Start-Sleep
命令来执行此操作。
You can add it to the arguments field by doing the following:
\n-Command "Start-Sleep 5; Get-NetAdapter | Restart-NetAdapter"Replace the number 5 with how many seconds you would like it to wait.- 命令“开始-睡眠 5;获取-NetAdapter | 重新启动-NetAdapter”\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.