Hey everyone! I'm looking for some help with creating a desktop shortcut on my laptop that I can double or right-click to run the command `Restart-NetAdapter -Name Ethernet`. Lately, when I leave my laptop overnight, the ethernet stops working in the morning, and I think it's due to my router restarting. I can fix the issue by running the command in an admin terminal, but if I try it in a regular terminal, I get an 'Access is denied' error (CimException, Windows System Error 5). I'm not very experienced with PowerShell, so I'm hesitant about implementing some of the solutions I've seen online. If I have to copy and paste commands every time, it's okay—I'm just trying to save some steps here. Thanks in advance!
5 Answers
You can create a PowerShell script to run without admin privileges, which then triggers your primary script as admin. Here’s how it goes: in your first script, write `Start-Process powershell.exe -Verb RunAs -ArgumentList "-file Path/to/your/actualScript.ps1"`. This way, you can right-click and select 'Run with PowerShell' to execute it.
You definitely need to elevate permissions for this. You could create a shortcut and set it to auto-elevate since that's a Windows function, not just PowerShell. For PowerShell, use `Start-Process` with the `-Verb` option. You can find more about it by using `Get-Help`. This will start an elevated PowerShell session that runs the `Restart-NetAdapter`. Just a heads up, this assumes your daily account has admin rights, which might not be ideal, so consider fixing the root of the problem too!
Search for PowerShell on your system, right-click, and choose 'Open file location.' Then copy that shortcut to your desktop. Edit the shortcut's properties, adding `-Command "Restart-NetAdapter"` at the end. In the advanced settings, you have the option to make it run as admin. Alternatively, consider setting this up as a scheduled task that runs under the SYSTEM account at logon; that will automate the process for you! Also, it's worth checking that your network drivers are up-to-date—visit your motherboard's website for the latest downloads. Plus, you might want to prevent your adapter from going to sleep or using power-saving modes.
Next time your connection drops, try using `ipconfig /renew` from the command prompt and let us know if that fixes things. It might help!
Make sure to check the power settings on your network adapter. You can find more information on how to manage power in this Microsoft article.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures