Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connect / Disconnect WiFi and Hibernate
#1
Note: This post has been edited to place the updated code here.

Network Connect Routine (Does not trigger a Windows UAC response).
Code: (Select All)
Width 36, 3
Color 15, 1: Cls
_Font 16
Locate 2, 2
Print "Connecting to your network...";
Shell _DontWait _Hide "netsh wlan connect name=YOUR WIFI NAME HERE"
_Delay 2
System

Create the exe file, right click it, and send it to your desktop.

Network Disconnect (Triggers a UAC response, but see how to avoid this by pigging backing onto Task Scheduler).
Code: (Select All)
Width 36, 3
Color 15, 1: Cls
_Font 16
Locate 2, 2
Print "Disconnecting from your network...";
Shell _DontWait _Hide "netsh wlan disconnect"
_Delay 2
System

To avoid the UAC, do this...

1) Open Windows Task Scheduler
2) Add a new folder. I named mine: My Network Disconnect
3) Click on the new folder and select to add a 'new task'. I named my new task: Network Disconnect
4) Make sure you check the box: Run with highest privileges
5) In the trigger tab, select to run on login.
6) In the actions tab, set the path and name of your disconnect program. Mine is: c:\my-exe-files\network disconnect.exe
7) Click OK to save the new task.

Next I used File Explorer to view my c:\my-exe-files\network disconnect.exe. I did a right click, selected 'Properties' and checked the box: Run as Administrator

Finally I tested the new task by clicking the "Run" command in the right panel of the Task Scheduler. It disconnected my internet connection, woohoo!

I made a desktop shortcut of Task Scheduler. I right clicked the shortcut and selected Properties.

I changed the Target to: C:\Windows\System32\schtasks.exe /RUN /TN "\My Network Disconnect\Network Disconnect"

The Start in: C:\Windows\System32

I changed the window to run minimized and saved my changes.

When I Double clicked the shortcut icon, woohoo again, it correctly communicated with Task Scheduler and shut off my wifi connection without getting a UAC prompt.

Hibernate PC (No UAC trigger).
Code: (Select All)
Width 36, 3
Color 15, 1: Cls
_Font 16
Locate 2, 2
Print "Hibernating..."
a$ = "shutdown /h"
Shell _DontWait _Hide a$
System

+1 to Steve and Spriggs for getting involved in the discussion. I had to work it out myself this time, but the support is very much appreciated.

Pete

------------------------------------------------------------

ORIGINAL POST TO EXPLAIN DISCUSSION THAT FOLLOWS

I created a desktop icon from the exe file. It works on my Windows 10. What I would like is to get around the UAC prompt it triggers. (User Account Control). I would have to turn UAC off.

I did try to go around it by making a folder in Task Scheduler. So, if I run it from Task Scheduler, directly, it works without a UAC warning, but when I make a desktop shortcut to trigger Task Scheduler to run it, guess what? If you said UAC asks me to verify I want to let Task Scheduler change my computer, you are correct! Anyway, the article I read for doing this Task Scheduler was 11 years old, so my guess is it worked back then, but not today.

If anyone knows another way around it, I'd love to read your post; otherwise, I'll keep on searching and let you guys know if I find anything.
------------------------------------------------------------
Shoot first and shoot people who ask questions, later.
Reply
#2
Did you click the "Run as Admin" tab for it?
Reply
#3
(08-20-2024, 03:38 AM)SMcNeill Wrote: Did you click the "Run as Admin" tab for it?
To the .exe I created, yes. Under the compatibility tab I checked the box Run as Administrator.

Something isn't right with the shortcut, as when I do give it UAC permission, it doesn't launch the task from the scheduler. I know the app works, and I know it is set up correctly in the Task Scheduler, because when I run it directly from the opened Task Scheduler pane, it works.

