茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1672811 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00032.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

微軟帝國 : [轉貼]如何透過排定的工作於開機時啟動某程式

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]如何透過排定的工作於開機時啟動某程式
How To Create a Scheduled Task That Runs at Boot Time
02.19.09 | 1 Comment

When you’re automating various Windows activities, sometimes it’s hard to know when you’re finished with one step and can move on to the next one. Case in point: I’m using a deployment product called Altiris to set up Windows on my servers. After Windows setup is complete, I need to make some configuration changes and install some software.

Unfortunately, Altiris tries to do this while Windows installation is still going on. As part of the installation, Altiris installs its agent software, and when the GUI portion of setup begins, this agent is loaded. This causes the rest of the process to fail.

While puzzling out how to work around this, I noticed that once Windows setup is finished but before the job completes, a number of programs are run automatically. Turns out there’s a section of the unattend.txt files called [GuiRunOnce] that specified command lines to be run when a user logs on to Windows for the first time, and if you’re using the AutoLogon parameter and a plain-text password, you can convince Windows to log on automatically.

Wouldn’t it be great (I said to myself) if there was a way I could run a batch file during this phase to create a small flag file on the root of the C: drive so that I could tell setup was complete? And it would have been easy, too, except that the last command rebooted the server. I wanted to create this flag file after the last reboot. As the Grinch said, “But how?”

As it happens it’s pretty simple. There’s a command-line tool called schtasks.exe that allows you to create scheduled tasks, including tasks that run at system start. Just use this syntax:
schtasks /create /tn "TaskName" /tr <task command line> /sc ONSTART /ru system

I hope everything except the /ru parameter should be self-explanatory. That paramter specifies the user to run as, and by using the reserved word “system” you instruct the task to run as the system account.

So I added this command to the [GuiRunOnce] command and added a batch file called SetDoneFlag.bat to my Windows setup files (this is left as an exercise for the reader). I don’t want that batch file run every time the system boots, so I just add this command as the last line:
schtasks /delete /tn "TaskName"

And voila! Now I can check for the existence of C:\DoneFlag.txt, and if it’s there, I know that Windows setup is complete, and I can continue on with the configuration.



原文出處:My Boog Pages » Blog Archive » How To Create a Scheduled Task That Runs at Boot Time
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|