Announcement

Collapse
No announcement yet.

vbscript that will run and write to a file

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

  • vbscript that will run and write to a file

    Hi All,

    I'm trying to get a VB script to work as a logoff script that will be applied to GPO for users to logoff.

    Basically what the script will do is to rename a folder to something else.

    After that it will write to a text file and then reboot the machine.

    What will happen then is the GPO will install the new version of the software.

    But if the user restarts again I don't want to logoff script to run again if that file that was written the first time it ran.

    Basically the new software is the same software installing to the same folder but a different revision.

    Is there anyway I can do this?

    I got the code so far for renaming the folder

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.MoveFolder "C:\\Program Files\Intuit\QuickBooks 2008-09" , "C:\\Program Files\Intuit\QuickBooks 2008-09_old"

    what would I need to do to get it so once it runs it writes to a text file that it ran or whatever and if it tries to run again and checks if that text file exists it will not rename the folder again.

    Any help would be great.

  • #2
    Re: vbscript that will run and write to a file

    Originally posted by Vann View Post
    if [...] text file exists it will not rename the folder again.
    Let's create a flag file that indicates if the script needs to be run.

    MSDN is your friend: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    Code:
    const FLAG_FILE = "C:\windows\logs\QuickBooks 2008-09.log"
    const OLD_DIR = "C:\\Program Files\Intuit\QuickBooks 2008-09"
    const NEW_DIR = "C:\\Program Files\Intuit\QuickBooks 2008-09_old"
    
    dim objFSO
    dim objTSO
    
    set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' Quit script if there is a flag file.
    if ( objFSO.FileExists(FLAG_FILE) ) then
      set objFSO = nothing
      wscript.quit
    end if
    
    objFSO.MoveFolder OLD_DIR, NEW_DIR
    
    set objTSO = objFSO.OpenTextFile(FLAG_FILE, 8, true, 0)
    objTSO.WriteLine("Quickbooks dir renamed.")
    
    objTSO.close
    set objTSO = nothing
    set objFSO = nothing
    -vP

    Comment


    • #3
      Re: vbscript that will run and write to a file

      Does the users have local Administrators or Power User Permissions?


      \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


      • #4
        Re: vbscript that will run and write to a file

        Ahh thanks heaps VonPryz. I will try and use that example and see what I can do with it.

        Cheers

        Comment


        • #5
          Re: vbscript that will run and write to a file

          Hi Rems,

          None of the usersr have any of those permissions. They would need some sort of permissions to write the file wouldn't they?

          Comment


          • #6
            Re: vbscript that will run and write to a file

            Originally posted by Vann View Post
            They would need some sort of permissions to write the file wouldn't they?
            To be able to modify the Program Files directory tree, yes. Try configuring the script to run at shutdown rather than logoff, that should overcome the permissions issue without granting your users privileges that they shouldn't have
            Gareth Howells

            BSc (Hons), MBCS, MCP, MCDST, ICCE

            Any advice is given in good faith and without warranty.

            Please give reputation points if somebody has helped you.

            "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

            "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

            Comment

            Working...
            X