Solved

Logoff VB Script for Citrix Windows Server 2003

Posted on 2006-07-06
6
459 Views
Last Modified: 2010-08-05
Hi,

I have a logon script which displays a Legal notice when users logon to Citrix. Part of this asks the user to agree/disagree and if they disagree it should log them off, but this doesn't work on the Citrix server, however does on XP clients. Please can anyone help.

The script I have is as follows:

'=================================================================
Option Explicit

Dim numQuestion
Dim objFSO, objLegalFile, objMOTDFile
Dim strScriptPath, strLegalText, strMOTDText

Set objFSO = CreateObject("Scripting.FileSystemObject")

strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName)

If objFSO.FileExists(strScriptPath & "\Legal.txt") Then
      Set objLegalFile = objFSO.OpenTextFile(strScriptPath & "\Legal.txt", 1)

      strLegalText = objLegalFile.ReadAll

      numQuestion = msgbox(strLegalText, vbYesNo + vbExclamation + vbDefaultButton2 + vbSystemModal, "Company Name")
      
      If numQuestion = vbNo Then
            Logoff()

            WScript.Quit
      Else
            If objFSO.FileExists(strScriptPath & "\MOTD.txt") Then
                  Set objMOTDFile = objFSO.OpenTextFile(strScriptPath & "\MOTD.txt", 1)

                  strMOTDText = objMOTDFile.ReadAll

                  MsgBox strMOTDText, vbOKOnly + vbInformation + vbSystemModal, "Company Name"
            End If
            WScript.Quit
      End If
Else
      MsgBox "Legal notice not found. Unable to login. Please contact IT Support!", vbOkOnly + vbCritical + vbSystemModal, "Company Name"
      Logoff()
End If

' This sub will logoff the current user, forcing any current apps to close.
Sub Logoff

      ' Win32Shutdown Method Constants
      CONST vbLogoff = 0
      CONST vbShutdown = 1
      CONST vbReboot = 2
      CONST vbPowerOff = 8
      CONST vbForce = 4

      Dim OpSysSet, OpSys

        Set OpSysSet=GetObject("winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}//./root/cimv2").ExecQuery( _
                   "Select * from Win32_OperatingSystem where Primary=true")
        for each OpSys in OpSysSet
          OpSys.Win32Shutdown(vbLogoff + vbForce)
        Next

End Sub
'================================================================

Thanks
0
Comment
Question by:sterlingdev
  • 3
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
justchat_1 earned 500 total points
ID: 17053233
Theres a shortcut you can try...im not familiar with that server but if you run "shutdown -l" on the server does it log off?
0
 

Author Comment

by:sterlingdev
ID: 17128548
I would like to fix the VB script really
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17132791
Try what I posted, if it works I can post code to do the same thing in a vb script(its alot simplier then alot of api calls)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:sterlingdev
ID: 17142277
But then the users would need access to shutdown.exe right and that would be a bit of a security issue!
0
 

Author Comment

by:sterlingdev
ID: 17142279
Is there any other way?
0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17143287
All users have access to shutdown.exe (unless explicitly prevented)...its a dos commend-just like net functionality
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

12 Experts available now in Live!

Get 1:1 Help Now