用ASP 启动服务器上的某一程序(notepad.exe)付源代码!!怎会不行??高手来吧!!!
问题1:notepad.exe 为什么不会运行?
问题2:如果服务器上有运行notepad.exe 而且窗口名字是“未定标题 - 记事
本”, 那为什么不会关闭notepad.exe
在asp 文件中
set r = server.createobject("mypro.closeexe")
r.restart
set r = nothing
在.cls 文件中
Option Explicit
Public Function Restart()
Execute "c:\winnt\system32\notepad.exe", Priority '强制启动
End Function
Public Function terminate()
terminatekhan '注销
End Function
在.bas文件中
Option Explicit
' ==========================================================
' = Process =
' ==========================================================
Private Const CREATE_NEW_CONSOLE = &H10
Private Const CREATE_NEW_PROCESS_GROUP = &H200
Private Const CREATE_SUSPENDED = &H4
Private Const DEBUG_PROCESS = &H1
Private Const DEBUG_ONLY_THIS_PROCESS = &H2
Private Const DETACHED_PROCESS = &H8
Private Const INFINITE = &HFFFF
Private Const MAX_PATH = 260
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const IDLE_PRIORITY_CLASS = &H40
Private Const NORMAL_PRIORITY_CLASS = &H20
Private Const REALTIME_PRIORITY_CLASS = &H100
Private Const SYNCHRONIZE = &H100000
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 String
lpDesktop As String
lpTitle As String
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 Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function GetLastError Lib "kernel32" () _
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 WaitForInputIdle Lib "user32" _
(ByVal hProcess As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) 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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' ==========================================================
' = Run the program associated with a file =
' ==========================================================
' Error conditions
Private Const ERROR_BAD_FORMAT = 11&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26
' ShowCmd values
Private Const SW_HIDE = 0
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Private Const SW_SHOW = 5
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
Private FName As String
Private LastErr As Long
Private ProcId As Long
Private ProcessPriority As Long
Public Property Get ProcessId() As Long
ProcessId = ProcId
End Property
Property Get Error() As Long
Error = LastErr
End Property
Public Property Get FileName() As String
FileName = FName
End Property
Public Property Let FileName(FileName As String)
FName = FileName
End Property
Public Property Get Priority() As Long
Priority = ProcessPriority
End Property
Public Property Let Priority(a As Long)
If a = NORMAL_PRIORITY_CLASS Or _
a = IDLE_PRIORITY_CLASS Or _
a = HIGH_PRIORITY_CLASS Then
ProcessPriority = a
End If
End Property
Public Sub Execute(Optional FileName As String, Optional Priority As Long)
Dim p As PROCESS_INFORMATION
Dim s As STARTUPINFO
Dim pHandle As Long
Dim r As Long
s.cb = Len(s)
s.dwFlags = 0
s.lpDesktop = vbNullString
s.lpReserved = vbNullString
s.lpTitle = vbNullString
If Not IsMissing(FileName) Then
FName = FileName
End If
If Not IsMissing(Priority) Then
If Priority = NORMAL_PRIORITY_CLASS Or _
Priority = IDLE_PRIORITY_CLASS Or _
Priority = HIGH_PRIORITY_CLASS Then
ProcessPriority = Priority
End If
End If
LastErr = 0
r = CreateProcess(FName, vbNullString, 0, 0, True, _
ProcessPriority, 0, vbNullString, s, p)
If r <> 0 Then
r = CloseHandle(p.hThread)
If r <> 0 Then
r = WaitForInputIdle(p.hProcess, INFINITE)
r = CloseHandle(p.hProcess)
End If
Else
LastErr = GetLastError()
End If
ProcId = p.dwProcessId
End Sub
Public Sub terminatekhan()
Dim winHwnd As Long
Dim RetVal As Long
Dim terminatekhan As String
winHwnd = FindWindow(vbNullString, "纸牌")
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, &H10, 0&, 0&)
If RetVal = 0 Then
terminatekhan = "关闭计算器出错!"
Else
terminatekhan = "关闭OK"
End If
Else
terminatekhan = "关闭计算器出错!"
End If
End Sub
Private Sub Class_Initialize()
LastErr = 0
ProcessPriority = NORMAL_PRIORITY_CLASS
End Sub