PDA

View Full Version : آموزش: روشن کردن کامپیوتر از حالت sleep



ali.rk
پنج شنبه 07 شهریور 1392, 22:51 عصر
سلام خوبید ؟
برای روشن کردن کامپیوتر ابتدا فایل taskschd.dll رو باید به Reference اضافه کنید .
C:\Windows\System32 مکان وجود taskschd.dll
109907
109908
یه دکمه هم بندازید.
حا لا نوبت کده (البته این کد کامل نیست ) :
Imports TaskScheduler
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim taskService As ITaskService = New TaskScheduler.TaskScheduler()
' Connect to the TaskService
taskService.Connect()
' Create a new task definition and assign properties
Dim taskDefinition As ITaskDefinition = taskService.NewTask(0)
taskDefinition.Settings.MultipleInstances = _TASK_INSTANCES_POLICY.TASK_INSTANCES_IGNORE_NEW
taskDefinition.RegistrationInfo.Description = "Testing the creation of a scheduled task via VB .NET"
taskDefinition.Principal.LogonType = _TASK_LOGON_TYPE.TASK_LOGON_S4U
taskDefinition.Settings.Hidden = False ' Set to True when running task should be hidden
' NOTE: When Hidden is true, it does not work if _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN
' is used as parameter to RegisterTaskDefinition
'
'
' Add a trigger that will fire the task every other day
taskDefinition.Settings.WakeToRun = True
taskDefinition.Settings.Priority = 7
Dim taskTrigger As IDailyTrigger = _
DirectCast(taskDefinition.Triggers.Create _
(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY), IDailyTrigger)
' Set to start ten minutes from now
taskTrigger.StartBoundary = _
DateTime.Now.AddMinutes(10).ToString _
("yyyy-MM-ddThh:mm:ss" & _
TimeZone.CurrentTimeZone.GetUtcOffset(Now).ToStrin g.Substring(0, 6))
' Rerun the task every other day
taskTrigger.DaysInterval = 2

' Create the Task action
Dim taskAction As IExecAction = _
DirectCast(taskDefinition.Actions.Create(_TASK_ACT ION_TYPE.TASK_ACTION_EXEC), IExecAction)
' The Path to the program
taskAction.Path = "C:\windows\notepad.exe"
' Set Arguments
taskAction.Arguments = ""
taskAction.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments)

