我正在尝试创建一个 VBScript,它创建一个批处理文件,然后创建一个计划任务来运行该批处理文件。到目前为止,我尝试过的所有操作都会创建批处理文件,但不会创建计划任务,而且我还没有收到任何错误。这是我目前所拥有的:
Option Explicit
Dim objFSO, outFile, wShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outFile = objFSO.CreateTextFile("C:\test.bat", True)
outFile.WriteLine "Start www.google.com"
outFile.Close
Set wShell = CreateObject ("Wscript.Shell")
wShell.Run "cmd SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN 'Test Task' /TR 'C:\test.bat' /ST 16:30", 0
我尝试了 ""Test Task"" 和 ""C:\test.bat"",得到了相同的结果。但是当我在命令提示符下运行以下命令时:
SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN "Test Task" /TR "C:\test.bat" /ST 16:30
任务创建成功。
我尝试的另一种方法是创建 2 个批处理文件:一个用于打开网页的批处理文件,一个用于创建计划任务的批处理文件。然后我最后运行了 task.bat 文件。这是我为此准备的:
Option Explicit
Dim objFSO, outFile, wShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outFile = objFSO.CreateTextFile("C:\test.bat", True)
outFile.WriteLine "Start www.google.com"
outFile.Close
Set outFile = objFSO.CreateTextFile("C:\task.bat", True)
outFile.WriteLine "SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN ""Test Task"" /TR ""C:\test.bat"" /ST 16:30"
Set wShell = CreateObject ("Wscript.Shell")
wShell.Run "cmd start ""C:\task.bat"""
这创建了批处理文件,但最后只是打开了 cmd,之后什么也没做。
我的猜测是问题出在 wShell.Run 部分,但我没有足够的经验知道问题出在哪里。
我不确定从这里去哪里,所以任何建议都很好。
最佳答案
作为 VBScript,您可以执行命令可以执行的任何操作。
以下是在根文件夹中列出计划任务的方法。
Set TS = CreateObject("Schedule.Service")
TS.Connect("Serenity")
Set rootFolder = TS.GetFolder("\")
Set tasks = rootFolder.GetTasks(0)
If tasks.Count = 0 Then
Wscript.Echo "No tasks are registered."
Else
WScript.Echo "Number of tasks registered: " & tasks.Count
For Each Task In Tasks
A=Task.Name
A = A & " " & Task.NextRunTime
A = A & " " & Task.LastTaskResult
wscript.echo A
Next
End If
这是来自 documentation展示如何创建任务。
Time Trigger Example (Scripting)
This scripting example shows how to create a task that runs Notepad at a specific time. The task contains a time-based trigger that specifies a start boundary to activate the task, an executable action that runs Notepad, and an end boundary that deactivates the task.
The following procedure describes how to schedule a task to start an executable at a specific time.
To Schedule Notepad to start at a Specific Time
Create a TaskService object. This object allows you to create the task in a specified folder.
Get a task folder and create a task. Use the
TaskService.GetFoldermethod to get the folder where the task is stored and theTaskService.NewTaskmethod to create the TaskDefinition object that represents the task.- Define information about the task using the
TaskDefinitionobject. Use theTaskDefinition.Settingsproperty to define the settings that determine how the Task Scheduler service performs the task and theTaskDefinition.RegistrationInfoproperty to define the information that describes the task.- Create a time-based trigger using the
TaskDefinition.Triggersproperty. This property provides access to theTriggerCollectionobject. Use theTriggerCollection.Createmethod (specifying the type of trigger you want to create) to create a time-based trigger. As you create the trigger, set the start boundary and end boundary of the trigger to activate and deactivate the trigger. The start boundary specifies when the task's action will be performed.- Create an action for the task to execute by using the
TaskDefinition.Actionsproperty. This property provides access to theActionCollectionobject. Use theActionCollection.Createmethod to specify the type of action you want to create. This example uses anExecActionobject, which represents an action that executes a command-line operation.- Register the task using the
TaskFolder.RegisterTaskDefinitionmethod. For this example the task will start Notepad at the current time plus 30 seconds.The following VBScript example shows how to schedule a task to execute Notepad 30 seconds after the task is registered.
' This sample schedules a task to start notepad.exe 30 seconds ' from the time the task is registered. '------------------------------------------------------------------ ' A constant that specifies a time-based trigger. const TriggerTypeTime = 1 ' A constant that specifies an executable action. const ActionTypeExec = 0 '******************************************************** ' Create the TaskService object. Set service = CreateObject("Schedule.Service") call service.Connect() '******************************************************** ' Get a folder to create a task definition in. Dim rootFolder Set rootFolder = service.GetFolder("\") ' The taskDefinition variable is the TaskDefinition object. Dim taskDefinition ' The flags parameter is 0 because it is not supported. Set taskDefinition = service.NewTask(0) '******************************************************** ' Define information about the task. ' Set the registration info for the task by ' creating the RegistrationInfo object. Dim regInfo Set regInfo = taskDefinition.RegistrationInfo regInfo.Description = "Start notepad at a certain time" regInfo.Author = "Administrator" ' Set the task setting info for the Task Scheduler by ' creating a TaskSettings object. Dim settings Set settings = taskDefinition.Settings settings.Enabled = True settings.StartWhenAvailable = True settings.Hidden = False '******************************************************** ' Create a time-based trigger. Dim triggers Set triggers = taskDefinition.Triggers Dim trigger Set trigger = triggers.Create(TriggerTypeTime) ' Trigger variables that define when the trigger is active. Dim startTime, endTime Dim time time = DateAdd("s", 30, Now) 'start time = 30 seconds from now startTime = XmlTime(time) time = DateAdd("n", 5, Now) 'end time = 5 minutes from now endTime = XmlTime(time) WScript.Echo "startTime :" & startTime WScript.Echo "endTime :" & endTime trigger.StartBoundary = startTime trigger.EndBoundary = endTime trigger.ExecutionTimeLimit = "PT5M" 'Five minutes trigger.Id = "TimeTriggerId" trigger.Enabled = True '*********************************************************** ' Create the action for the task to execute. ' Add an action to the task to run notepad.exe. Dim Action Set Action = taskDefinition.Actions.Create( ActionTypeExec ) Action.Path = "C:\Windows\System32\notepad.exe" WScript.Echo "Task definition created. About to submit the task..." '*********************************************************** ' Register (create) the task. call rootFolder.RegisterTaskDefinition( _ "Test TimeTrigger", taskDefinition, 6, , , 3) WScript.Echo "Task submitted." '------------------------------------------------------------------ ' Used to get the time for the trigger ' startBoundary and endBoundary. ' Return the time in the correct format: ' YYYY-MM-DDTHH:MM:SS. '------------------------------------------------------------------ Function XmlTime(t) Dim cSecond, cMinute, CHour, cDay, cMonth, cYear Dim tTime, tDate cSecond = "0" & Second(t) cMinute = "0" & Minute(t) cHour = "0" & Hour(t) cDay = "0" & Day(t) cMonth = "0" & Month(t) cYear = Year(t) tTime = Right(cHour, 2) & ":" & Right(cMinute, 2) & _ ":" & Right(cSecond, 2) tDate = cYear & "-" & Right(cMonth, 2) & "-" & Right(cDay, 2) XmlTime = tDate & "T" & tTime End Function
关于windows - 用于创建计划任务的 VBScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31549393/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm