Jump to content

Recommended Posts

Posted

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\Communicator\[email protected]\GalContacts.db

C:\Users\myusername\AppData\Local\Microsoft\Communicator\[email protected]\GalContacts.db.idx

 

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\Communicator\[email protected]\GalContacts.db"

del "C:\Users\myusername\AppData\Local\Microsoft\Communicator\[email protected]\GalContacts.db.idx"

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 '[email protected]' is?

I am quite new to scripting so any help would be greatly appreciated!

 

Kind regards

Posted

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?

Posted (edited)

C:\Users\%username%\AppData\Local\Microsoft\Commun icator\[email protected]\GalContacts.db

C:\Users\%username%\AppData\Local\Microsoft\Commun icator\[email protected]\GalContacts.db.idx"

 

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\Communicator\sip_%username%@mycompany.com\GalContacts.db.idx works OK for me.

Edited by DevilsAdvocate
Posted

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 [email protected] 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

Posted (edited)

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\Communicator\[email protected]\GalContacts.db"

del "C:\Users\myusername\AppData\Local\Microsoft\Communicator\[email protected]\GalContacts.db.idx"

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")

IF NOT %ERRORLEVEL%==0 (


[indent]ECHO Sum'n wen' wrong Cap'n!
PAUSE
EXIT /b[/indent]


) ELSE (


[indent] (The next bit of your script)[/indent]


)

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?"

Edited by Garacesh
Posted

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...

 

@echo on

e:

erase desktop.ini /A:H

 

I'm rubbish at scripts though, so sorry if I am thinking too simple!

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...