Link to home
Start Free TrialLog in
Avatar of sterlingdev
sterlingdev

asked on

Logoff VB Script for Citrix Windows Server 2003

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
ASKER CERTIFIED SOLUTION
Avatar of justchat_1
justchat_1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sterlingdev
sterlingdev

ASKER

I would like to fix the VB script really
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)
But then the users would need access to shutdown.exe right and that would be a bit of a security issue!
Is there any other way?
All users have access to shutdown.exe (unless explicitly prevented)...its a dos commend-just like net functionality