Really dumb VB question....

Discussion in 'Web Design & Coding' started by Mainframeguy, Nov 16, 2003.

  1. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    Maybe I am being too lazy to find out (I do code, just not in VB!)

    But is the following a valid script to shutdown windoze XP (I have delimited with <start> and <end> - rest is pasted right out of file)...

    <start>
    'Begin shell script code'
    set WshShell = CreateObject("WScript.Shell")

    WshShell.Run "c:\windows\system32\cmd.exe"


    'Wait until cmd.exe has loaded'
    While WshShell.AppActivate("c:\windows\system32\cmd.exe") = FALSE
    wscript.sleep 1000
    Wend

    'Bring cmd.exe to the foreground'
    WshShell.AppActivate "c:\windows\system32\cmd.exe"

    'Change directories and issue shutdown command
    WshShell.SendKeys "cd{\}"
    WshShell.SendKeys "{ENTER}"
    WshShell.SendKeys "cd windows{\}system32"
    WshShell.SendKeys "{ENTER}"
    WshShell.SendKeys "shutdown -s"
    WshShell.SendKeys "{ENTER}"

    'End shell script code'
    <end>

    incase you wonder why... I am trying to run this when MBM jits a temperature trigger that makes my system unstable - it is not the best script, a warning window to close apps would be kind!, but I thought it was s start.... I know you guys will tell me all about it...
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Uhm, what a waste of time to go thru all that, why not just execute shutdown directly?
     
  3. Mainframeguy

    Mainframeguy Debiant by way of Ubuntu Folding Team

    Messages:
    3,763
    Location:
    London, UK
    as you do ..... really I'd like to make it highly adaptable... any suggestions?
     
  4. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Well, if you just execute shutdown -s, from the CMD, it should find the executable itself, and execute it, no need to cd or anything