We help IT Professionals succeed at work.
Get Started

VB logon script only works at second logon

yccdadmins
yccdadmins asked
on
723 Views
Last Modified: 2014-01-14
Greetings all,

I've run into a strange VBScript error with a logon script I've created.  At one point the script has to copy a shortcut to the end users desktop.  This has to be copied at each logon because the URL will change from one server to another depending on which is the primary.

When the URL in the source file is changed to a new server, end users log in and the script should overwrite the existing file with the new one that has the correct URL.

Problem is, the script only seems to work the second time the end users log in.  Below is the script and any help would be great....

On Error Resume Next

'-----------------------------------------------------
'Set variables for group determination etc.
'-----------------------------------------------------
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
Set WSHShell = CreateObject("Wscript.Shell")
Set WSHProcess = WSHShell.Environment("Process")
'Set objShell = CreateObject(wscript.shell)

'-----------------------------------------------------
'Get the distinguished name of the user that logged on
'-----------------------------------------------------
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)


'-----------------------------------------------------
'Report back the groups the user belongs to.
'-----------------------------------------------------
For Each strGroup in objUser.MemberOf
    strGroupPath = "LDAP://" & strGroup
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN

'-----------------------------------------------------
'Get the Logon Server and end script if not xxxxxxx
'-----------------------------------------------------
'DomainLogonServer = WSHProcess("LogonServer")



'---------------------------------------------------------------
' Call the AD Security Group and copy appropriate shortcut.
'---------------------------------------------------------------


      Select Case strGroupName

        Case "TN-BACS Users"
           
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            set WshShell = WScript.CreateObject("WScript.Shell")
            tDesktopPath = WshShell.SpecialFolders("Desktop")
            objFSO.CopyFile "C:\Scripts\Shortcut\Picture Perfect 4 Client.*", tDesktopPath, True

        Case "TN-BACSWEB-Users"
           
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            set WshShell = WScript.CreateObject("WScript.Shell")
            tDesktopPath = WshShell.SpecialFolders("Desktop")
            objFSO.CopyFile "C:\Scripts\Shortcut\BACSWEB.*", tDesktopPath, True


    End Select



Next
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE