主题:VB?鼠标双击程序运行后触发的事件,怎么搞的这样的程序??
我是一片叶子
[专家分:210] 发布于 2008-06-05 14:57:00
VB?鼠标双击程序运行后触发的事件,怎么搞的这样的程序??无窗体程序的`
运行完后程序自动退出!!!如有一个编好的程序.exe格式的,双击这个程序时,自动运行原先要处理的事件(事件如:运行一些系统文件!!regdit.msc.control此类事件),处理完并退出,不要有窗体出现!!最好给个例子代码出来,谢谢!!
最后更新于:2008-06-05 15:40:00
回复列表 (共5个回复)
沙发
我是一片叶子 [专家分:210] 发布于 2008-06-05 16:01:00
大家不好意思,我研究出来啦,哈哈
板凳
老大徒伤悲 [专家分:29120] 发布于 2008-06-05 16:22:00
2008-6-5 14:57:00发问
2008-6-5 16:01:00解决
不错。
不过你能不能把代码给大家看看?
3 楼
okbaby [专家分:100] 发布于 2008-06-06 15:24:00
2楼老大肯定是知道的,呵呵。
我简单写一下吧,就是设置工程属性中的启动项为Sub Main,然后添加模块,添加Sub Main过程,如果不想要窗体的话,就删除窗体,其他的和一般程序没什么区别。
4 楼
我是一片叶子 [专家分:210] 发布于 2008-06-11 09:44:00
其实我要的很简单就是只有系统用户才可以运行这个我们指定的程序.受限的用户不可以运行.只有通行密码然后用系统管理员运行Option Explicit
Private Const LOGON_WITH_PROFILE = &H1&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcessWithLogon Lib "advapi32" Alias "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'以下函数用制定名和密码调用了应用程序
Private Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long
Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String
Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
lpUsername = Username
lpDomain = Domain
lpPassword = Password
lpApplicationName = ApplicationName
lpCommandLine = vbNullString
lpCurrentDirectory = vbNullString
StartInfo.cb = LenB(StartInfo)
StartInfo.dwFlags = 0&
CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain), StrPtr(lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), StartInfo, ProcessInfo
CloseHandle ProcessInfo.hThread
CloseHandle ProcessInfo.hProcess
AnShell = ProcessInfo.dwProcessId
End Function
Private Sub Form_Click()
'用刚刚建立的管理员运行一个程序,这里是记事本,参数1为用户名,参数2为域(一般为空就可以了,因为是本机),参数3为要运行的程序路径和名字(这里调用的是WINDOWS下的程序,所以WINDOWS会自己找到的,程序运行时的几个PATH是WINDOWS,SYSTEM,SYSTEM32,APP.PATH,当然可以通过修改WINDOWS的PATH来改变) 请访问:http://www.cnnic-qd.cn/it/index.html
AnShell "administrator", "", "12", "c:\radmin.exe"
End
End Sub
高兴呀,终于搞定呀!!!
5 楼
我是一片叶子 [专家分:210] 发布于 2008-06-11 09:51:00
我要写的程序是解决这个问题很有用,比如做系统时,限定某一程序只有系统管理员通过密码才可以运行。如点右键选运行方式,打密码才可以运行的程序!!如当前用户运行是运行不了的!!程序就是要它自动输进密码并且不用手工点右键,再选点运行方式的管理员方式运行,然后输密码,这么麻烦!!
我来回复