VB Code for Shutdown App

Discussion in 'Scripting & Programming' started by shadowwebs, Oct 2, 2012.

  1. shadowwebs

    shadowwebs Megabyte Poster

    842
    11
    76
    If action = "Shutdown" Then
    Shell("shutdown -t" & time _ "shutdown -s -f \\m" &workstation)

    That is the code I have entered for it to look at variables I have set named "action" and "time" and "workstation"

    Essentially, the application will look at what the user sets the "action" text to, in this case "shutdown", and then will look at what is in the "time" field and shutdown the computer based on this information.

    It doesn't like the code however, and I know this is because I am trying to continue the Shell command across both the time field, action & workstation field on one line.

    I did VB over 10 years ago, so to come back to it now is all strange so I know I am missing the obvious.

    - - - Updated - - -

    Sorted:
    If action = "Shutdown" Then
    Shell("shutdown –t " & time & " -s -f –m " & workstation)

    - - - Updated - - -

    oops, that hasnt worked either... any advice would be handy
     
    Certifications: compTIA A+, Apple Certified Technical Coordinator 10.10 (OS X Yosemite, Server and Support)
  2. BB88

    BB88 Kilobyte Poster Gold Member

    383
    13
    76
    I would add in a basic MsgBox for debugging purposes. You can make sure your variables are being declared, and have the correct information in, so:

    Code:
    MsgBox "shutdown –t " & time & " -s -f –m " & workstation
    Then make sure that the code displayed in the MsgBox is valid.
     
    Certifications: CompTIA A+, CompTIA Network+, MCSA: Office 365,, 70-410, 70-680
    WIP: CompTIA: Security+
  3. shadowwebs

    shadowwebs Megabyte Poster

    842
    11
    76
    tested that, it came up fine in the msgbox... so that leaves extra confusion as to why it's not working still.

    i shall continue to look
     
    Certifications: compTIA A+, Apple Certified Technical Coordinator 10.10 (OS X Yosemite, Server and Support)
  4. BB88

    BB88 Kilobyte Poster Gold Member

    383
    13
    76
    OK, try using something like this:

    Code:
    Dim wshShell
    Set wshShell = WScript.CreateObject("WScript.Shell")
    wshShell.Run "shutdown –t " & time & " -s -f –m " & workstation
     
    Certifications: CompTIA A+, CompTIA Network+, MCSA: Office 365,, 70-410, 70-680
    WIP: CompTIA: Security+
  5. shadowwebs

    shadowwebs Megabyte Poster

    842
    11
    76
    i have imported the code above and this comes up as 'wscript is not declared... does this need to be declared as a string also?
     
    Certifications: compTIA A+, Apple Certified Technical Coordinator 10.10 (OS X Yosemite, Server and Support)
  6. BB88

    BB88 Kilobyte Poster Gold Member

    383
    13
    76
    Which version of VB are you using?
     
    Certifications: CompTIA A+, CompTIA Network+, MCSA: Office 365,, 70-410, 70-680
    WIP: CompTIA: Security+
  7. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    You say your code "doesn't work". Exactly what about it doesn't work? does it throw an error? if so, what?

    BB88's code isn't going to work, because it's vbscript, not VB - which I'm guessing you are using.

    Have you ensured that the action you are entering is exactly the text you are checking? i.e. that the case is correct? The code as you have it is case sensitive - so if won't match unless the action you enter is exactly: "Shutdown". if it's "shutdown" (i.e. no capital S), the if will fail.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  8. BB88

    BB88 Kilobyte Poster Gold Member

    383
    13
    76
    Certifications: CompTIA A+, CompTIA Network+, MCSA: Office 365,, 70-410, 70-680
    WIP: CompTIA: Security+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.