Solved

logoff n shutdown

Posted on 2008-10-04
17
971 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
Technology Partners: 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!

 

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 50 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 50 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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