Solved

Logoff VB Script for Citrix Windows Server 2003

Posted on 2006-07-06
6
464 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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