ASP.net extract 7zip

cyberiadmin
cyberiadmin used Ask the Experts™
on
Hello,

How can i create a ASP.net 2.0 script that does the following in order.
1) shutdown a services
2) deletes a folder and all sub content
3) extracts a 7zip archive  
4) start up a services

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
1)

With regards to shutting down a service, you can make use of the ServiceController class

You need to add the namespace System.ServiceProcess (may need to asdd reference to it)

then find the name of your service (can be found in registry under hklm/SYSTEM/CurrentControlSet/Services

        Dim controller As New ServiceController

        controller.MachineName = "."
        controller.ServiceName = "Tomcat5"
        controller.Stop()
        controller = Nothing

the above example shuts down tomcat v5 service
Top Expert 2006

Commented:
okay I know you said asp.net 2.0 script. I am not sure what you mean by that. I assume some dotnet code? So either vb.net or c#. Considering your last couple of questions was vbscript related, I assume you will be content with vb.net

so to continue

2) try the code here http://www.java2s.com/Tutorial/VB/0160__Collections/Deleteadirectorycontainingfilesandsubdirectories.htm

Imports System.IO

Public Class Tester
    Public Shared Sub Main
   
        Try
            System.IO.Directory.Delete("c:\a", True)
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        Finally
            Beep()
        End Try
   

    End Sub

End Class

Author

Commented:
Found out how to do part 1 and part 4 but thanks for the info for part 1 as i will need to still use this else where in the coding.

dim service as New TCAdminSDK.Objects.Service
service.ServiceId="TCXXXXXXXXX"
If service.Find() Then
service.Stop()
service.Start()
End If
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

Commented:
http://en.wikipedia.org/wiki/ASP.NET

I have added an exmaple script created by LFA, that just list the server ip and port of the login user game server.
<%@ Page LANGUAGE="VB" %>

<%@ Register TagPrefix="cc1" Namespace="TCAdminSDK.Web.UI" Assembly="TCAdminSDK" %>
<html>
<head>
    <title><%=TCAdminSDK.Web.Templates.GetCustomTitle() %> - Custom Page</title>
  <SCRIPT LANGUAGE="VB" RUNAT="server">

    Private _SelectedService As TCAdminSDK.Objects.Service
    Public ReadOnly Property SelectedService() As TCAdminSDK.Objects.Service
        Get
            If _SelectedService Is Nothing Then
                _SelectedService = New TCAdminSDK.Objects.Service
                _SelectedService.ServiceID = Request.QueryString("serviceid")
                If _SelectedService.Find() Then

                    ' ''''''''''''''''''' '
                    'Basic security check '
                    ' ''''''''''''''''''' '

                    Select Case TCAdminSDK.Web.Session.CurrentUserType
                        Case TCAdminSDK.Objects.UserType.Admin, TCAdminSDK.Objects.UserType.SubAdmin

                            ' ''''''''''''''''''''''''''''''''''''''' '
                            'Admin and subadmin always has permission '
                            ' ''''''''''''''''''''''''''''''''''''''' '

                        Case TCAdminSDK.Objects.UserType.User

                            ' ''''''''''''''''''''''''''''''''''''''''''' '
                            'Current user should be the game server owner '
                            ' ''''''''''''''''''''''''''''''''''''''''''' '

                            If Not _SelectedService.UserID = TCAdminSDK.Web.Session.CurrentUser Then
                                TCAdminSDK.Web.Util.RedirectToHome()
                            End If
                        Case TCAdminSDK.Objects.UserType.SubUser

                            ' ''''''''''''''''''''''''''''''''''''''''''''''''' '
                            'Current user owner should be the game server owner '
                            ' ''''''''''''''''''''''''''''''''''''''''''''''''' '

                            If Not _SelectedService.UserID = TCAdminSDK.Web.Session.CurrentUserParentAccount Then
                                TCAdminSDK.Web.Util.RedirectToHome()
                            End If
                    End Select
                End If
            End If
            Return _SelectedService
        End Get
    End Property

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'Redirect to login page if not authenticated
        If Not TCAdminSDK.Web.Session.IsAuthenticated Then
            Response.Redirect(String.Format("Login.aspx?returnto={0}", Request.RawUrl))
        End If
    End Sub

    Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ' '''''''''''''''''''''''''''''''''''''''' '
    'You can add code for the page load event. '
    ' '''''''''''''''''''''''''''''''''''''''' '

    End Sub

  </SCRIPT>
</head>
<body>
   <!-- #Include virtual="header.aspx" -->

   <!-- --------------------------------- -->
   <!-- Create the breadcrumb manually :( -->
   <!-- --------------------------------- -->

   <div style="width: 100%; text-align: center;" id="NavigationPanel">
<table cellspacing="0" cellpadding="0" border="0" align="center" class="navigation_menu"><tr>

     <td style="width: 90%;" class="description_labels_small"><a href="admin_home.aspx"><%=iif(TCAdminSDK.Web.Session.CurrentUserType=TCAdminSDK.Objects.UserType.Admin, "Admin", "User") %> Home</a> &gt; <a href="services.aspx">Game Servers</a> &gt; <a href="<%=String.Format("service_home.aspx?serviceid={0}&svc_short_desc={1}",Me.SelectedService.ServiceId, Me.SelectedService.ShortGameNameAndSlots) %>"><%=Me.SelectedService.ShortGameNameAndSlots %></a> &gt; <%=Me.MenuHeader1.Text %> </td>
     

<td align="right" class="description_labels_small">
<span>[</span>
<a href="login.aspx?action=LogOff">Log Out</a>
<span>]</span></td>

   </tr>
</table>

</div>

   <!-- ----------------- -->
   <!-- End of breadcrumb -->
   <!-- ----------------- -->

   <cc1:menuheader id="MenuHeader1" runat="server" Width="695px" Text="Custom Page"></cc1:menuheader>

   <!-- -------------------------- -->
   <!-- Your custom code Goes Here -->
   <!-- -------------------------- -->

   <br/>Game Server Ip: <%=Me.SelectedService.ServerIP %><br/>
   Game Server Port: <%=Me.SelectedService.ServerPort %><br/>

   <!-- ------------------ -->
   <!-- End of custom code -->
   <!-- ------------------ -->

   <!-- #Include virtual="footer.aspx" -->
</body>
</html>

Open in new window

Top Expert 2006
Commented:
3) Extracting a 7zip file. I would assume it would again be command line driven

Looking at the 7zip website, it suggests HX Dos Extender http://www.7-zip.org/links.html but didnt make much sense
so found this here http://superuser.com/questions/160672/howto-use-7-zip-to-create-a-self-extracting-archive-from-dos-batch-file

I dont have 7zip but wonder if you could try out some of the examples and post what works here

http://superuser.com/questions/160672/howto-use-7-zip-to-create-a-self-extracting-archive-from-dos-batch-file

You could use the old skool vb way and use the shell function to execute this command line for 7zip, it will work but vb.net has now a Process object which you can use to execute.

Top Expert 2006

Commented:
ok, just saw your posts

its just plain old vb.net. So the code posted should work.

You said you did 1 and 4. I guess they go hand in hand. The code I have differs from yours somewhat.
Top Expert 2006

Commented:
Now I'm off to bed. I will respond to any questions you have tomorrow (later today lol)

Author

Commented:
Thanks, this will help be start off. I will continue looking into this if i do have any more questions about this, hope people do not mind me asking.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial