Link to home
Start Free TrialLog in
Avatar of rolamohammed
rolamohammedFlag for Saudi Arabia

asked on

How can i delete contact - one or more than 1 in specific folder


dear All,

refrence to my post in this url :-

https://www.experts-exchange.com/questions/21844678/About-Repeating-the-Script-For-Mr-Brian.html

Q1:- is there any Script ( I will consider it Script C )  you can write to Delete Specific Contacts ( more than 1contact ) ( what will happen if I want to delete 1 contact only do you think the script will be different  ) completely after I mention them in the script  from Specifc Folder like ( SEMSEM ) and after it delete the Records completely , it will send an E-mail Conatain the Following :-
 (1-  complete Computer Name like ( Rola.mydomain.com) ).
 ( 2 - Computer IP-Address ).
  3- All the Contacts ( As Full Name )  which has been deleted from the User PC according to the Script which has been excuted .
  4- Display message that say the Following  : ( All Users Has been Deleted. For any Information Contact US ).

The E-mail should be Like that :-

The following Conatcts has been deleted from  ( Rola.mydomain.com ) , IP-Address ( x.x.x.x ):
rola@aaa.com , same@aaa.com , noha@aaa.com .

No Problems at all have been found on This PC.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

please try to provide me with the script so i can start work with it.

many thanks for you .
Avatar of rolamohammed
rolamohammed
Flag of Saudi Arabia image

ASKER

guys ,

what is going on ?
Hi rolamohammed,

think it looks to most around here like work so there will be few touching it having said that, i'll take another stab at it.

do you have a file where the contacts to delete are listed? i mean how must tehe script determine which contact to delete?

bruintje

Hi,

thanks for your reply.

i could not understand you.

its not work, or i am not instruct any one to work, its just only help from you as Experts,

i hope some one help me guys please .
Hello Rola,

i'll help

do you have a file where the contacts to delete are listed?
how must the script determine which contact to delete?

Brian
Ya Brian

you are the one who knows very well.

the File is located on shared folder on the PC , and its takes all the information from it and store in the Folder SEMSEM.

so when i will delete , it will delete from the Client who this script run on him , it will not delete from the File it self ,

Please help me in this Brian .
this is not completely clear, do you need to add the contact to delete to the script itself in other words

1. you say ms x need to be deleted on machine z
2. then add the name to the script manually
3. send this script to machine z
4. and there is will delete ms x from the contact folder SEMSEM


Hi Brian ,

Good Morning ,

No, i will explain to you exactly what i need :-

as you know, i create a lof of contacts by using our script A .

then after 4 months , there are 2 or 3 contacts has left the company completely. so i need to write a script that it will delete this contacts from the Folder " SEMSEM " which has been created by Script A from all the User Machine .

but , there is one idea came to my mind, which is :-

How we are going to determine the contact or contacts which we need to delete ?

so , if we need to delete for example this user " Rola.Mohammed " with all of her completely information, how we are going to specify this ?

or, if we have multiple contacts we need to delete them from the folder " SEMSEM " , how we are going to specify for the script , please go to this folder " SEMSEM " and delete the following Contacts " ROLA.Mohammed , Ahmed .... etc " ?

and what will happen if the script could not find any contact or contacts to be deleted , is there any POP-UP message it will appear to the user him self ?

i do not know ?

Or, what do you think about this Idea :-

as long as we need to delete the contact or group of contacts , let us write them on specific excel sheet , and we will ask the script to take the complete names from excel sheet on this file , and delete them from folder " SEMSEM " .

which Idea you prefer ?

please tell me .


Hi Rola,

>>when we need to delete the contact or group of contacts , let us write them on specific excel sheet , and we will ask the script to take the complete names from excel sheet on this file , and delete them from folder " SEMSEM " 

-----------
that sounds good to me, you can also include a message for the administrator [you] that will report back if all are deleted or not

the sheet will contain the same info as the SCRIPT A sheet only with contacts that need to be deleted, i'll check on the fullname and emailaddress to delete a contact
-----------

if this sounds ok, i'll post the script


Brian

YES , Brian .

your IDEA IS WONDERFUL MAN , GOOOOOOOOOOOOOO AHEAD ,

I am waiting you .

in this HOT NIGHT and cloudy sky , its impossible to work alone in my company , i am alone here deploying your scripts and we are testing it man .