For fun, I made a shortcut of the task scheduler to the desktop. That simply refreshes all tasks in a command line, without UAC approval. That looked promising, so I changed the path to: C:\Windows\System32\schtasks.exe /RUN /TN "Tasks\My Network Disconnect\Network Disconnect"

So a command window flashes for a millisecond on the screen and closes. That means something is misconfigured somehow, in the shortcut. I hope it isn't that the file I made is a two word file, separated by a space, or the same of the file itself. The path is correct as written: Tasks\My Network Disconnect

Pete
Shoot first and shoot people who ask questions, later.
Reply
#4
This would probably be better to use a batch file for.
Tread on those who tread on you

Reply
#5
I was considering that next.

Start "" C:\Windows\System32\schtasks.exe /RUN /TN "Tasks\My Network Disconnect\Network Disconnect"

Still gets the UAC, even when I right click the .bat file to and choose to Run as Administrator.

Doesn't work as coded, but this is interesting...

Start "" C:\Windows\System32\schtasks.exe

That does run the Task Scheduler, alone, in a command window. So it's the /RUN /TN "Tasks\My Network Disconnect\Network Disconnect" that is coded wrong.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#6
Change the task setting so it runs as an admin and store your credentials in the task. It shouldn't ask for UAC when running after that.
Tread on those who tread on you

Reply
#7
Well, got it working!

I had to make a different path.

C:\Windows\System32\schtasks.exe /RUN /TN "Tasks\My Network Disconnect\Network Disconnect" - Didn't work.

C:\Windows\System32\schtasks.exe /RUN /TN " C:\Windows\System32\Tasks\My Network Disconnect\Network Disconnect" - Didn't work.

C:\Windows\System32\schtasks.exe /RUN /TN "\My Network Disconnect\Network Disconnect" - Worked!

No UAC to contend with by running it through the Task Schedular. Nice!

Pete

Edit: I updated the initial post. It now contains all the info, if I correctly recalled every step, to get this puppy working without UAC interference.
Shoot first and shoot people who ask questions, later.
Reply
#8
(08-21-2024, 12:05 AM)Pete Wrote: Well, got it working!

I had to make a different path.

C:\Windows\System32\schtasks.exe /RUN /TN "Tasks\My Network Disconnect\Network Disconnect" - Didn't work.

C:\Windows\System32\schtasks.exe /RUN /TN " C:\Windows\System32\Tasks\My Network Disconnect\Network Disconnect" - Didn't work.

C:\Windows\System32\schtasks.exe /RUN /TN "\My Network Disconnect\Network Disconnect" - Worked!

No UAC to contend with by running it through the Task Schedular. Nice!

Pete

Edit: I updated the initial post. It now contains all the info, if I correctly recalled every step, to get this puppy working without UAC interference.

Try it with the full network path.  For example, instead of just "C:/" :

"\\Desktop-ucgl6oi\c"

Though instead of "\\Desktop-ucgl6ol\", you'd use your own PC's identifier.
Reply
#9
Nope, no bueno.

The only one it accepts going into trigger Task Scheduler is: \My Network Disconnect\Network Disconnect

It just took some trial and error to get there. Really more time than I wanted to spend, considering how easy it was to write the shell. The neat thing now is I don't have to wait for that DAMN Win10 hover over the network symbol to open. Honestly if I was running that asshole company priority one would be to make everything fast and every new edition faster.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#10
Well I changed the title of the original post to include....

Connecting to your wifi and hibernating your PC.

I made these to cut some time off my slow ASCII laptop. With all the MS bloat running in the background it can take you to 90 seconds for the power or network taskbar symbols to respond. Now I jut click a shortcut and keep doing whatever. No more waiting and no UAC crap to deal with, either.

Again, +1 to Steve and The Spriggs for getting involved and brainstorming with me. I had to pound out the Task Scheduler problem myself, but the support at this forum means a lot. I mean in Steve's case, if I'm drowning, I can always count on him to throw me an inflatable. Sure, it's shaped like an anvil but at least it floats!

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 2 Guest(s)