VB里面单击按钮运行程序
我想设计一个定时关机的程序,按下按钮运行“shutdown.exe-s-t10-c即将关机”,请问如何在VB里面编写代码?顺便问一下,不用shutdown.exe还有什么...
我想设计一个定时关机的程序,按下按钮运行“shutdown.exe -s -t 10 -c 即将关机”,请问如何在VB里面编写代码?
顺便问一下,不用shutdown.exe还有什么别的办法实现关机? 展开
顺便问一下,不用shutdown.exe还有什么别的办法实现关机? 展开
展开全部
Shell () 函数额可以调用第三方程序。 shutdown是windows管理关机的程序,直接调用
Shell "cmd.exe /c shutdown -s -t 10 -c"
另外,你说要别的办法,用windows API: ExitWindowsEx
ExitWindowsEx需要获取权限
主要代码:
Private Sub Form_Load()
Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim tmpLuid As LUID
Dim tkpNew As TOKEN_PRIVILEGES
Dim tkpPrevious As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
'获取当前进程的一个伪句柄
hProcessHandle = GetCurrentProcess()
OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED
lBufferNeeded = 0
'允许当前应用程序有关闭操作系统的权限
AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded
End Sub
Private Sub Command1_Click()
'重新启动计算机
ExitWindowsEx EWX_REBOOT, 0
End Sub
Private Sub Command2_Click()
'关闭计算机
ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0
End Sub
Private Sub Command4_Click()
ExitWindowsEx EWX_LOGOFF, 0
End Sub
Shell "cmd.exe /c shutdown -s -t 10 -c"
另外,你说要别的办法,用windows API: ExitWindowsEx
ExitWindowsEx需要获取权限
主要代码:
Private Sub Form_Load()
Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim tmpLuid As LUID
Dim tkpNew As TOKEN_PRIVILEGES
Dim tkpPrevious As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
'获取当前进程的一个伪句柄
hProcessHandle = GetCurrentProcess()
OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED
lBufferNeeded = 0
'允许当前应用程序有关闭操作系统的权限
AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded
End Sub
Private Sub Command1_Click()
'重新启动计算机
ExitWindowsEx EWX_REBOOT, 0
End Sub
Private Sub Command2_Click()
'关闭计算机
ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0
End Sub
Private Sub Command4_Click()
ExitWindowsEx EWX_LOGOFF, 0
End Sub
追问
这是怎么回事?
展开全部
Private Sub Command1_Click()
Shell "shutdown.exe -s -t " & Text1.Text
End Sub
Shell "shutdown.exe -s -t " & Text1.Text
End Sub
追问
顺便问:如果我要运行一个程序如QQ.exe该怎么办呢?
追答
Shell "C:\Program Files\Tencent\QQ\Bin\QQ.exe"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在按钮事件里写:
Shell "cmd.exe /c shutdown -s -t 10 -c"
Shell "cmd.exe /c shutdown -s -t 10 -c"
追问
如果我要运行一个程序如QQ.exe该怎么办呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
shell "shutdown.exe -s -t 10 -c 即将关机"
追问
顺便问:如果我要运行一个程序如QQ.exe该怎么办呢?
追答
把shutdown.exe -s -t 10 -c 即将关机 改成需要执行的文件的路径和文件名即可,
如:D:\.....\QQ.EXE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果你的那个图标
和
菜单的位置是固定不变的话,可以用
api函数
public
declare
function
setcursorpos
lib
"user32"
(byval
x
as
long,
byval
y
as
long)
as
long‘这个函数可以讲鼠标移动到任意(x,y)位置
public
declare
sub
mouse_event
lib
"user32"
(byval
dwflags
as
long,
byval
dx
as
long,
byval
dy
as
long,
byval
cbuttons
as
long,
byval
dwextrainfo
as
long)’模拟鼠标单击
先找到你那个图标和菜单的位置x
和y,然后
dim
ret
as
long
ret=setcursorpos(x,y)'移动到那个位置
mouse_event(&h2,
0,
0,
0,
0)'鼠标左键按下
mouse_event(&h4,
0,
0,
0,
0)‘鼠标左键弹起
和
菜单的位置是固定不变的话,可以用
api函数
public
declare
function
setcursorpos
lib
"user32"
(byval
x
as
long,
byval
y
as
long)
as
long‘这个函数可以讲鼠标移动到任意(x,y)位置
public
declare
sub
mouse_event
lib
"user32"
(byval
dwflags
as
long,
byval
dx
as
long,
byval
dy
as
long,
byval
cbuttons
as
long,
byval
dwextrainfo
as
long)’模拟鼠标单击
先找到你那个图标和菜单的位置x
和y,然后
dim
ret
as
long
ret=setcursorpos(x,y)'移动到那个位置
mouse_event(&h2,
0,
0,
0,
0)'鼠标左键按下
mouse_event(&h4,
0,
0,
0,
0)‘鼠标左键弹起
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询