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

logoff n shutdown

vbs code to logoff and shutdown pc without any user permission.
0
ankur3020
Asked:
ankur3020
  • 7
  • 7
  • 3
3 Solutions
 
ltlbearand3Commented:
The below script will shutdown the PC.  It will give the user a one minute warning.  Just copy the code and paste into notepad.  Save the file as shutmedown.vbs and run it.

You can open a command prompt and type shutdown to see all the switches available.  This could also be done as a batch file --

Echo Off
shutdown /s

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s"

Open in new window

0
 
si_shamilCommented:
you don't need to use vbscript for that
just use a "shutdown.exe"  utility

Example: shutdown -s -t 0
and if you want to force it: shutdown -s -t 0 -f

or you can create a batch file:
@echo off
title Shutting down the system...
 
shutdown -s -t 0

Open in new window

0
 
ltlbearand3Commented:
Please note that the switches are different on Vista.  Please use the switches as noted on my first post.  If you want to do the shutdown with no warning you can do shutdown /s /f /t 0

As both I and si_shamil state, this can be done in DOS or vb script.
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
ankur3020Author Commented:
i tried this on vista, but it is not doing anything.

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s/f/t 0"

if i remove /f/t 0 then it is working but system shutdown after 1 min. i want force shutdown/logoff.
can shutdown be relpaced with logoff
please check
0
 
si_shamilCommented:
I think you have typo in the command. use space after each parameter:

shutdown /s /f /t 0

all parameters separated - (/s)   (/f)  (/t 0)

0
 
ankur3020Author Commented:
i made a vbs file with following code. when i ran it , it did nothing. just a cmd flickered and hide.

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown (/s) (/f) (/t 0)"


please make a vbs , test it in vista and attach. or email me at ankurjain30@gmail.com
0
 
si_shamilCommented:
Copy and paste this code

Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s /f /t 0"

Open in new window

0
 
ankur3020Author Commented:
i copied and run, nothing happened, again just cmd flicked for a second only. even this time i tried in xp.
0
 
si_shamilCommented:
Can you provide more info:

1: how you running the script
2: which extension you use for the script file
3: can you post here the script you ran
0
 
ankur3020Author Commented:
i retried but it works this time. i think it afraid of u.  thanks

can u tell me if i have to call logoff then what i should write in place of shutdown?
0
 
si_shamilCommented:
This wil do:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "logoff"

Open in new window

0
 
ankur3020Author Commented:
without any /s /f and /t ?
0
 
ankur3020Author Commented:
i ran the following code in vista and got error
"system can not find the file specified"

Set objShell = CreateObject("Wscript.Shell")
objShell.run "logoff"

Open in new window

0
 
si_shamilCommented:
try this then:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /l"

Open in new window

0
 
ltlbearand3Commented:
I am sorry, I forgot in Vista the /f does not work when used with /t as /t forces the logoff.  Try the below as your script --

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s /t0"

Open in new window

0
 
ankur3020Author Commented:
it worked , thanks a lot
0
 
si_shamilCommented:
You welcome!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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