+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Be Gentle! in Coding and Web Development; This is my first post so I hope I get it right! I am trying to write a simple batch ...
  1. #1

    Join Date
    Jun 2014
    Location
    London
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Wink Be Gentle!

    This is my first post so I hope I get it right!

    I am trying to write a simple batch file for the company I work for which will shut down Microsoft Lync (I have sussed that bit) and then delete 2 files from the following location as we are having address book update issues:

    C:\Users\myusername\AppData\Local\Microsoft\Commun icator\sip_my.name@mycompany.com\GalContacts.db
    C:\Users\myusername\AppData\Local\Microsoft\Commun icator\sip_my.name@mycompany.com\GalContacts.db.id x

    This is the script I wrote for MY account:

    -------------
    echo off
    taskkill /f /im communicator.exe
    echo Communicator has shut down
    pause
    C:
    del "C:\Users\myusername\AppData\Local\Microsoft\Commu nicator\sip_my.name@mycompany.com\GalContacts.db"
    del "C:\Users\myusername\AppData\Local\Microsoft\Commu nicator\sip_my.name@mycompany.com\GalContacts.db.i dx"
    echo Files Deleted
    pause

    -------------

    Now, the problem I have is that I have been asked to create this for any user that logs in to a machine in our board room.
    How can I change it so that the users username will be inserted where 'myusername' and 'sip_my.name@mycompany.com' is?
    I am quite new to scripting so any help would be greatly appreciated!

    Kind regards

  2. #2
    Griff's Avatar
    Join Date
    Feb 2009
    Location
    Bedfordshire
    Posts
    514
    Thank Post
    199
    Thanked 95 Times in 77 Posts
    Rep Power
    38
    GET HIM !! RAAAAAAAAAAAR!

    only joking! Hi there.

    I think you can just use %USERNAME% ?? not sure about the email bit though is it the same as their logon name for windows?

  3. #3

    Join Date
    Mar 2007
    Posts
    1,753
    Thank Post
    79
    Thanked 288 Times in 219 Posts
    Rep Power
    85
    I thinik you can address appdata directly using %appdata%\Local\Microsoft\Commun icator\sip_my.name@mycompany.com\GalContacts.db

    Disclaimer. I'm thinking out loud here. Test test and test!

  4. #4
    DevilsAdvocate's Avatar
    Join Date
    May 2007
    Location
    West Midlands
    Posts
    406
    Thank Post
    19
    Thanked 40 Times in 31 Posts
    Rep Power
    45
    C:\Users\%username%\AppData\Local\Microsoft\Commun icator\sip_my.name@mycompany.com\GalContacts.db
    C:\Users\%username%\AppData\Local\Microsoft\Commun icator\sip_my.name@mycompany.com\GalContacts.db.id x"

    However, i'm not sure how you will target the specific sip account folder.

    How are you SIP account names formatted? Ours are username based and the following - C:\Users\%username%\AppData\Local\Microsoft\Commun icator\sip_%username%@mycompany.com\GalContacts.db .idx works OK for me.
    Last edited by DevilsAdvocate; 3rd June 2014 at 09:21 AM.

  5. #5

    Join Date
    Jun 2014
    Location
    London
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks everyone for getting back so quickly.

    I have tried the %username% option but get the error - 'The filename, Directory name, or volume syntax label is incorrect'???
    I have also tried the %appdata% option but get the error - 'The system cannot find the path specified'???

    Also, the SIP_MY.NAME is based on our email which would be bob.builder@mycompany.com whereas our usernames are BUI59900 (first 3 letters of surname followed by staff number)

    I would pull my hair out if I had any!!
    Again, any (more) help would be appreciated!

    Kind regards

  6. #6

    Join Date
    Mar 2007
    Posts
    1,753
    Thank Post
    79
    Thanked 288 Times in 219 Posts
    Rep Power
    85
    %USERPROFILE%\AppData\Local
    will direct to local folder.

    Link attached will help you set email address as a local VAr then your can recall it from the command line.
    http://blog.thesysadmins.co.uk/creat...directory.html

  7. #7


    Join Date
    Jan 2012
    Posts
    2,595
    Thank Post
    929
    Thanked 344 Times in 264 Posts
    Rep Power
    211
    echo off
    Use @echo off - it silences the "echo off" command, too.

    taskkill /f /im communicator.exe
    No issue here.

    echo Communicator has shut down
    Error checking would be better than an echo that will tell you it was shut down even if it wasn't.

    pause
    Pauses are good, but if you can incorporate error checking, you only need to pause if an error is encountered.

    C:
    If you're declaring explicit paths I'm pretty sure you don't need this line at all.

    del "C:\Users\myusername\AppData\Local\Microsoft\Commu nicator\sip_my.name@mycompany.com\GalContacts.db"
    del "C:\Users\myusername\AppData\Local\Microsoft\Commu nicator\sip_my.name@mycompany.com\GalContacts.db.i dx"

    Yep, those are fine.

    echo Files Deleted
    pause

    Again, error checking and an unneeded pause


    Now, I'm not going to hark on about error checking and not give you an example.. The most simple method is using ERRORLEVEL 0, which for every command, means "Everything went OK" (or at least "I did my bit fine")
    Code:
    IF NOT %ERRORLEVEL%==0 (
    
    ECHO Sum'n wen' wrong Cap'n! PAUSE EXIT /b
    ) ELSE (
    (The next bit of your script)
    )
    This would mean that if the ERRORLEVEL was not 0 (A lot of commands can have multiple ERRORLEVELs, each meaning different things, so it gets more complicated the more you dive into it) it would throw the error (via echo) and pause the script. If the ERRORLEVEL is 0, though, it ignores that and goes to the next bit in the script (ELSE).. Batch also supports ELSEIF for multiple conditions which comes in handy later. Using ELSE also has the added advantage that the script will not attempt to continue on with the script if it hits an error (as most of the time, you're checking because one thing relies on something else being done previously and borks up if condition A isn't fulfilled) - If it meets the first condition (IF) it will not go to the next (ELSE). You can use EXIT /b to halt and exit at any point, which is also handy at times.

    Overall your script is pretty sound, though. I moved on from Batch to PowerShell quite quickly so I don't know much about how to help you there.. But %USERNAME% will always be the name of the current user (unless your script explicitly overwrites it, not recommended).. The e-mail bit would be a bit more complicated depending on how your e-mails are formatted. For example, our emails here are YYYYYX@... (whereas YYYYY is full surname and X is first initial) There are still ways to do this in batch, though. So the big question is "How are peoples' e-mail addresses formatted?"
    Last edited by Garacesh; 3rd June 2014 at 11:05 AM.

  8. #8
    Joanne's Avatar
    Join Date
    Nov 2007
    Location
    Lancashire
    Posts
    1,504
    Thank Post
    116
    Thanked 112 Times in 104 Posts
    Blog Entries
    17
    Rep Power
    74
    Could you run a script that searched the Users folder for the files GalContacts.db and GalContacts.db.id x then delete them? Then stick it in startup for all users?

    Kinda like the delete desktop.ini script job...

    Code:
    @echo on
    
    e:
    
    erase desktop.ini /A:H
    I'm rubbish at scripts though, so sorry if I am thinking too simple!

  9. #9

    Join Date
    Jun 2014
    Location
    London
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks a million to all of you for the info, it has definitely given me a few more ways to try as opposed to just using my 'simple' script!

    Kind regards

SHARE:
+ Post New Thread

Similar Threads

  1. New Website...be gentle :S
    By Duane_Dibbley in forum Web Development
    Replies: 30
    Last Post: 28th May 2010, 03:11 PM
  2. Replies: 9
    Last Post: 8th November 2005, 09:45 AM
  3. Data Projector being stupid
    By e_g_r in forum Hardware
    Replies: 3
    Last Post: 19th October 2005, 03:27 PM
  4. poptech being streamed live
    By russdev in forum General Chat
    Replies: 0
    Last Post: 28th September 2005, 07:50 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •