Test environment: windows Server 2003 R2
I. Start menu startup item realization
The user must be logged in to execute.
Test script (python code):
import time
fout = open('e:\\','w')
while True:
tmp = '%d-%02d-%02d %02d:%02d:%02d \r\n' % ()[0:6]
print tmp
(tmp)
()
(5)
1. Routine operation
1.1 Creating shortcuts;
1.2 Place the created shortcut into the Start Menu startup item;
1.3. Power-on verification;
2、Hide the command line window to start
The above operation method has a command line window, some occasions feel less practical, we can remove the command line window by the following two ways.
2.1 Changing the file extension of python scripts to ".pyw"
Other operations are similar to the above process and will not be repeated here.
2.2 Starting via scripts like vbs
The vbs code is below:
Set ws = CreateObject("")
"cmd /c E:\",vbhide
Path to configure according to the specific circumstances, the other and the previous operation is similar, and will not repeat here.
If you don't want to use a shortcut, it's fine to put the script directly into the startup item.
Attachment:
Configure account auto-login
Through the start menu startup items to realize the words, must be carried out accordingly to ensure that the user logs on to the system, here is a way to automatically log on to the account.
a. Type "Rundll32 ,UsersRunDll" in the Run box;
b. Open the user account interface, remove the check mark in front of "To use this machine, the user must enter a user name and password", press "OK" and then enter the user name and password that you need to log in automatically;
II. Start-up scripts
You can't use a loop, and it's best to configure a timeout.
Test code (python):
import time
fout = open('e:\\','w')
tmp = '%d-%02d-%02d %02d:%02d:%02d \r\n' % ()[0:6]
print tmp
(tmp)
()
The steps are as follows:
a. Open the Group Policy Editor by typing in Run;
b. Select the "Computer Configuration" = & gt; "Windows Settings" = & gt; "Scripting" = & gt; "Startup " option;
c. Select the script;
d. Configure the maximum waiting time for scripts, the path is "Computer Configuration" = > "Administrative Templates" = > "System" = > "Scripts" = > "Maximum Waiting Time for Group Policy Scripts"; "Scripts" = > "Maximum Waiting Time for Group Policy Scripts". "Scripts" = > "Maximum Wait Time for Group Policy Scripts";
III. Calling the script through a service
a. Write a script to start the service serviceStartShell, the code is as follows (only the code of the main function is listed here):
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;
C:\Python27\ e:\ /install
c. Service offloading;
/uninstall