免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 6825 | 回复: 26
打印 上一主题 下一主题

关于windows下计划任务脚本的问题??  关闭 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-08-21 00:53 |只看该作者 |倒序浏览
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob"
errJobCreated = objNewJob.Create _
    ("notepad.exe", "********123000.000000-420", _
        True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated

以上就是这个vbs脚本可以成功执行,不知怎样修改,让notepad立即执行或以几秒或一分钟后 执行 时间上怎莫修改 还有不要弹出对话框来

论坛徽章:
0
2 [报告]
发表于 2005-08-21 19:45 |只看该作者

关于windows下计划任务脚本的问题??

Windows Script Host                
Sleep Method

Suspends script execution for a specified length of time, then continues execution.

object.Sleep(intTime)
Arguments
object
WScript object.
intTime
Integer value indicating the interval (in milliseconds) you want the script process to be inactive.
Remarks

The thread running the script is suspended, releasing its CPU utilization. Execution resumes as soon as the interval expires. Using the Sleep method can be useful when you are running asynchronous operations, multiple processes, or if your script includes code triggered by an event. To be triggered by an event, a script must be continually active (a script that has finished executing will certainly not detect an event). Events handled by the script will still be executed during a sleep.
Note   Passing the Sleep method a 0 or –1 does not cause the script to suspend indefinitely.
Example

The following example demonstrates the use of a single .wsf file for two jobs in different script languages (VBScript and JScript). The functionality of both jobs is the same — each runs the Windows calculator and sends it keystrokes to execute a simple calculation.

<package>;
   <job id="vbs">;
      <script language="VBScript">;
         set WshShell = WScript.CreateObject("WScript.Shell"
         WshShell.Run "calc"
         WScript.Sleep 100
         WshShell.AppActivate "Calculator"
         WScript.Sleep 100
         WshShell.SendKeys "1{+}"
         WScript.Sleep 500
         WshShell.SendKeys "2"
         WScript.Sleep 500
         WshShell.SendKeys "~"
         WScript.Sleep 500
         WshShell.SendKeys "*3"
         WScript.Sleep 500
         WshShell.SendKeys "~"
         WScript.Sleep 2500
      </script>;
   </job>;

   <job id="js">;
      <script language="JScript">;
         var WshShell = WScript.CreateObject("WScript.Shell";
         WshShell.Run("calc";
         WScript.Sleep(100);
         WshShell.AppActivate("Calculator";
         WScript.Sleep(100);
         WshShell.SendKeys("1{+}";
         WScript.Sleep(500);
         WshShell.SendKeys("2";
         WScript.Sleep(500);
         WshShell.SendKeys("~";
         WScript.Sleep(500);
         WshShell.SendKeys("*3";
         WScript.Sleep(500);
         WshShell.SendKeys("~";
         WScript.Sleep(2500);
      </script>;
   </job>;
</package>;
See Also

论坛徽章:
0
3 [报告]
发表于 2005-08-21 20:37 |只看该作者

关于windows下计划任务脚本的问题??

回 renstone921 大哥
谢谢阿
可是我看太不懂啊
能不能再详细点啊
我不懂vbs

论坛徽章:
0
4 [报告]
发表于 2005-08-21 20:56 |只看该作者

关于windows下计划任务脚本的问题??

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob"
errJobCreated = objNewJob.Create _
   ("notepad.exe", "********123000.000000-420", _
       True , 1 OR 4 OR 16, , , JobID)
<package>;
  <job id="vbs">;
     <script language="VBScript">;
        set WshShell = WScript.CreateObject("WScript.Shell"
        WshShell.Run "calc"
        WScript.Sleep 100
        WshShell.AppActivate "Calculator"
        WScript.Sleep 100
        WshShell.SendKeys "1{+}"
        WScript.Sleep 500
        WshShell.SendKeys "2"
        WScript.Sleep 500
        WshShell.SendKeys "~"
        WScript.Sleep 500
        WshShell.SendKeys "*3"
        WScript.Sleep 500
        WshShell.SendKeys "~"
        WScript.Sleep 2500
     </script>;
  </job>;

Wscript.Echo errJobCreated
不能运行

论坛徽章:
0
5 [报告]
发表于 2005-08-21 21:01 |只看该作者

关于windows下计划任务脚本的问题??

你需要做的仅仅是把下面的代码段加入你的代码。
set WshShell = WScript.CreateObject("WScript.Shell"
WshShell.Sleep 2500

论坛徽章:
0
6 [报告]
发表于 2005-08-21 21:14 |只看该作者

关于windows下计划任务脚本的问题??

renstone921大哥
报错:对象不支持‘wshell.sleep'

论坛徽章:
0
7 [报告]
发表于 2005-08-21 21:19 |只看该作者

关于windows下计划任务脚本的问题??

你把你的全部代码贴出来。

论坛徽章:
0
8 [报告]
发表于 2005-08-21 21:25 |只看该作者

关于windows下计划任务脚本的问题??

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob"
errJobCreated = objNewJob.Create _
    ("Notepad.exe", "********123000.000000-420", _
        True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated
set WshShell = WScript.CreateObject("WScript.Shell"
WshShell.Sleep 2500
Wscript.Echo errJobCreated
执行后可以成功后报错对象不支持‘wshell.sleep'
sleep 2500 之后不能把notepad启动

论坛徽章:
0
9 [报告]
发表于 2005-08-21 21:48 |只看该作者

关于windows下计划任务脚本的问题??

你把下面的代码为a.vbs,然后用鼠标双击来启动执行

set WshShell = WScript.CreateObject("WScript.Shell"

        WScript.Sleep 100001

         WshShell.Run "calc"
         WshShell.AppActivate "Calculator"
         WScript.Sleep 100
         WshShell.SendKeys "1{+}"
         WScript.Sleep 500
         WshShell.SendKeys "2"
         WScript.Sleep 500
         WshShell.SendKeys "~"
         WScript.Sleep 500
         WshShell.SendKeys "*3"
         WScript.Sleep 500
         WshShell.SendKeys "~"
         WScript.Sleep 2500

论坛徽章:
0
10 [报告]
发表于 2005-08-21 21:55 |只看该作者

关于windows下计划任务脚本的问题??

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob"
errJobCreated = objNewJob.Create _
    ("Notepad.exe", "********123000.000000-420", _
        True , 1 OR 4 OR 16, , , JobID)

set WshShell = WScript.CreateObject("WScript.Shell"
WshShell.Sleep 2500
Wscript.Echo errJobCreated
刚才贴错了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP