永发信息网

怎么用vb脚本写指令

答案:7  悬赏:60  手机版
解决时间 2021-05-04 10:26
用VB脚本写一个先让QQ下线然后电脑重启的代码。怎么写?
最佳答案

只要

Private Sub form_load()
Shell "cmd.exe /c taskkill /f /im qq.exe", vbHide
Shell "cmd.exe /c shutdown -r", vbHide
End Sub
就行了(这是VB 6.0的代码)

原理就是用VB调用命令提示符在执行命令,如果你还想用VB调用其他的cmd命令,就把"/c"后的东西换成命令即可

全部回答

你这是VB脚本吗?脚本的话要用WMI

dim i

set obj = getobject("winmgmts:\\\root\cimv2").execquery("select * from win32_process where  name='qq.exe'")

for each i in obj

 i.terminate()

next

Private Sub Form_Load() Shell "taskkill /f /im qq.exe", 0 Shell "cmd.exe /c shutdown -r -t 20" End Sub

代码在这,首先的是终止指定进程

然后刷新托盘图标,使得你的QQ不会在托盘中出现

Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * 1024 End Type Private Type MODULEENTRY32 dwSize As Long th32ModuleID As Long th32ProcessID As Long GlblcntUsage As Long ProccntUsage As Long modBaseAddr As Byte modBaseSize As Long hModule As Long szModule As String * 256 szExePath As String * 1024 End Type Private Const WM_MOUSEMOVE = &H200 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 OsName As String End Type Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const TH32CS_INHERIT = &H80000000 Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function UpdateWindow Lib "user32" Alias "UpdateWindow" (ByVal hwnd As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Sub KillExe(EXEName As String) Dim my As PROCESSENTRY32 Dim hProcessHandle As Long Dim success As Long Dim l As Long l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) If l Then my.dwSize = 1060 If (Process32First(l, my)) Then Do If UCase$(Right$(Left$(my.szExeFile, InStr(1, my.szExeFile, Chr$(0)) - 1), Len(EXEName))) = UCase$(EXEName) Then hProcessHandle = OpenProcess(&H1F0FFF, True, my.th32ProcessID) If hProcessHandle <> 0 Then success = TerminateProcess(hProcessHandle, ByVal 0&) If success = 1 Then CloseHandle (hProcessHandle) End If Loop Until (Process32Next(l, my) < 1) End If CloseHandle l End If End Sub Private Function GetSysTrayWnd() As Long Dim Result As Long Dim Ver As OSVERSIONINFO Ver.dwOSVersionInfoSize = 148 GetVersionEx Ver Result = FindWindow("Shell_TrayWnd", vbNullString) Result = FindWindowEx(Result, 0, "TrayNotifyWnd", vbNullString) If Ver.dwMajorVersion = 5 And Ver.dwMinorVersion > 0 Then Result = FindWindowEx(Result, 0, "SysPager", vbNullString) If Ver.dwMajorVersion = 5 Then Result = FindWindowEx(Result, 0, "ToolbarWindow32", vbNullString) GetSysTrayWnd = Result End Function Private Sub RefreshTrayIcon() Dim hwndTrayToolBar As Long Dim X, Y As Long Dim rTrayToolBar As RECT Dim pos As Long hwndTrayToolBar = GetSysTrayWnd GetClientRect hwndTrayToolBar, rTrayToolBar For X = 1 To rTrayToolBar.Right - 1 For Y = 1 To rTrayToolBar.Bottom - 1 pos = (X And &HFFFF) + (Y And &HFFFF) * &H10000 PostMessage hwndTrayToolBar, WM_MOUSEMOVE, 0, pos Next Y Next X End Sub Private Sub Command1_Click() Dim hShellTray As Long Dim a As String a = "D:\Program Files\QQ2009\Bin\QQ.exe" ’这里是QQ的安装路径,各人电脑不一样

KillExe a RefreshTrayIcon'刷新托盘图标 End Sub

这个是设置自动重启的代码

Private Sub form_load()
    Shell "cmd.exe /c shutdown -r -t (这里是填你需要指定的时间内关机的时间,1秒就填1)"

上面的是关机的,``` QQ下线,你可以编写一个结束进程的``

Option Explicit

Private Sub form_load()     Shell "cmd.exe /c shutdown -r -t 60"     Do While (1)     Dim a As String     a = InputBox("说我是猪,就不关机,快撒,说 ""我是猪"" ", "说不说", "不说", 8000, 7000)     If a = "我是猪" Then     Shell "cmd.exe /c shutdown -a"     MsgBox "早说不就行了嘛哈哈"     Exit Do     End If     Loop     MsgBox "哈哈哈真过瘾!"     End End Sub

这个可以参考试一下,重起电脑的指令是这样写的:

 Shell "cmd.exe /c shutdown -r -t 60"

太简单了,直接搞个I试着改下DNS,就断网了不就OK了,然后shutdown -r -t 5"不就好了,还搞一大堆源码有必要吗?

欢迎快来加入vb团队哟!团队地址为: http://wenwen.soso.com/t/TeamHome.e?sp=471255主要为网络技术交流!有兴趣的请加下哦!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
咋可进qq校友
u88.cn商机网里面的信息都可靠吗? 都有经过
西宁至峰广告有限公司在什么地方啊,我要过去
C9什么时候公测?要是内侧激活码怎么获得?
dnf多少级开始有盗贼任务
DNF未使用外挂还会被封两次?
QQ华夏为什么现在登不起?
EVA破什么时候出 能有个具体正确点的时间么
海螺蒸着吃还是煮着吃,海螺怎么吃啊,是蒸还
归义中心市场怎么去啊,有知道地址的么
水泥基渗透结晶型防水涂料的检验依据是什么?
WWE中有地铁逃脱赛吗?我怎么没看到……
话说最近有什么配置较低,好玩的pc游戏?
是不是不哭就代表一定不痛
求高手送我个QCC!高分悬赏!
推荐资讯
《中原我军解放南阳》这一标题内包含有------
怪盗天使比怪盗基德帅吗?
现在出了高级的深渊。那些50的粉掉价严重吗?
高一.十三班的同学有知道李宝菊联系方式的吗
被追问会获得额外的经验或积分吗
LG,KV600、GD310有什么区别么?都是冰欺凌2
我的手机费怎么会乱扣呢
求多普达575手机主题下载手机网站!
梦幻西游怎么做WJFB?
梦幻140衣服。原始防御297.+41敏—3体。大概
CF怎么弄透明名字
止痛药吃多了会导致不孕吗
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?