Announcement

Collapse
No announcement yet.

Run script on first login only?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run script on first login only?

    Hey Guys/Gals,

    I have created a VBScript to create a set of 13 folders in a users homedrive upon login, but unfortunetely some users have already created these and we want to limit my script to only new users,

    Is there an option or addon for AD to only run this script for the first time a users logs on?

    Thanks

    Anth

  • #2
    Re: Run script on first login only?

    I dont think so. I think that you can use login script and put there smething like:

    If Not (objFileSystem.FolderExists(strFolderLocation)) Then
    Call objFileSystem.CreateFolder(strFolderLocation)
    End if
    Thanks

    Caspi

    Comment


    • #3
      Re: Run script on first login only?

      Smart script caspi.
      I think this is indeed the best solution to create subfolders by logonscript.


      When you have to create 13 subfolders this way, you best could create one subroutine in the script.
      This script shows an example how to use a Sub for folder creation.
      Code:
      'Get currentuser information
      With CreateObject("ADSystemInfo")
        Set objUser = GetObject("LDAP://" & .UserName)
        strUser          = objUser.sAMAccountName
        strHomeDirectory = objUser.homeDirectory
      End With
      If IsEmpty(strHomeDirectory) or IsNull(strHomeDirectory) Then _
      strHomeDirectory = WScript.CreateObject("WScript.Shell") _
                         .ExpandEnvironmentStrings("%homeDrive%%homepath%")
      
      
      strRoot = strHomeDirectory & "\Desktop"   '(<-- choose an existing! rootpath)
        CreateSubFolder strRoot & "\01-" & strUser
        CreateSubFolder strRoot & "\02-" & strUser
        CreateSubFolder strRoot & "\03-" & strUser
        CreateSubFolder strRoot & "\04-" & strUser
        CreateSubFolder strRoot & "\05-" & strUser
        CreateSubFolder strRoot & "\06-" & strUser
        CreateSubFolder strRoot & "\07-" & strUser
        CreateSubFolder strRoot & "\08-" & strUser
        CreateSubFolder strRoot & "\09-" & strUser
        CreateSubFolder strRoot & "\10-" & strUser
        CreateSubFolder strRoot & "\11-" & strUser
        CreateSubFolder strRoot & "\12-" & strUser
        CreateSubFolder strRoot & "\13-" & strUser
      
      Set objUser = Nothing
      wscript.quit
      
      '-----------------------------------
      sub CreateSubFolder(strFolder)
        With CreateObject("Scripting.FileSystemObject")
        If Not (.FolderExists(strFolder)) Then _
        .CreateFolder strFolder
        End With
      End Sub
      note, In the script above the folders will be created within the HOMEDIRECTORY of the user. For your case you have to change the beginning of this script according to your own script so the subfolders will be created in the user's HOMEDRIVE.

      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X