📜 ⬆️ ⬇️

Autostart PPPoE connection without logging in to your account

I would like to tell you about one trick that can be done using Task Scheduler in Windows.
I have Windows 7 installed, and also have a PPPoE connection from our city cable provider.
The task is to enable this connection immediately after the connection to the local network rises in Windows, and the user may not even be logged in to his account yet.
Most of the instructions that can be found in runet are reduced to the removal of the shortcut connection in the autorun. Here is another case. It is necessary that the connection be made before logging in to the user account.
Looking ahead, I will say that in the same way you can do the execution of any other command, not only when connected to any wired network, but also to Wi-Fi.
I give a complete description, with a bunch of screenshots, as for beginners.

So, what we have is:
• Windows, in which there are several accounts (I have created another account for clarity), and you do not want to make an auto login to any of them.

• Connection using PPPoE, which must be enabled immediately after initialization of the desired network.
• There is no router that would solve this problem in the bud, independently connecting and distributing the Internet to computers on the local network. Well, or the router is not needed in principle.

We find out the unique connection identifier (GUID)


We go to the "Start" - "Control Panel" - "System and Security" - below the "Administration" select "View event logs."

In the window that opens, on the left, we go along this path: “Application and service logs” / “Microsoft” / “Windows” / “Network Profile” / “Running”, we find lines with the event code “10000” there.

Among them we find the one that belongs to the desired network, I have this "Network 2". Switch to the "Details" tab, and here it is, the GUID we need.

You can immediately turn on "XML mode", and view a piece of the XML-representation " ... ".

As another option, you can find the desired GUID in the registry by the following path:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ NetworkList \ Profiles

The GUID I need is “{80362A4A-DAFB-4B7E-B00C-22AC773E35A3}”.
Example of an XML representation of the event:
 <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-NetworkProfile" Guid="{FBCFAC3F-8459-419F-8E48-1F0B49CDB85E}" /> <EventID>10000</EventID> <Version>0</Version> <Level>4</Level> <Task>0</Task> <Opcode>0</Opcode> <Keywords>0x4000200000000000</Keywords> <TimeCreated SystemTime="2013-04-28T11:26:41.252839400Z" /> <EventRecordID>157</EventRecordID> <Correlation /> <Execution ProcessID="572" ThreadID="1664" /> <Channel>Microsoft-Windows-NetworkProfile/Operational</Channel> <Computer>HWin7VM0-PC</Computer> <Security UserID="S-1-5-19" /> </System> <EventData> <Data Name="Name"> 2</Data> <Data Name="Description"></Data> <Data Name="Guid">{80362A4A-DAFB-4B7E-B00C-22AC773E35A3}</Data> <Data Name="Type">0</Data> <Data Name="State">17</Data> <Data Name="Category">1</Data> </EventData> </Event> 

Here I see that the Network 2 network profile has been connected, and I see its GUID in the string " {80362A4A-DAFB-4B7E-B00C-22AC773E35A3} ".

Create a .bat file


You should make sure that you have a PPPoE connection configured so that all users can use it if you want the connection to be made from the System user or from another account. This is necessary for the case when the account that you usually use does not have a login password. Later I will remind about it again.
I assume that you have already configured the connection, the only thing that needs to be done is to create a .bat file in which you will need to write
rasdial MyDearProvider login password
where rasdial is a console application with which you can establish a connection, “MyDearProvider” is the name of the PPPoE connection to be connected, and “login” and “password”, respectively, are the login and password for the connection. Immediately in the console you can check whether you are connecting to the Internet by running this file, or you can do without the console by setting the “pause” command in the next line and running the file, but do not forget to remove the pause command afterwards, when you achieve launching a .bat file will result in an internet connection.
')

Create a task in the scheduler


We go to “Start” - “Control Panel” - “System and Security” - at the bottom, under “Administration”, select “Task Schedule”.

The task scheduler will start, where you have to select “Task Scheduler Library” on the left, and in the right part of the window click “Create task ...”.

In the window that opens, on the “General” tab, fill in the “Name”, for example, “Autoconnect_MyDearProvider”; in the “Security Settings” below, select the desired user from whom the connection will be made, then “Perform regardless of user registration”, however, if user there is no password to log into the account, the connection will not be made if the user is not logged in. In case you do not have an account password, select “system” as the user. The highest rights for the task are not needed.

The tab "Triggers" will be the most interesting. Press the “Create” button, in the window that opens, in the “Start task:” drop-down list, select “At event”.
In the “Advanced Parameters” you can set up a delayed launch, I set 15 seconds, but then I changed this value for 5 seconds, because I was tired of waiting when I tested all this.
In the "Parameters" select "Custom", just to the right click "Create an event filter".

A window for creating an event filter appears. You can fill the frame for the filter with the tools presented on the “Filter” tab, and then go to the XML representation of the created filter.
Select the following in the event log field: “Applications and Services Logs” / “Microsoft” / “Windows” / “Network Profile” / “Running”. We put near the "Running" daw.

Then select “NetworkProfile” as the source of events.
Event code indicate "10000".
It should look like this:

Go to the tab "XML", and see the following:

It is necessary to edit this, otherwise the trigger will trigger on the connection in general of any network, even on the connection of the PPPoE connection itself.
Click on the checkbox "Edit request manually."
A warning will appear that in the future we will not be able to use the "Filter" tab to configure this filter, agree to continue by clicking "Yes". We get the following:

In the place where I have the cursor (right before the closing tag), I need to add one more condition.
We add there " and *[EventData[Data[@Name='Guid']='{80362A4A-DAFB-4B7E-B00C-22AC773E35A3}']] ", changing my GUID "{80362A4A-DAFB-4B7E-B00C-22AC773E35A3} On some kind of your own.

Click OK to close the filter settings window, and OK again to close the trigger settings. You can select a newly created trigger, click “Edit ...”, and make sure that the “Defer to:” setting is enabled in the advanced parameters with the right amount of time, for some reason I did not save this option the first time.
On the “Actions” tab, click “Create”, in the window that opens, select “Run program”, then click “Browse ...”, and specify where our .bat file is located. By the way, instead of creating a .bat file, you could just write a rasdial command in the “Program or Script” field, and enter “MyDearProvider login password” in the field with arguments, it would be equivalent to launching the .bat file. However, it seems to me that it is more convenient to edit a text file than to wander through the settings of the task scheduler in search of the desired field.

Click OK, and then go to the "Conditions" tab.
Here we remove the checkbox "Run only when powered from the mains", if it is not necessary. Set the option "Run only when connected to the following network:" - set the network that you just configured. This is not necessary, since the filter configured earlier already contains this condition, however, it is not enough that something can go wrong, I decided to leave this setting enabled.

And finally, the "Settings" tab. Here you can leave "Enable task on demand" and "Forced stop of the task if it does not stop on request." It is necessary to remove the checkbox from "Stop a task that is running longer:".
In order to avoid such a case as “it is impossible to connect the first time”, you can enable the checkbox “On failure of execution, restart after:”, and set a waiting period, for example, 1 minute. I put the number of restart attempts 6. I think it should be connected in 6 minutes.

Finally, click "OK", and get the necessary.

On the right you need to click on the caption “Enable log of all tasks”, this will help when debugging the execution of the task. After setting the log can be disabled.
Go to the "Network and Sharing Center".

From the left click "Change adapter settings", and get into the "Network Connections". Select "Local Area Connection", disable it. Then re-enable and wait for 15 seconds (or as many as configured in the trigger). After a while, the status of the connection should change under the name PPPoE-connection, and the event scheduler is more or less described in the task scheduler log.
Then you can check how the computer behaves by restarting it, and waiting for the invitation to select a user to appear. If you wait some time without choosing a user, the Windows should still connect to PPPoE, even if no user is logged in. If you have a static IP address, then it is easier to verify that the computer is connected to the Internet. In my case, the IP address is issued dynamically, so I use the DDNS service.
So, we note how much time is now, so that later we know where to look at the logs in the task log and restart the computer.
Unfortunately, in the case when the task is performed from the system or from another user, it will be possible to disconnect the PPPoE connection only by executing the “rasdial MyDearProvider / disconnect” command from the administrator.

Conclusion


For what you need it - decide for yourself. For example, I needed this in order to access the computer via VNC and be able to reboot it if necessary.
For those who want to experiment with a WiFi connection - the necessary log is here: “Application and service logs” / “Microsoft” / “Windows” / “WLAN-AutoConfig” / “Operational”. There you can catch a connection to some WiFi-network by its SSID.
UPD : Here lies one “but”: the code 10000 is not recorded in the NetworkProfile log if Windows exits from hibernation. However, Windows 7 writes event number 300 to the Microsoft-Windows-Diagnostics-Performance log . You can simply add another trigger to enable the task. This is quite applicable if the computer is stationary.

Materials used in this topic:


superuser.com/questions/262799/how-to-launch-a-command-on-network-connection-disconnection - a description of creating a task with its own filter.
social.technet.microsoft.com/Forums/en-US/winservergen/thread/fac16f3c-d088-4d66-83d8-7139261dea83 - How to trace a network when an error occurs. Approximately the same as on the previous link, only descriptions a little more.
superuser.com/questions/92414/how-to-run-a-program-when-connecting-to-a-specific-network-in-windows-7 - a case with a WiFi connection.

Source: https://habr.com/ru/post/178313/


All Articles