Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

logoff n shutdown

Posted on 2008-10-04
17
Medium Priority
?
979 Views
Last Modified: 2010-05-18
vbs code to logoff and shutdown pc without any user permission.
0
Comment
Question by:ankur3020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 3
17 Comments
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22642166
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
 
LVL 5

Expert Comment

by:si_shamil
ID: 22642408
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
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22642715
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ankur3020
ID: 22643365
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
 
LVL 5

Expert Comment

by:si_shamil
ID: 22643534
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
 

Author Comment

by:ankur3020
ID: 22643817
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
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 200 total points
ID: 22643825
Copy and paste this code

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

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22644924
i copied and run, nothing happened, again just cmd flicked for a second only. even this time i tried in xp.
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22644956
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
 

Author Comment

by:ankur3020
ID: 22645140
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
 
LVL 5

Expert Comment

by:si_shamil
ID: 22645151
This wil do:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "logoff"

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22645173
without any /s /f and /t ?
0
 

Author Comment

by:ankur3020
ID: 22645183
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
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 200 total points
ID: 22645494
try this then:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /l"

Open in new window

0
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22646861
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
 

Accepted Solution

by:
ankur3020 earned 0 total points
ID: 22646862
it worked , thanks a lot
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22647294
You welcome!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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