to execute server side exe file from client side

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnuSumesh
    New Member
    • Aug 2007
    • 96

    to execute server side exe file from client side

    Hi

    I m new to ASP 'n' this forum also.
    I m writing one code to invoke remote desktop service for given IP address. For that i m using mstsc.exe file to invoke RDP.
    I have a no of links to be displayed on the page and on click of link, RDP for that IP should be called.
    Currently i m using one button to invoke RDP.

    But i m doing some mistake. here is my code:

    serverlist.txt file just contains the username and corrosponding IP addresses.
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
    
    <%
    
    '' To Get Server List into Array corrosponding to particular User
    
    Dim ForReading
    ForReading = 1
    
    Dim list()
    Dim l
    
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
    ("C:\ServerList.txt", ForReading)
    
    Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    
    if arrServiceList(0)="anu" then
    l= Ubound(arrServiceList)
    Redim list(l)
    For i = 1 to Ubound(arrServiceList)
    list(i-1)=arrServiceList(i)
    Next 
    end if
    Loop
    %>
    
    <%
    Dim objFS, objLogFile, fo
    Dim strLogFilename
    
    strLogFilename = "testrun.log"
    
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set fo=objFS.GetFolder("c:\test") 
    Set objLogFile=fo.CreateTextFile(strLogFilename,true) 
    
    objLogFile.writeLine "starts now "
    
    public function runfile()
    
    objLogFile.writeLine "in run"
    
    dim wshell
    set wshell=CreateObject("WScript.Shell")
    
    objLogFile.writeLine "Object created"
    
    call wshell.run ("C:\windows\system32 \mstsc.exe /v:172.20.31.102")
    
    objLogFile.writeLine "after run"
    
    set wshell=nothing
    
    End function
    %>
    
    <html>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
    <body>
    <TABLE width="100%" height="100%">
    <% For i = 0 to Ubound(list)-1 %>
    <tr>
    <td> 
    <a href="#"> <img src="images\AppIcons\TerminalServices.gif"> <% =list(i) %> </a>
    </td>
    </tr>
    <% Next %>
    
    <tr>
    <td>
    <input type="button" value="click me" name="sub" onClick="<%runfile()%>" />
    </td>
    </tr>
    
    </Table>
    
    </body>
    
    </html>
    in this code:- its displaying the images with IP.
    I have inserted one button. i want to call runfile() function to be called on click event of that button.

    For testing purpose i m writing into logfile in runfile() function.

    The problem is:
    1. when i browse this page , at the same time it call the
    runfile() function 'n' write entries into file.
    2. on click of button, the function is not getting called.
    3. wshell.run ("C:\windows\sy stem32 \mstsc.exe /v:172.20.31.102 ") is not executing. The syntax is correct( i m sure abt the syntax)

    mstsc.exe file is on server side. i want it to execute from client side 'n' it should invoke RDP for the client.

    Please help me in this issue.
    I m trying from last 2 days.
    I need it urgently

    Thanks in advance.

    Anu
    Last edited by jhardman; Nov 30 '07, 10:40 PM. Reason: put code in code tags. Please note button marked - #
  • urstop
    New Member
    • Oct 2007
    • 12

    #2
    1. Thatz not how you call a funtion that is on the sever side from the button click in ASP.
    You will have to submit the page on the button click and capture the form submission and in that call the runfile method.

    2. Executing a exe on the server, this EXE even if you execute it succesfully will not be visible to you, it will be created in the ASP procress and is not visible to you, so if the EXE creates any problems it might lead to a recycle of the ASP process or hanging of the process/IIS.

    Let me know if you have any queries.

    Regards,
    UrStop

    Comment

    • AnuSumesh
      New Member
      • Aug 2007
      • 96

      #3
      hi

      thanks for reply.
      i understand i m doing wrong.
      now i have changed my code as follows:
      Code:
      <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
      <html>
      
      <HEAD>
      <TITLE></TITLE>
      </HEAD>
      <body>
      
      <%
      '' To Get Server List into Array corrosponding to particular User
      Dim ForReading
      ForReading = 1
      
      Dim list()
      Dim l
      
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
      Set objTextFile = objFSO.OpenTextFile _
          ("C:\ServerList.txt", ForReading)
      
      Do Until objTextFile.AtEndOfStream
          strNextLine = objTextFile.Readline
          arrServiceList = Split(strNextLine , ",")
      
          if arrServiceList(0)="Anu" then
              l= Ubound(arrServiceList)
              Redim list(l)
              For i = 1 to Ubound(arrServiceList)
      	   list(i-1)=arrServiceList(i)
              Next 
          end if
      Loop
      %>
      
      <form name="serverslist">
      <TABLE width="100%" height="100%">
      <% For i = 0 to Ubound(list)-1 %>
      <tr><td> 
      <a href="runfile.vbs" <% =list(i)%>> <img src="images\AppIcons\TerminalServices.gif"> </a>
      <a href="runfile.vbs" <% =list(i)%>> <% =list(i) %> </a>
      </td></tr>
      <% Next %>
      
      </Table>
      </form></body></html>
      and the runfile.vbs file is :
      Code:
      On Error Resume Next
      dim IP
      IP=WScript.Arguments.Item(0)
      	WScript.Echo "IP is "&IP
      	dim wshell
      	set wshell=CreateObject("WScript.Shell")
      	wshell.Run "some exe "& IP
      	set wshell=nothing
      Now the problem is in syntax of <a href="runfile.v bs" <% =list(i)%>>.
      vbs file starts executing on click of lick but i want to pass the parameters also.

      1. Please suggest me what should be the correct format of URL to be passed in <href= >.
      2. when vbs starts executing, it asks the user to open/Save. But i want it to run automatically without user interaction. is it possible? if yes then how?

      thanks a lot in advance.

      Anu
      Last edited by jhardman; Nov 30 '07, 10:42 PM. Reason: put code in code tags. Please note button marked - #

      Comment

      Working...