Jump to content

Script To Log Off


kevan79

Recommended Posts

Ok, basically I'm looking for a script that pops up a message box with yes/no boxes, if they click no, the user is logged off before they can actually get 'into' the OS. If yes, then it proceds and logs them onto the network.

I know how to get the message box, but not sure how to code the yes/no and log off portion.

Thanks,

Kevan

Link to comment
Share on other sites


Set WshShell = WScript.CreateObject("Wscript.Shell")
intReturn = MsgBox ("If you agree click ok to continue", vbOKCancel + vbExclamation, "Alert")

if intReturn = 2 then WshShell.Run "shutdown -l" ,,True
if intReturn = 1 then wscript.quit

Link to comment
Share on other sites

Thanks alot, that works nicely...changed the Okcancel to Yesno and it is great...one question though...

My text is too long to fit on one line, actually takes several...how do I wrap this so I don't get errors?

Use & _ and then restart " and close with " again? Haven't had time to test it...just curious.

Thanks again.

Link to comment
Share on other sites

MsgBox ("If" & VBCRLF & "you" & VBCRLF & "agree" & VBCRLF & _
          "click" & VBCRLF & "ok" & VBCRLF & "to" & _
          VBCRLF & "continue", vbOKCancel + vbExclamation, "Alert")

Link to comment
Share on other sites

Ok...this is going to sound crazy...but...I've got the code working...thank you alot for that...but is there a limit as too how many characters you can put into a message box? Reason being, it's cutting off my message right int he middle of a word. It works, but I just need more space...any tips/ideas?

Thanks.

Link to comment
Share on other sites

Here it is :)

Set WshShell = WScript.CreateObject("Wscript.Shell")
intReturn = MsgBox ("THIS IS A DEPARTMENT OF DEFENSE COMPUTER SYSTEM. THIS COMPUTER SYSTEM, INCLUDING ALL RELATED EQUIPMENT,NETWORKS AND" & VBCRLF & _
"NETWORK DEVICES (SPECIFICALLY INCLUDING INTERNET ACCESS), ARE PROVIDED ONLY FOR AUTHORIZED U.S. GOVERNMENT USE." & VBCRLF & _
"DOD COMPUTER SYSTEMS MAY BE MONITORED FOR ALL LAWFUL PURPOSES, INCLUDING TO ENSURE THAT THEIR USE IS AUTHORIZED, FOR" & VBCRLF & _
"MANAGEMENT OF THE SYSTEM, TO FACILITATE PROTECTION AGAINST UNAUTHORIZED ACCESS, AND TO VERIFY SECURITY PROCEDURES," & VBCRLF & _
"SURVIVABILITY AND OPERATIONAL SECURITY.  MONITORING INCLUDES ACTIVE ATTACKS BY AUTHORIZED DOD ENTITIES TO TEST OR" & VBCRLF & _
"VERIFY THE SECURITY OF THIS SYSTEM.  DURING MONITORING, INFORMATION MAY BE EXAMINED, RECORDED, COPIED AND USED FOR" & VBCRLF & _
"AUTHORIZED PURPOSES.  ALL INFORMATION, INCLUDING PERSONAL INFORMATION, PLACED ON OR SENT OVER THIS SYSTEM MAY BE" & VBCRLF & _
"MONITORED. USE OF THIS DOD COMPUTER SYSTEM, AUTHORIZED OR UNAUTHORIZED, CONSTITUTES CONSENT TO MONITORING OF THIS" & VBCRLF & _
"SYSTEM. UNAUTHORIZED USE MAY SUBJECT YOU TO CRIMINAL PROSECUTION. EVIDENCE OF UNAUTHORIZED USE  COLLECTED DURING" & VBCRLF & _
"MONITORING MAY BE USED FOR ADMINISTRATIVE, CRIMINAL OR OTHER ADVERSE ACTION.  USE OF THIS SYSTEM CONSTITUTES CONSENT TO" & VBCRLF & _
"MONITORING FOR THESE PURPOSES.",  vbYesNo + vbExclamation, "DOD Consent to Monitoring")


if intReturn = 2 then WshShell.Run "shutdown -l" ,,True
if intReturn = 1 then wscript.quit

It didn't post as nice in here...sorry about that...but as it stands right now, the message box cuts off the test towards the end at 'col' in the word collected.

Thanks for helping out with this.

Kevan

Link to comment
Share on other sites

Yep, you ran into the and I quote "The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used." limit. In your case 1175 characters including spaces.

Why not have this as a prompt before they login? Reword it that by entering a password and logging in they agree to the terms.

run gpedit.msc

Computer Configuration\Windows Settings\Security Settings\Local Policies\Security Options

Interactive Logon: Message text for users attempting to logon

Interactive Logon: Message title for users attempting to logon

Link to comment
Share on other sites

Ah, so there is a limit...oh well.

I knew about the interactive logon thing you were talking about, but that just gives the user the "OK" box, I'll have to talk to my bosses some more to see if it is ok to break the orginal message into 2 message boxes.

Anyhow, Thanks alot for your help and I'm sure I'll be back on here asking more questions.

Thanks again,

Kevan

Link to comment
Share on other sites

Ok question.

The script isn't logging people off...it works on my personal laptop at home. But it isn't logging off people off on Windows 2k3 Server or XP Pro laptops that are a member of the domain for some reason?

ALso, in Group Policy, logon scripts are set to run synchrously (sp) but on XP domain members the scripts are running synchrously, i.e. the client boots all the way up into Windows, and they can just ignore the Yes/No boxes and click nothing.

Any ideas on this?

THanks,

Kevan

Link to comment
Share on other sites

Ok I figured out why it's not logging off...I changed the orginal script Iceman posted from vbOkCancel to vbYesNo, and this makes the boxes Yes/No, but then the script does not act as it should, i.e. log people off...so, is there a 'correct' way to make the yes/no boxes so that it will log off people?

If not, I guess Ok/Cancel will have to work, but Yes/No would be alot nicer.

Thanks,

Kevan

Link to comment
Share on other sites

Change:

if intReturn = 2 then WshShell.Run "shutdown -l" ,,True
if intReturn = 1 then wscript.quit

to:

if intReturn = 7 then WshShell.Run "shutdown -l" ,,True
if intReturn = 6 then wscript.quit

Return codes for MSGBOX:

1 OK 
2 Cancel
3 Abort
4 Retry
5 Ignore
6 Yes
7 No

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...