Announcement

Collapse
No announcement yet.

Help request with a logon script to update a program file

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

  • Help request with a logon script to update a program file

    Hi all,

    First off I want to say how much I appreciate the forum you guys have created here. Scripting is something I'm very much wanting to learn more about, but until I can, I'm hoping you guys can help with a small project I've been tasked with.

    My organization uses a software that we very much dislike because of the numerous issues that plague it. Unfortunately, we can't switch to a different software because of the nature of our business. This vendor has asked that one of our techs (me) go around to each workstation and copy an updated file to each workstation. The irony being that this program has an update service that can call home, but it's the update service itself that needs to be overwritten and it apparently can't update itself.

    Rather than going to each workstation and wasting an entire day doing their job I've tried to script something on my own. Here's what I've come up with so far, but what I need help with are some of the little side things I'd like this script to do for me:

    @echo off

    net use x: \\DCServerName\ApplicationFolder\VendorFolder\Upda teLocation
    x:
    copy *.* "C:\Program Files\VendorApplication\Application
    net use x: /delete
    exit

    This is the logon script I created, but I'm going to make it a seperate batch file so I don't have to go back and delete a large portion of the login script when I'm done. I can just delete the one line that points to this seperate batch file.

    What I could use some help with are some of the other things I'd like this script to do for me.

    1. I'd like to put in some kind of "runonce" command so this batch doesn't run repeatedly on workstations that have already received the update.

    2. Once the update runs, I'd like the batch to somehow verify that the new file has been copied to the appropriate location (the new file is a different file size if that helps). I've had it appear to run once or twice but the file doesn't always get updated. If it doesn't verify that the file was copied I'd like it to not flag the runonce switch I mentioned earlier.

    3. Once the verify has gone through, I'd like the batch to write to a text file I'll create on the DC and copy in the computer name of the workstation that just updated successfully.

    Also the /delete command to disconnect the temporary mapped drive doesn't work all the time either so if you have a suggestion of what syntax I can use to have it drop that drive more consistently that would be greatly appreciated.

    All the users are local admins on their workstations and they're all running on a WinXP environment with 2K servers.

    Any help you guys could provide will make me sing your praises.
    Last edited by StriderRyu; 13th December 2006, 01:04.

  • #2
    Re: Help request with a logon script to update a program file

    Last first.

    The net use x: /delete doesn't work because you are pointed to x:. Change back to c: first.

    Appending to a log file should be easy:

    echo %COMPUTERNAME% >> \\DC\PublicShare\LogFile.txt
    You may want to include %DATE% and %TIME% on that same line so you know when it happened.

    If you want to make sure the new EXE is in place, you could do a "dir" of the file and look for something particular using "find". For example:

    C:\WINDOWS>dir winhelp.exe
    Volume in drive C is SystemWXP
    Volume Serial Number is 946A-73CC

    Directory of C:\WINDOWS

    08/23/2001 01:00 PM 256,192 winhelp.exe
    1 File(s) 256,192 bytes
    0 Dir(s) 7,933,214,720 bytes free
    set updated=false
    dir winhelp.exe | find "256,192 bytes" > nul
    if not errorlevel 1 set updated=true
    echo %updated%
    Finally, implement a runonce feature, include a tag file in the source directory. Something named to uniquely indicate this rollout. Then test at the top of your script to see if the tag file exists in the target directory:

    if exist "C:\Program Files\VendorApplication\Application\Version_2006_1 2_13.txt" exit
    Cheers,

    Rick

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

    Comment


    • #3
      Re: Help request with a logon script to update a program file

      Woot thanks for the help. Here's what I'm currently using which includes a lot of the suggestions you gave me:

      net use x: \\DC\apps\VendorFolder\UpdatedFile.exe
      x:
      copy *.* "c:\Program Files\VendorFolder\AppFolder"
      c:
      net use x: /delete

      echo %COMPUTERNAME% %DATE% %TIME% >> \\DC\apps\VendorFolder\UpdateFodler\Updatelog.txt
      I tried adding some of the other stuff you mentioned, but I never got the syntax correct and I was trying to infer a lot of things that I don't know how to do. Here's my awful "doesn't know scripting" version of what you suggested:

      @echo off

      %systemroot%
      cd\
      cd "c:\Program Files\VendorFolder\AppFolder"
      set updated=false
      dir UpdatedFile.exe | find "32,768 bytes" > nul
      if not errorlevel 1 set updated=true
      echo %updated%

      if updated=true exit

      net use x: \\DC\apps\VendorFolder\UpdatedFile.exe
      x:
      copy *.* "c:\Program Files\VendorFolder\AppFolder"
      c:
      net use x: /delete

      echo %COMPUTERNAME% %DATE% %TIME% >> \\DC\apps\VendorFolder\UpdateFodler\Updatelog.txt
      When I try running that, I keep getting:

      =true was unexpected at this time

      I know that's coming up just because I didn't know how to implement where it's keeping the info of whether or not the updated file was actually there or not. (as you can see, my grammar is nearly as poor as my scripting skills )

      The main portion of the script seems to be running the way I had hoped. The file is getting pushed out and the update log is getting updated. If you can help out with that other stuff like the runonce and the verify that's great, but otherwise I'm good enough for now. Thanks in advance.

      Comment


      • #4
        Re: Help request with a logon script to update a program file

        if updated=true exit

        should be

        if "%updated%"=="true" exit

        BTW, the set updated=false/true and echo %updated% bits were really for informational / testing purposes. You could drop all the "updated" stuff and just do an "if not errorlevel 1 exit". Also your share on X is really the EXE name or is that a typo?
        Last edited by rvalstar; 15th December 2006, 07:54. Reason: Added BTW
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment


        • #5
          Re: Help request with a logon script to update a program file

          Can we change "exit" to something like "go to line 40" like in the old days of basic? Sorry that's all the programming I can remember. hehe

          There's parts of the script after this update, that I want to keep running if the update is already present.

          Comment


          • #6
            Re: Help request with a logon script to update a program file

            I tend to use "Flag Files". These are files that you put there to test for later

            for instance:

            echo V1.21 >UpdateVerFlag121.txt
            <time passes/things happen>

            if exist updateverflag121.txt goto label If the file's there, drop the next bit of code and go to a place in the file called "label"
            <some code> <----- This is what happens if the file ISN'T there...

            :label <------ This is a place in the file called "Label" - after this is what happens if the file WAS there...
            <some other code>
            Last edited by Stonelaughter; 20th December 2006, 01:24.


            Tom
            For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

            Anything you say will be misquoted and used against you

            Comment


            • #7
              Re: Help request with a logon script to update a program file

              p.s. rvalstar's right - you can't map a drive to an exe file... you have to map a drive to a folder.


              Tom
              For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

              Anything you say will be misquoted and used against you

              Comment


              • #8
                Re: Help request with a logon script to update a program file

                That was a typo. Missed that part of his last reply.

                Comment


                • #9
                  Re: Help request with a logon script to update a program file

                  Originally posted by Stonelaughter View Post
                  I tend to use "Flag Files". These are files that you put there to test for later
                  StriderRyu didn't seem to hook on to that first time around. Using the file size test isn't as efficient but will still do the job.

                  StriderRyu:

                  You could test for file date using the same code if file size is ever the same -- see the output of that initial winhelp dir.

                  Also, if you use a flag file, you need to make sure to only place it if the file size test succeeds as that was an initial concern (#2) of yours.

                  Regarding GOTO's (and there is a place for them), why not try an IF block using parentheses?

                  Using a flag file,

                  if not exist "C:\Program Files\...\Version_yyyymmdd.txt" (
                  all your copy logic
                  )
                  Using the IF ERRORLEVEL bit:

                  if errorlevel 1 (
                  all your copy logic
                  )
                  Do make sure you understand ERRORLEVEL. FIND sets a 0 errorlevel for success and a non-zero for failure. "if errorlevel n" is true for errorlevels >= n. "if not errorlevel n" is true for errorlevels < n. Thus notice I dropped the "not" above.

                  Do try a "help if" in a CMD box to learn more. There are all kinds of neat features like ELSE blocks and %ERRORLEVEL% that allows easier testing for specific values.
                  Cheers,

                  Rick

                  ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                  2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

                  Comment

                  Working...
                  X