• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Shut Down Windows

Hi! Is it possible to write a code to shut down windows using vbscript through browser??
0
wongww
Asked:
wongww
1 Solution
 
PaulHewsCommented:
I hope not!  Hopefully we still have some security in our browser.
0
 
yongyihCommented:
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
 
manojanandCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
manojanandCommented:
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
 
PaulHewsCommented:
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
 
kodiakbearCommented:
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
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
 
catfish2k1Commented:
Hi wanted tospeak with manojanand if you can email at mcpetrina@hotmail.com. I have a question.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now