Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Logoff VB Script for Citrix Windows Server 2003

Posted on 2006-07-06
6
Medium Priority
?
473 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

885 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