1,服务器 是win NT
2,服务器程序是JAVA的
3,是B/S结构
整个难点就是于java怎么样启动NT 上的exe程序。
启动EXE程序可以用线程的Runtime.getRuntime().exec()方法运行。如果有多个任务可以写个bat。
至于用户怎么发请求给server让它执行,这个不难吧,做过网站的对这个最熟悉不过了;
using System.Collections.Genericusing System.Linq
using System.Web
using System.Web.UI
using System.Web.UI.WebControls
using System.Diagnostics
using System.Runtime.InteropServices
using System
using System.Windows.Forms
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//修改此除····
}
Process process = null
IntPtr appWin
private string exeName = ""
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId)
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName)
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent)
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hwnd, int nIndex)
[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong)
//private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags)
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint)
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hwnd, uint Msg, long wParam, long lParam)
private const int SWP_NOOWNERZORDER = 0x200
private const int SWP_NOREDRAW = 0x8
private const int SWP_NOZORDER = 0x4
private const int SWP_SHOWWINDOW = 0x0040
private const int WS_EX_MDICHILD = 0x40
private const int SWP_FRAMECHANGED = 0x20
private const int SWP_NOACTIVATE = 0x10
private const int SWP_ASYNCWINDOWPOS = 0x4000
private const int SWP_NOMOVE = 0x2
private const int SWP_NOSIZE = 0x1
private const int GWL_STYLE = (-16)
private const int WS_VISIBLE = 0x10000000
private const int WM_CLOSE = 0x10
private const int WS_CHILD = 0x40000000
public string ExeName
{
get
{
return exeName
}
set
{
exeName = value
}
}
}
要求应该是在客户端网页上发送消息到服务器,然后服务器响应这个消息并执行程序,然后将程序运行结果返回给网页。
当然还有一种要求是用网页管理服务端程序,跟远程桌面一样,这个由于篇幅限制不多解释,请自己去搜索VNC这个远程控制台。
回到正题,一般来讲,服务端脚本语言都可以执行程序的,这里以PHP为例子
<?phpexec("./run.sh",$output)//接收控制台输出的内容或者程序执行的结果
print_r($output)//输出这个结果给网页
?>
一般来讲,在网页直接指令执行服务器文件风险性极高,所以许多时候这些服务端脚本语言的默认设定是不会让你执行文件的,需要自行修改相关设置参数提升权限才可以获取让脚本语言执行文件的权限,系统文件夹的权限也相应需要修改。不同系统对应设置不同。
Windows的权限设置很详细,建议要进行这种高风险操作之前先详细了解文件权限方面知识,这部分内容不在本题范围中,不多做解释。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)