Solved

logoff n shutdown

Posted on 2008-10-04
17
964 Views
Last Modified: 2010-05-18
vbs code to logoff and shutdown pc without any user permission.
0
Comment
Question by:ankur3020
  • 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now