' Register the task in the Task Scheduler's root folder
Const taskName As String = "Testing creation of a scheduled task"
Dim rootFolder As ITaskFolder = taskService.GetFolder("\")
rootFolder.RegisterTaskDefinition( _
taskName, taskDefinition, _
CInt(_TASK_CREATION.TASK_CREATE_OR_UPDATE), _
"MyUsername", "MyPassword", _
_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN_OR_P ASSWORD)
' Clean up the COM variables
While System.Runtime.InteropServices.Marshal.ReleaseComO bject(rootFolder) <> 0
Application.DoEvents()
End While
rootFolder = Nothing
While System.Runtime.InteropServices.Marshal.ReleaseComO bject(taskTrigger) <> 0
Application.DoEvents()
End While
taskTrigger = Nothing
While System.Runtime.InteropServices.Marshal.ReleaseComO bject(taskAction) <> 0
Application.DoEvents()
End While
taskAction = Nothing
While System.Runtime.InteropServices.Marshal.ReleaseComO bject(taskDefinition) <> 0
Application.DoEvents()
End While
taskDefinition = Nothing
While System.Runtime.InteropServices.Marshal.ReleaseComO bject(taskService) <> 0
Application.DoEvents()
End While
taskService = Nothing
GC.Collect() ' Start .NET CLR Garbage Collection
GC.WaitForPendingFinalizers() ' Wait for Garbage Collection to finish
End Sub
End Class

کد کامل می خواین : خودتون تلاش کنید :لبخند: (:خنده پسر عمه زایی:)
در این روش در واقع ما با ایجاد یک task توسط Task Scheduler کامپیوتر رو روشن می کنیم . آموزش ساخت task
http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/

کاهی اوقات این ارور رو میده
109909
که می تونید تیک do not store password رو بزنید :
109910
خب ساخت task تموم شد اما فایده :
به پوشه C:\Windows\System32\Tasks بروید . و task مورد نطر رو باز کنید . (با نوت پد)
109911
حالا اگر یه کم حوصله و هوشمندی به خرج بدید می تونبد کدتون رو کامل کنید .
کد شما باید با فایل (متن نوت پدمون) هماهنگ باشد تا درست کار کند
نکات :
در تمامی موارد درایو که ویندوز در آن نصب شده c می باشد.
اکثر کامپیوتر ها قابلیت روشن شدن از حالت خواب را دارن . ولی اگر یه تست درست کنید بهتر (مثلا اگر بعد از 5 دقیقه روشن شد یا نه رو از کاربر بپرسه. اگه گفت نه با عرض معذرت خواهی بگید کامپیوتر شما این قابلیت رو نداره )

مراجع :
http://www.codeproject.com/Tips/606876/How-to-create-a-task-in-Windows-Task-Scheduler
http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/

فایده task
یکی از فایده ها روشن کردن کامپیوتر است .
اگر یه کم هم کار کنید می تونید بفهمید که قابلیت انجام کار به صورت هر روز ساعت مثلا 2 رو داره دیگه احتیاج به timer گذاشتن نداره .

با تشکر از Andrew
(tnx Andrew)

لطفا ً یکی تو وینوز 8 در حالت shutdown هم امتحان کنه و نتیجه رو بگه . ممنون می شم

بخشید اگه کد رو کامل نکردم وقت نشد دیگه (مثلا دانش آموزما (ده هَ)).

یه تشکر هم بکنید ممنون می شم

ادمین جان واسه قانون شکنی ببخشید

ali.rk
یک شنبه 10 شهریور 1392, 13:57 عصر
آموزش ساخت task

How to Make Your PC Wake From Sleep Automatically (http://www.howtogeek.com/119028/how-to-make-your-pc-wake-from-sleep-automatically/)

http://cdn.howtogeek.com/wp-content/uploads/2012/07/image185.png
When you put your PC into sleep mode, it normally waits until you press a button before it wakes from sleep – but you can have your PC automatically wake from sleep at a specific time.
This can be particularly useful if you want your PC to wake and perform downloads in off-peak hours or start other actions before you wake up in the morning — without running all night.
Setting a Wake Time

To have the computer automatically wake up, we’ll create a scheduled task. To do so, open the Task Scheduler by typing Task Scheduler into the Start menu and pressing Enter.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image186.png
In the Task Scheduler window, click the Create Task link to create a new task.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image187.png
Name the task something like “Wake From Sleep.” You may also want to tell it to run whether a user is logged on or not and set it to run with highest privileges.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image188.png
On the Triggers tab, create a new trigger that runs the task at your desired time. This can be a repeating schedule or a single time.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image189.png
On the conditions tab, enable the Wake the computer to run this task option.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image190.png
On the actions tab, you must specify at least one action for the task – for example, you could have the task launch a file-downloading program. If you want to wake the system without running a program, you can tell the task to run cmd.exe with the /c “exit” arguments – this will launch a Command Prompt window and immediately close it, effectively doing nothing.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image191.png
Save your new task after configuring it.
Putting The Computer to Sleep

Put the computer to sleep using the Sleep option instead of shutting it down. The computer won’t wake up if it’s not in sleep mode. You can also change Windows’ power saving options (http://www.howtogeek.com/?post_type=post&p=102897) to have the PC automatically sleep after it hasn’t been used for a while or when you press specific buttons.
http://cdn.howtogeek.com/wp-content/uploads/2012/07/image192.png
You can also create a scheduled task that puts the PC to sleep. See: Make Your PC Shut Down at Night (But Only When You’re Not Using It) (http://www.howtogeek.com/?post_type=post&p=30758)
Wake On LAN (http://www.howtogeek.com/?post_type=post&p=70374)is another method you can use to wake computers – wake on LAN works over the network.