如何通过asp程序启动服务器

yangchuzi 2004-11-17 09:08:50
我想通过访问服务器的asp文件,点击其中的按钮之类的,然后启动服务器,有这样的代码吗,如何写,能不能详细点,因为我对asp懂得很少
...全文
212 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
poron9 2004-11-17
  • 打赏
  • 举报
回复
高手……
TSD 2004-11-17
  • 打赏
  • 举报
回复
*_*
Jaron 2004-11-17
  • 打赏
  • 举报
回复
使用sqlserver的扩展存储过程

xp_cmdshell 'dir c:\>c:\a.txt'
waiber 2004-11-17
  • 打赏
  • 举报
回复
通过访问服务器的asp文件,点击其中的按钮之类的,然后启动服务器?

问题不清...
herage 2004-11-17
  • 打赏
  • 举报
回复
不行吧,没启动服务器上执行ASP?
life360 2004-11-17
  • 打赏
  • 举报
回复
晕,服务器没有启动。asp文件能启动????微软都没那么厉害
wanghui0380 2004-11-17
  • 打赏
  • 举报
回复
上面是好想是对iis重启的控制??
我这里有一个真正的服务器重启的代吗,不过是c#的用的wmi对象,不过可以改成asp的(asp也是可以用wmi对象的,我想有下面例子你可以自己改成asp的)
(1).连接远程计算机:

  按照下列语句可以实现连接远程计算机:


ConnectionOptions options = new ConnectionOptions ( ) ;
options.Username ="管理者帐号用户名";
options.Password = "管理者帐号口令" ;
ManagementScope scope = new ManagementScope( "\\\\" + "远程计算机名或IP地址" + "\\root\\cimv2", options ) ;
//用给定管理者用户名和口令连接远程的计算机
scope.Connect ( ) ;

  (2).得到在远程计算机中可以进行WMI控制:

System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;

  (3).调用WMI控制,实现重启远程计算机:

foreach ( ManagementObject mo in queryCollection1 )
{
string [ ] ss= { "" } ;
//重启远程计算机
mo.InvokeMethod ( "Reboot" , ss ) ;
}

  五.C#实现重启远程计算机的源程序代码(boot.cs)和执行界面:

  在了解了C#实现重启远程计算机的这些重要步骤后,就可以从容的得到重启远程计算机的完整代码,具体如下:

using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Management ;
public class Form1 : Form
{
private TextBox textBox1 ;
private TextBox textBox2 ;
private TextBox textBox3 ;
private Label label1 ;
private Label label2 ;
private Label label3 ;
private Button button1 ;
private System.ComponentModel.Container components = null ;
public Form1 ( )
{
//初始化窗体中的各个组件
InitializeComponent ( ) ;
}
//清除程序中使用过的资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing ) ;
}
private void InitializeComponent ( )
{
textBox1 = new TextBox ( ) ;
textBox2 = new TextBox ( ) ;
textBox3 = new TextBox ( ) ;
label1 = new Label ( ) ;
label2 = new Label ( ) ;
label3 = new Label ( ) ;
button1 = new Button ( ) ;

SuspendLayout ( ) ;
textBox1.Location = new System.Drawing.Point ( 140 , 46 ) ;
textBox1.Name = "textBox1" ;
textBox1.Size = new System.Drawing.Size ( 172 , 21 ) ;
textBox1.TabIndex = 0 ;
textBox1.Text = "" ;

textBox2.Location = new System.Drawing.Point ( 138 , 85 ) ;
textBox2.Name = "textBox2" ;
textBox2.Size = new System.Drawing.Size ( 174 , 21 ) ;
textBox2.TabIndex = 1 ;
textBox2.Text = "" ;

textBox3.Location = new System.Drawing.Point ( 139 , 120 ) ;
textBox3.Name = "textBox3" ;
textBox3.PasswordChar = ''*'' ;
textBox3.Size = new System.Drawing.Size ( 173 , 21 ) ;
textBox3.TabIndex = 2 ;
textBox3.Text = "" ;

label1.Location = new System.Drawing.Point ( 24 , 50 ) ;
label1.Name = "label1" ;
label1.Size = new System.Drawing.Size ( 120 , 16 ) ;
label1.TabIndex = 1 ;
label1.Text = "机器名称或IP地址:" ;

label2.Location = new System.Drawing.Point ( 37 , 88 ) ;
label2.Name = "label2" ;
label2.TabIndex = 1 ;
label2.Text = "管理者名称:" ;
label2.TextAlign = System.Drawing.ContentAlignment.TopRight ;

label3.Location = new System.Drawing.Point ( 37 , 125 ) ;
label3.Name = "label3" ;
label3.Size = new System.Drawing.Size ( 100 , 16 ) ;
label3.TabIndex = 1 ;
label3.Text = "管理者密码:" ;
label3.TextAlign = System.Drawing.ContentAlignment.TopRight ;

button1.Location = new System.Drawing.Point ( 95 , 168 ) ;
button1.Name = "button1" ;
button1.Size = new System.Drawing.Size ( 136 , 32 ) ;
button1.TabIndex = 3 ;
button1.Text = "重新启动远程计算机" ;
button1.Click += new System.EventHandler ( button1_Click ) ;

this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 336 , 245 ) ;
this.Controls.Add ( button1 ) ;
this.Controls.Add ( textBox1 ) ;
this.Controls.Add ( textBox2 ) ;
this.Controls.Add ( textBox3 ) ;
this.Controls.Add ( label1 ) ;
this.Controls.Add ( label2 ) ;
this.Controls.Add ( label3 ) ;