Brian , let us do this idea also in delete specific itmes from one contact .
if its possible .


i am waiting for your script man , i am waiting like i am waiting for my wedding DAY :)) .

BTW, i am not enga at all, i am joking .
'------------------
' SCRIPT C
'------------------
'this script will
'1. lookup contacts in the SEMSEM folder
'2. if found delete them
'3. and send the mail
'------------------
 
Dim objNS, oOlFolder As MAPIFolder, objOutlook, objExcel, objWorkbook, x, objContact As Outlook.ContactItem
 
Const olFolderContacts = 10
 
Set objOutlook = CreateObject("Outlook.Application")
Set objNS = objOutlook.GetNamespace("MAPI")
Set oOlFolder = objNS.GetDefaultFolder(olFolderContacts).Folders("SEMSEM")
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("\\Ho-it-htaguiam\test2\egypt-2.xls")
x = 1
 
Do Until objWorkbook.Sheets(1).Cells(x, 1).Value = ""

  Set objContact = oOlFolder.Items.Find("[FullName] = "" & objWorkbook.Sheets(1).Cells(x, 1).Value & """)
  If objContact.Email1Address = objWorkbook.Sheets(1).Cells(x, 3).Value Then
    objContact.Delete
  End If
   
  x = x + 1
   
Loop
 
Set oOlFolder = Nothing
Set objNS = Nothing
Set objOutlook = Nothing
Set objContact = Nothing
 
objWorkbook.Close False
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
 
'WScript.Echo ("Say Thanks to  us " & vbCrLf & "We are here to serve you.")
 
Dim objNet, strComputerName, strDomainName
 
Set objNet = CreateObject("WScript.NetWork")
strComputerName = objNet.ComputerName
strDomainName = objNet.UserDomain
Set objNet = Nothing
'------------------

'------------------
' ©Bill James - bill@billsway.com

Dim IP_Address: IP_Address = GetIP()
Dim ws: Set ws = CreateObject("WScript.Shell")
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim TmpFile: TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.Run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.Run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While Not .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Address") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetIP = IP
  fso.GetFile(TmpFile).Delete
  Set fso = Nothing
  Set ws = Nothing
'------------------
 
' now we have both computername and ip address
' time to send te email
 
'------------------
' source: http://www.rgagnon.com/wshdetails/wsh-0018.html

Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim ol, ns, newMail
 
ToAddress = "boma_15@hotmail.com"
MessageSubject = "Outlook Contact Update"
MessageBody = "Dear All," & vbCrLf & vbCrLf & _
           "Computer " & strComputerName & strDomainName & ", IP-Address " & IP_Address & ", has been updated by this script deleting all contacts and no problems found at all ."
 
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.To = ToAddress
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.Send
 
Set ol = Nothing: Set ns = Nothing: Set newMail = Nothing
'------------------

Ya Brian ,

this is Rola From Egypt.

is it going to mention the contacts which has been deleted from the user PC in the E-mail like that :-

 this computer has been updated by this script deleting all contacts and no problems found at all ."
the following contacts has been deleted :-
1...........................
2...........................
3...........................
4............................


thanks brian , i will test it and i will come back to you.

BTW, i deploy your scripts for 250 users untill now, and we are working in the correct way .

if you do not mind , can you please give me the chance to have some sleep and test them tommorow morning and then inform you .

brain, i am worked for the last 14 Hours, and really i need to have some food and sleep , i cant see very well in front of me .

C.U tommorow .



Goodmorning Rola,

this is a new SCRIPT C it contains the contacts that have been deleted

'------------------
' SCRIPT C
'------------------
'this script will
'1. lookup contacts in the SEMSEM folder
'2. if found delete them
'3. and send the mail
'------------------
 
Dim objNS, oOlFolder As MAPIFolder, objOutlook, objExcel, objWorkbook, x, objContact As Outlook.ContactItem
Dim strBody2

Const olFolderContacts = 10
 
Set objOutlook = CreateObject("Outlook.Application")
Set objNS = objOutlook.GetNamespace("MAPI")
Set oOlFolder = objNS.GetDefaultFolder(olFolderContacts).Folders("SEMSEM")
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("\\Ho-it-htaguiam\test2\egypt-2.xls")
x = 1
strBody2 = ""

