Solved

Shut Down Windows

Posted on 2002-07-29
9
214 Views
Last Modified: 2010-04-24
Hi! Is it possible to write a code to shut down windows using vbscript through browser??
0
Comment
Question by:wongww
9 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 100 total points
ID: 7187053
I hope not!  Hopefully we still have some security in our browser.
0
 
LVL 2

Expert Comment

by:yongyih
ID: 7187135
how about using API in VB program? ^_^ (not related to vbscript and browser =P )

http://www.vbcode.com/asp/code.asp?lstCategory=API+Call

0
 
LVL 2

Expert Comment

by:manojanand
ID: 7187956
Hi,

   This is Anand from India, Yea it is possibe and here is what u  are looking for with this VBscript u can shutdown,loggoff,restart machine even the ,achines in the network, please give me points.



Happy Programming,
Anand.


This is a VBscript File

OPTION EXPLICIT

    'Shutdown Method Constants
    CONST CONST_SHUTDOWN                = 1
    CONST CONST_LOGOFF                  = 0
    CONST CONST_POWEROFF                = 8
    CONST CONST_REBOOT                  = 2
    CONST CONST_FORCE_REBOOT            = 6
    CONST CONST_FORCE_POWEROFF          = 12
    CONST CONST_FORCE_LOGOFF            = 4
    CONST CONST_FORCE_SHUTDOWN          = 5
     
    'Declare variables
    Dim blnLogoff, blnPowerOff, blnReBoot, blnShutDown
    Dim blnForce
    Dim intTimer
    Dim UserArray(3)
    Dim MyCount

Sub Reboot(strServer)

    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    Call HTMLHeaders

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_REBOOT)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_REBOOT)
        End If

        IF intStatus = 0 Then
            strMessage = "Reboot of machine: " & strServer & " successful."
        Else
            strMessage = "Failed to reboot machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub LogOff()
'*
'* Purpose: Logs off the user currently logged onto a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to preform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub LogOff(strServer)


    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_LOGOFF)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_LOGOFF)
        End If

        IF intStatus = 0 Then
            strMessage = "Logging off the current user on machine " & _
                         strServer & "..."
        Else
            strMessage = "Failed to log off the current user from machine " _
                & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub PowerOff()
'*
'* Purpose: Powers off a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to perform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub PowerOff(strServer)


    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_POWEROFF)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_POWEROFF)
        End If

        IF intStatus = 0 Then
            strMessage = "Power off of machine: " & strServer & " successful."
        Else
            strMessage = "Failed to power off machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub Shutdown()
'*
'* Purpose: Shutsdown a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to perform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub Shutdown(strServer)

    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_SHUTDOWN)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_SHUTDOWN)
        End If

        IF intStatus = 0 Then
            strMessage = "Shut down of machine: " & strServer & "successful."
        Else
            strMessage = "Failed to shut down machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub
0
 
LVL 2

Expert Comment

by:manojanand
ID: 7187963
Hi,

   This is Anand from India, Yea it is possibe and here is what u  are looking for with this VBscript u can shutdown,loggoff,restart machine even the ,achines in the network, If u find this code is which u want please give me points.Bye


Happy Programming,
Anand.


This is a VBscript File

OPTION EXPLICIT

    'Shutdown Method Constants
    CONST CONST_SHUTDOWN                = 1
    CONST CONST_LOGOFF                  = 0
    CONST CONST_POWEROFF                = 8
    CONST CONST_REBOOT                  = 2
    CONST CONST_FORCE_REBOOT            = 6
    CONST CONST_FORCE_POWEROFF          = 12
    CONST CONST_FORCE_LOGOFF            = 4
    CONST CONST_FORCE_SHUTDOWN          = 5
     
    'Declare variables
    Dim blnLogoff, blnPowerOff, blnReBoot, blnShutDown
    Dim blnForce
    Dim intTimer
    Dim UserArray(3)
    Dim MyCount

Sub Reboot(strServer)

    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    Call HTMLHeaders

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_REBOOT)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_REBOOT)
        End If

        IF intStatus = 0 Then
            strMessage = "Reboot of machine: " & strServer & " successful."
        Else
            strMessage = "Failed to reboot machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub LogOff()
'*
'* Purpose: Logs off the user currently logged onto a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to preform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub LogOff(strServer)


    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_LOGOFF)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_LOGOFF)
        End If

        IF intStatus = 0 Then
            strMessage = "Logging off the current user on machine " & _
                         strServer & "..."
        Else
            strMessage = "Failed to log off the current user from machine " _
                & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub PowerOff()
'*
'* Purpose: Powers off a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to perform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub PowerOff(strServer)


    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_POWEROFF)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_POWEROFF)
        End If

        IF intStatus = 0 Then
            strMessage = "Power off of machine: " & strServer & " successful."
        Else
            strMessage = "Failed to power off machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub


'********************************************************************
'*
'* Sub Shutdown()
'*
'* Purpose: Shutsdown a machine.
'*
'* Input:   strServer           a machine name
'*          strOutputFile       an output file name
'*          strUserName         the current user's name
'*          strPassword         the current user's password
'*          blnForce            specifies whether to force the logoff
'*          intTimer            specifies the amount of time to perform the function
'*
'* Output:  Results are either printed on screen or saved in strOutputFile.
'*
'********************************************************************
Private Sub Shutdown(strServer)

    ON ERROR RESUME NEXT

    Dim objFileSystem, objService, objEnumerator, objInstance
    Dim strQuery, strMessage
    Dim intStatus
    ReDim strID(0), strName(0)

    'Establish a connection with the server.
    If blnConnect("root\cimv2" , _
                   strUserName , _
                   strPassword , _
                   strServer   , _
                   objService  ) Then
        Call document.write("")
        Call document.write("Please check the server name, " _
                        & "credentials and WBEM Core.")
        Exit Sub
    End If

    strID(0) = ""
    strName(0) = ""
    strMessage = ""
    strQuery = "Select * From Win32_OperatingSystem"

    Set objEnumerator = objService.ExecQuery(strQuery,,0)
    If Err.Number Then
        Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred during the query."
        If Err.Description <> "" Then
            Print "Error description: " & Err.Description & "."
        End If
        Err.Clear
        Exit Sub
    End If

    i = 0
    For Each objInstance in objEnumerator
        If blnForce Then
            intStatus = objInstance.Win32ShutDown(CONST_FORCE_SHUTDOWN)
        Else
            intStatus = objInstance.Win32ShutDown(CONST_SHUTDOWN)
        End If

        IF intStatus = 0 Then
            strMessage = "Shut down of machine: " & strServer & "successful."
        Else
            strMessage = "Failed to shut down machine: " & strServer & "."
        End If
        Call WriteLine(strMessage,objOutputFile)
    Next

End Sub
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 38

Expert Comment

by:PaulHews
ID: 7188170
Hi Anand, welcome to Experts Exchange.  Please note that it is the etiquette here to use comments only.  The questioner can still select your answer if he feels it is the best that suits his needs.

Check this link for more information:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

Hope to see you around. :)

0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7522815
Dear manojanand
I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See: <http://www.experts-exchange.com/jsp/communityNews.jsp>
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

EXPERTS: I will return in seven days to close this question.
Please leave your thoughts and recommendations here

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Thanks !

kodiakbear
Experts Exchange Moderator
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8049093
Hi wongww,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept PaulHews's comment(s) as an answer.

wongww, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8095930
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Expert Comment

by:catfish2k1
ID: 8461624
Hi wanted tospeak with manojanand if you can email at mcpetrina@hotmail.com. I have a question.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now