this.Name = "Form1" ;
this.Text = "利用C#重新启动远程计算机" ;
this.ResumeLayout(false) ;

}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{
//定义连接远程计算机的一些选项
ConnectionOptions options = new ConnectionOptions ( ) ;
options.Username = textBox2.Text ;
options.Password = textBox3.Text ;
ManagementScope scope = new ManagementScope( "\\\\" + textBox1.Text + "\\root\\cimv2", options ) ;
try {
//用给定管理者用户名和口令连接远程的计算机
scope.Connect ( ) ;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;
foreach ( ManagementObject mo in queryCollection1 )
{
string [ ] ss= { "" } ;
//重启远程计算机
mo.InvokeMethod ( "Reboot" , ss ) ;
}
}
//报错
catch ( Exception ee ) {
MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ) ;
}
}
}

孟子E章 2004-11-17
  • 打赏
  • 举报
回复
startstopservice.asp

<%@ Language=VBScript %>
<%
Response.Status = "403 Access Forbidden"
On Error Resume Next

Response.Status = "403 Access Forbidden"
Function StartStopService

Dim theServer

Dim theService

Dim theAction

Dim strPath

Dim IISObject

Dim OriginalStatus

dim theSelectServicesValue

On error Resume Next
theSelectServicesValue = Request.QueryString("view")
theServer = Request.QueryString("server")
theService = Request.QueryString("service")
theAction = Request.QueryString("action")

strPath = "WinNT://" & theServer & "/" & theService
Set IISObject = GetObject (strPath)

OriginalStatus = IISObject.Status

If Trim(theAction) = "stop" then
IISObject.Stop
Else

IISObject.Start
End If

'延时操作

Dim a
a= Now()
While (DateDiff("s",a,Now()) < 6)
Wend

Response.Write("<SCRIPT LANGUAGE='JavaScript'>" & vbcrlf)
Response.Write(" window.location.replace('displayservices.asp?view=" & theSelectServicesValue & "');" & vbcrlf)
Response.Write("</SCRIPT>" & vbcrlf)
End Function
%>
</HEAD>
<BODY>
<%StartStopService %>
</BODY>
</HTML>


需要管理员权限
孟子E章 2004-11-17
  • 打赏
  • 举报
回复
displayservices.asp

<%@ Language=VBScript%>
<%
On Error Resume Next

MY_MACHINE_NAME = ""
%>

<HTML>
<HEAD>
<TITLE>停止、启动服务程序</TITLE>

<SCRIPT LANGUAGE=javascript>
<!--
var selectedServicesValue = '<%=Request.QueryString("view")%>;';
if (selectedServicesValue=0)
selectedServicesValue=101;

function UpdateSelectedServicesValue()
{
selectedServicesValue = select1.value
window.location.replace('displayservices.asp?view='+selectedServicesValue);
}
//-->
</SCRIPT>

<%
Function BuildTable()
Dim theStatus
Dim theSelectServicesValue

theSelectServicesValue = Request.QueryString("view")

If theSelectServicesValue = 0 Then
theSelectServicesValue = 101
End If
strMachineName = MY_MACHINE_NAME
If strMachineName = "" Then
strMachineName = Request.ServerVariables("SERVER_NAME")
End If
%>

<!--Top table, holds title and dropdown box-->
<div align=center>
<table border=0 width="600" aligh="center">
<tr>
<td width='50%'><p align="left"><H4>启动或者停止<%=strMachineName%>上的服务<H4></td>
<td width='50%'><p align="right">Show
<SELECT id=select1 onchange="UpdateSelectedServicesValue();return false">
<OPTION VALUE=101 <%If theSelectServicesValue=101 then Response.Write("SELECTED")%>>All</OPTION>
<OPTION VALUE=4 <%If theSelectServicesValue=4 then Response.Write("SELECTED")%>>Started</OPTION>
<OPTION VALUE=2 <%If theSelectServicesValue=2 then Response.Write("SELECTED")%>>Starting</OPTION>
<OPTION VALUE=1 <%If theSelectServicesValue=1 then Response.Write("SELECTED")%>>Stopped</OPTION>
<OPTION VALUE=999 <%If theSelectServicesValue=999 then Response.Write("SELECTED")%>>Stopping</OPTION>
</SELECT>
</td>
</tr>
</table>

<table name=ServiceTable id=ServiceTable border = 0 cellspacing=1 bgcolor="gray" width="600">
<tr bgcolor=#0099FF><th>服务名称</th><th>服务状态</th><th>操作</th></tr>
<%

strPath = "WinNT://" & strMachineName & ",computer"

Set IISObject = GetObject (strPath)

IISObject.Filter = Array("Service")

For Each Thing in IISObject%>
<%On Error Resume Next
theStatus = 999
theStatus = Thing.Status
On Error Goto 0%>
<%If theStatus=4 and (theSelectServicesValue = 4 or theSelectServicesValue = 101) then %>
<tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#AB7BFC'" onmouseout='this.bgColor="#FFFFFF"'>
<td><%=Response.Write(Thing.Name)%></td>
<td align='middle'><%Response.Write("已启动")%></td>
<td align='middle'><%Response.Write("<a target='_self' href='startstopservice.asp?service=" & Thing.Name & "&action=stop&server=" & strMachineName & "&view=" & theSelectServicesValue & "'>停止</a></td>") %>
</tr>
<%ElseIf theStatus=2 and (theSelectServicesValue = 2 or theSelectServicesValue = 101) then%>
<tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#AB7BFC'" onmouseout='this.bgColor="#FFFFFF"'>
<td><%=Response.Write(Thing.Name)%></td>
<td align='middle'>正在启动</td>
<td>n/a</td>
</tr>
<%ElseIf theStatus=8 then%>
<tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#AB7BFC'" onmouseout='this.bgColor="#FFFFFF"'>
<td><%=Response.Write(Thing.Name)%></td>
<td align='middle'>服务错误</td>
<td align='middle'>n/a</td>
</tr>
<%elseIf theStatus=1 and (theSelectServicesValue = 1 or theSelectServicesValue = 101) then %>
<tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#AB7BFC'" onmouseout='this.bgColor="#FFFFFF"'>
<td><%=Response.Write(Thing.Name)%></td>
<td align='middle'><%Response.Write("已停止")%></td>
<td align='middle'><%Response.Write("<a target='_self' href='startstopservice.asp?service=" & Thing.Name & "&action=start&server=" & strMachineName & "&view=" & theSelectServicesValue & "'>启动</a></td>")%>
</tr>
<%ElseIf theStatus = 999 and (theSelectServicesValue = 999 or theSelectServicesValue = 101) then%>
<tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#AB7BFC'" onmouseout='this.bgColor="#FFFFFF"'>
<td><%=Response.Write(Thing.Name)%></td>
<td align='middle'>正在停止</td>
<td>n/a</td>
</tr>
<%End If
Next
%>

</table>
<%End Function%>


</HEAD>
<BODY>


<%BuildTable()%>
</BODY>
</HTML>
arcow 2004-11-17
  • 打赏
  • 举报
回复
不可能的
cueixu1 2004-11-17
  • 打赏
  • 举报
回复
shutdown.exe -r -t 0
是表示立即从其服务器
你用SHELL执行就可以了
tojworks 2004-11-17
  • 打赏
  • 举报
回复
真是晕了!
surferc 2004-11-17
  • 打赏
  • 举报
回复
突然想起一点不能到能不有在asp中创建一个shell环境这样应该能重启
surferc 2004-11-17
  • 打赏
  • 举报
回复
突然想起我哥们说的一句话:“这帮子农民真没法弄,什么都想拿asp干,就差在asp上面开飞机、跑火车了!”哇哈哈 (绝对不是针对楼主啊,想起好笑写上来了)

从理论上来说楼主的想法可以实现,找个Vhost系统看看里面可能有相关的代码。
surferc 2004-11-17
  • 打赏
  • 举报
回复
楼主,服务器都停了,asp不能解析执行。
yangchuzi 2004-11-17
  • 打赏
  • 举报
回复
我是想重启服务器

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