Do Until objWorkbook.Sheets(1).Cells(x, 1).Value = ""

  Set objContact = oOlFolder.Items.Find("[FullName] = "" & objWorkbook.Sheets(1).Cells(x, 1).Value & """)
  If objContact.Email1Address = objWorkbook.Sheets(1).Cells(x, 3).Value Then
    objContact.Delete
    strBody2 = strBody2 & x & ". " & objContact.FullName & vbCrLf
  End If
  x = x + 1
   
Loop
 
Set oOlFolder = Nothing
Set objNS = Nothing
Set objOutlook = Nothing
Set objContact = Nothing
 
objWorkbook.Close False
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
 
'WScript.Echo ("Say Thanks to  us " & vbCrLf & "We are here to serve you.")
 
Dim objNet, strComputerName, strDomainName
 
Set objNet = CreateObject("WScript.NetWork")
strComputerName = objNet.ComputerName
strDomainName = objNet.UserDomain
Set objNet = Nothing
'------------------

'------------------
' ©Bill James - bill@billsway.com

Dim IP_Address: IP_Address = GetIP()
Dim ws: Set ws = CreateObject("WScript.Shell")
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim TmpFile: TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
Dim ThisLine, IP
  If ws.Environment("SYSTEM")("OS") = "" Then
    ws.Run "winipcfg /batch " & TmpFile, 0, True
  Else
    ws.Run "%comspec% /c ipconfig > " & TmpFile, 0, True
  End If
  With fso.GetFile(TmpFile).OpenAsTextStream
    Do While Not .AtEndOfStream
      ThisLine = .ReadLine
      If InStr(ThisLine, "Address") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
    Loop
    .Close
  End With
  'WinXP (NT? 2K?) leaves a carriage return at the end of line
  If IP <> "" Then
    If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
  End If
  GetIP = IP
  fso.GetFile(TmpFile).Delete
  Set fso = Nothing
  Set ws = Nothing
'------------------
 
' now we have both computername and ip address
' time to send te email
 
'------------------
' source: http://www.rgagnon.com/wshdetails/wsh-0018.html

Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim ol, ns, newMail
 
ToAddress = "boma_15@hotmail.com"
MessageSubject = "Outlook Contact Update"
MessageBody = "Dear All," & vbCrLf & vbCrLf & _
           "Computer " & strComputerName & strDomainName & ", IP-Address " & IP_Address & ", has been updated by this script deleting all contacts and no problems found at all ." & vbCrLf
           
MessageBody = MessageBody & "The following contacts have been deleted:" & vbCrLf

MessageBody = MessageBody & strBody2

Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.To = ToAddress
newMail.Subject = MessageSubject
newMail.Body = MessageBody
newMail.Send
 
Set ol = Nothing: Set ns = Nothing: Set newMail = Nothing
'------------------

Brian ,

i do not understand fully about this script.

How its going to delete the contacts , or how it will know that , these contacts need to be deleted ?

Please , be with me , i am not able to imagin it completely with my self , so i will be very happy if you help me to do that .

thanks
it will open the file with contacts to delete, yoiu probably need to name it differently like egypt-contact delete.xls

---------
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("\\Ho-it-htaguiam\test2\egypt-2.xls")
x = 1
strBody2 = ""
---------

then it starts to loop through the contacts
---------
Do Until objWorkbook.Sheets(1).Cells(x, 1).Value = ""
---------

next it will check the contactname in Column 1
---------
  Set objContact = oOlFolder.Items.Find("[FullName] = "" & objWorkbook.Sheets(1).Cells(x, 1).Value & """)
---------

then it checks the mail address
---------
  If objContact.Email1Address = objWorkbook.Sheets(1).Cells(x, 3).Value Then
---------

if these 2 are found in the list then it actually deletes the contact
---------
    objContact.Delete
---------

this string will build up for every contact deleted to send in the mail later
---------
    strBody2 = strBody2 & x & ". " & objContact.FullName & vbCrLf
---------

is this more clear? if not ask for clarification

brian ,

thanks for your help,

i know i made a lot of confuse for you ,

please , i discover some issue with Script A , while i am deploying it for my CEO , Please have a look to it , its urgent for me , we have duplicated itmes , please help me , here is the location .

https://www.experts-exchange.com/questions/21850507/For-Mr-Brian-Urgent-Regarding-Script-A-B.html


ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial