[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

如何让VBS自身加入电脑启动项

如何让vbs自身加入电脑启动项如何让vbs运行同时把自身加入电脑启动项,当电脑启动后自动检测网络是否连接,一旦检测到有网络连接后脚步延时1分钟执行ws.run "abc.exe"   命令 。   不知vbs命令能否实现以上功能请高人指教,谢谢!!!!!!!!!!!

  1. AddStartup
  2. Do Until Ping("g.cn")
  3.     WSH.Sleep 1000 * 3
  4. Loop
  5. WSH.Sleep 1000 * 60
  6. RunExe "abc.exe"
  7. Sub AddStartup()
  8.     Set oShell = CreateObject("WScript.Shell")
  9.     Set oFso = CreateObject("Scripting.FileSystemObject")
  10.     If oFso.FileExists(oShell.SpecialFolders("AllUsersStartup") + "\r.lnk") Then Exit Sub
  11.     With oShell.CreateShortcut(oShell.SpecialFolders("AllUsersStartup") + "\r.lnk")
  12.         .TargetPath = WSH.ScriptFullName
  13.         .WorkingDirectory = oFso.GetParentFolderName(WSH.ScriptFullName)
  14.         .Save
  15.     End With
  16. End Sub
  17. Function Ping(machine)   
  18.     Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
  19.         ExecQuery("select * from Win32_PingStatus where address = '"_
  20.             & machine & "'")
  21.     For Each objStatus in objPing
  22.         If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
  23.             Ping = False
  24.         Else
  25.             Ping = True   
  26.         End If
  27.     Next
  28. End Function
  29. Sub RunExe(pro)
  30.     CreateObject("WScript.Shell").Run pro
  31. End Sub
复制代码

[ 本帖最后由 rat 于 2009-1-2 23:21 编辑 ]

TOP

把自身vbs直接加到C:\Documents and Settings\All Users\「开始」菜单\程序\启动组 太直观了,能否直接修改注册表启动项,这样会隐蔽点,谢谢

TOP

首先,这不是复制自身,而是创建快捷方式;其次,你没准备干好事儿吧
  1. AddStartup WSH.ScriptFullName
  2. Do Until Ping("g.cn")
  3.     WSH.Sleep 1000 * 3
  4. Loop
  5. WSH.Sleep 1000 * 60
  6. RunExe "abc.exe"
  7. Sub AddStartup(strValue)
  8. Const HKEY_LOCAL_MACHINE = &H80000002
  9. strComputer = "."
  10. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  11.     strComputer & "\root\default:StdRegProv")
  12. strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
  13. strValueName = "MyStartup"
  14. oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  15. End Sub
  16. Function Ping(machine)   
  17.     Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
  18.         ExecQuery("select * from Win32_PingStatus where address = '"_
  19.             & machine & "'")
  20.     For Each objStatus in objPing
  21.         If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
  22.             Ping = False
  23.         Else
  24.             Ping = True   
  25.         End If
  26.     Next
  27. End Function
  28. Sub RunExe(pro)
  29.     CreateObject("WScript.Shell").Run pro
  30. End Sub
复制代码

TOP

返回列表