Test environment: Windows Server 2003 R2
First, Start menu launch item implementation
The user must be logged in to perform.
Test script (Python code):
Copy Code code as follows:
Import time
Fout = open (' E:\\1.txt ', ' W ')
While True:
TMP = '%d-%02d-%02d%02d:%02d:%02d \ r \ n '% time.localtime () [0:6]
Print tmp
Fout.write (TMP)
Fout.flush ()
Time.sleep (5)
1. General operation
1.1 Create shortcuts;
1.2 Put the shortcut you created into the Start menu start item;
1.3, power-on verification;
2. Hide Command Line window start
The above operation method has the command line window, some occasions do not feel very practical, we can remove the command line window in the following two ways.
2.1 Change the file name extension of the Python script to ". Pyw"
Other actions are similar to the above process and are not discussed here.
2.2 Starts with a script such as a VBS
The VBS code is as follows:
Set ws = CreateObject ("Wscript.Shell")
Ws.run "Cmd/c E:\test1.py", vbhide
The path is configured according to the situation, and the rest is similar to the previous operation, and is no longer detailed here.
If you don't want to use a shortcut, put the script directly into the startup item.
Report:
Configure account Login automatically
By starting menu Startup items to implement, you must ensure that the user login system, here is an account of automatic login method.
A, type "Rundll32 Netplwiz.dll,usersrundll" in the Run box;
b, open user account interface, will be "to use this machine, users must enter user name and password" before the check out, press "OK" to enter the need to automatically login username and password;
Second, the boot script
You cannot use loops, preferably configuring timeout times.
Test code (Python):
Copy Code code as follows:
Import time
Fout = open (' E:\\1.txt ', ' W ')
TMP = '%d-%02d-%02d%02d:%02d:%02d \ r \ n '% time.localtime () [0:6]
Print tmp
Fout.write (TMP)
Fout.close ()
The steps are as follows:
A, run the input gpedit.msc Open Group Policy Editor;
B, select "Computer Configuration" => "Windows Settings" => "Script" => "startup" option;
C, select the script;
D, configure the maximum wait time for the script, the path is "Computer Configuration" => "=>" System "=>" script "=>" The maximum wait time for Group Policy scripts;
Third, call the script through a service
A, write the script to start the service Servicestartshell, the code is as follows (this only lists the code for the main function):
Copy Code code as follows:
int main (int argc,char* argv[])
{
Init ();
dwThreadID = GetCurrentThreadID ();
Service_table_entry st[] =
{
{szservicename, (lpservice_main_function) ServiceMain},
{NULL, NULL}
};
printf ("argc =%d \ n", argc);
if ((4 = argc) && 0 = = stricmp (argv[3], "/install"))
{
Install (argv[1],argv[2]);
Writereg (argv[1],argv[2]);
}
else if ((2 = argc) && 0 = = stricmp (argv[1], "/uninstall"))
{
Uninstall ();
}
Else
{
if (! StartServiceCtrlDispatcher (ST))
{
printf ("Register Service Main Function error!");
}
}
return 0;
}
b, service installation;
Copy Code code as follows:
ServiceStartShell.exe C:\Python27\python.exe E:\test1.py/install
C, the service uninstall;
Copy Code code as follows:
Servicestartshell.exe/uninstall