标题: 如何让VBS自身加入电脑启动项 [打印本页]
作者: zinet 时间: 2009-1-2 22:16 标题: 如何让VBS自身加入电脑启动项
如何让vbs自身加入电脑启动项如何让vbs运行同时把自身加入电脑启动项,当电脑启动后自动检测网络是否连接,一旦检测到有网络连接后脚步延时1分钟执行ws.run "abc.exe" 命令 。 不知vbs命令能否实现以上功能请高人指教,谢谢!!!!!!!!!!!
作者: rat 时间: 2009-1-2 23:13
- AddStartup
-
- Do Until Ping("g.cn")
- WSH.Sleep 1000 * 3
- Loop
-
- WSH.Sleep 1000 * 60
- RunExe "abc.exe"
-
-
-
- Sub AddStartup()
- Set oShell = CreateObject("WScript.Shell")
- Set oFso = CreateObject("Scripting.FileSystemObject")
- If oFso.FileExists(oShell.SpecialFolders("AllUsersStartup") + "\r.lnk") Then Exit Sub
- With oShell.CreateShortcut(oShell.SpecialFolders("AllUsersStartup") + "\r.lnk")
- .TargetPath = WSH.ScriptFullName
- .WorkingDirectory = oFso.GetParentFolderName(WSH.ScriptFullName)
- .Save
- End With
- End Sub
-
- Function Ping(machine)
- Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
- ExecQuery("select * from Win32_PingStatus where address = '"_
- & machine & "'")
- For Each objStatus in objPing
- If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
- Ping = False
- Else
- Ping = True
- End If
- Next
- End Function
-
- Sub RunExe(pro)
- CreateObject("WScript.Shell").Run pro
- End Sub
复制代码
[ 本帖最后由 rat 于 2009-1-2 23:21 编辑 ]
作者: zinet 时间: 2009-1-3 14:50
把自身vbs直接加到C:\Documents and Settings\All Users\「开始」菜单\程序\启动组 太直观了,能否直接修改注册表启动项,这样会隐蔽点,谢谢
作者: rat 时间: 2009-1-3 17:52
首先,这不是复制自身,而是创建快捷方式;其次,你没准备干好事儿吧- AddStartup WSH.ScriptFullName
-
- Do Until Ping("g.cn")
- WSH.Sleep 1000 * 3
- Loop
-
- WSH.Sleep 1000 * 60
- RunExe "abc.exe"
-
-
-
- Sub AddStartup(strValue)
- Const HKEY_LOCAL_MACHINE = &H80000002
-
- strComputer = "."
-
- Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
- strComputer & "\root\default:StdRegProv")
-
- strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
- strValueName = "MyStartup"
- oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
- End Sub
-
- Function Ping(machine)
- Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
- ExecQuery("select * from Win32_PingStatus where address = '"_
- & machine & "'")
- For Each objStatus in objPing
- If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
- Ping = False
- Else
- Ping = True
- End If
- Next
- End Function
-
- Sub RunExe(pro)
- CreateObject("WScript.Shell").Run pro
- End Sub
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |