Search Windows and Linux Networking

Thursday, December 22, 2011

VBScript for Map share folder as Z: drive

VBScript for Map share folder as Z: drive 


'VBScript to Map folder as Z: Drive
Option Explicit
Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "Z:" , "\\Server.domainname.com\Share\"

Friday, December 9, 2011

Step by Step How to: Uninstalling Zabbix Agent from Windows system.

Step by Step How to: Uninstalling Zabbix Agent from Windows system.

Suppose you have installed Zabbix Agent in C:\Program Files\Zabbix with following method :-

Echo Server=192.168.73.142 > "c:\Program Files\zabbix\zabbix_agentd.conf"
Echo Hostname=%COMPUTERNAME% >> "c:\Program Files\zabbix\zabbix_agentd.conf"
"C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –i
"C:\Program Files\zabbix\zabbix_agentd.exe" -c "c:\Program Files\zabbix\zabbix_agentd.conf" –s


And you want to uninstall it now to do fire the following command from command prompt:

Note:- It is always good option to backup our configuration file want to use later.

C:\Program Files\Zabbix>zabbix_agentd.exe -x -c"C:\Program Files\Zabbix\zabbix_agentd.Conf"
C:\Program Files\Zabbix>zabbix_agentd.exe -d -c"C:\Program Files\Zabbix\zabbix_agentd.Conf"
rmdir /s "C:\Program Files\Zabbix"


This will uninstall windows zabbix agnet from your system. 1st command stop zabbix agent service , 2nd uninstalled zabbix agent and last one do cleanup by deleting Zabbix directory with all constant from it. 

Thursday, December 8, 2011

Using Split Function in VBScript

Using Split Function in VBScript to get needed value

'Using Split Function with delimited with ://

Dim strOutPut ,i, strMngrDn
Dim strValue

strOutPut = "LDAP://cn=Sandeep Kapadane,OU=Pune,DC=Domainname,DC=com"
strValue = Split(strOutPut,"://")

For i = 0 to Ubound(strValue)
    strmngrDn=strValue(1)
Next
Msgbox strMngrDN


OUT PUT OF strMngrDN will be:-
cn=Sandeep Kapadane,OU=Pune,DC=Domainname,DC=com



Tuesday, December 6, 2011

Excel Function to split text from one cell to other two cells

Excel Function (formula) to split text from one cell to other two Cells

Suppose you have excel file with User name in same cell like shown in following screen shot.


and If you want to split cell in other column cell for First name and Last Name.Then write the function MID

=MID(A2,1,SEARCH(" ",A2)) 

To get First Name of (Sandeep Kapadane) result will be Sandeep.

And to get Last name in other cell then write the function as:-

=MID(A2,SEARCH(" ",A2)+1,20)

To get Last Name of (Sandeep Kapadane) result will be Kapadane

Now drag the formula to apply to all you result will be look like




Friday, December 2, 2011

Simple C program asking user to press ENTER Key and ignore other all keys before continue

Simple C program asking user to press ENTER Key and ignore other keys before continue

 /* Simple program asking user to press ENTER Key and ignore other */
/* Author: Sandeep           Date: 1 DEC 2011 */

#include<stdio.h>
#include<conio.h>
main()
{  char name[80];
   printf("Enter your Name:");
   scanf("%s",&name);
   printf("\nPress \"ENTER\" Key to Continue...");
  
   while(getch()!=0x0d);   /* This is the statement  checking input key with value 0x0d hex value of Enter */
  
   printf("\nHello %s how are you?",name);
   printf("\nPress Any key to Exit");
   getch();
   return(0);
}

VBScript for Search for all users in Windows Active Directory and export it in to well formatted Excel file

Search for all users in Windows Active Directory and export it in to well formatted  Excel file using VBScript.

If Your boss want all users Email address in excel file from you and your Active Directory having more than 50 to 100 user then it is boring job to type or copy and pest all users details in excel file to do job easy write VBScript file that do what you want within 3 to 5 min. and your boss also happy on your work for quick response. so if  you want t  export active directory user full name and email address in to MS-Excel file copy it into text file and save it as ADUserInExcel.vbs.

Option Explicit
Dim adocommand, adoconnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN , strGivenNAme ,strSN, strmail
Dim objExcel, objwb, objrange, x

Set objExcel = createObject("Excel.Application")
set objwb = objExcel.Workbooks.add
set objwb = objExcel.activeWorkBook.Worksheets(1)
objwb.Name = "User Information "

ObjExcel.Visible = True
objwb.Activate
objwb.Cells(1,1).Value = "First Name"
objwb.Cells(1,2).value = "Last Name"
objwb.Cells(1,3).value = "Dispaly Name"
objwb.Cells(1,4).value = "Login Name"
objwb.Cells(1,5).value = "Email Address"
set objrange = objExcel.Range("A1","E1")
objRange.Interior.ColorIndex = 15
objRange.font.Bold = True

x= 2


'Setup ADO Objects.
Set adocommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOobject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory Domain
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

'Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,cn,givenName,sn,mail"

'Constuct the LDAP syntax query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adocommand.commandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("TimeOut") = 30
adoCommand.properties("Cache Results") = False

' Run the query

Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
  ' Retrieve values and display.
   strName = adoRecordset.Fields("sAMAccountName").Value
   strCN = adoRecordset.Fields("cn").Value
   strGivenName = adoRecordset.Fields("givenName")
   strSN = adoRecordset.Fields("sn").Value
   strmail = adoRecordset.Fields("mail").Value
  
   ' Write data in Excel file

   objwb.Cells(x,1).Value = strGivenName
   objwb.Cells(x,2).value = strSN
   objwb.Cells(x,3).value = strCN
   objwb.Cells(x,4).value = strName
   objwb.Cells(x,5).value = strmail

   'Move to the Next Record in the recordset.
   adoRecordSet.MoveNext
   x = x + 1
Loop

'autofit the output
 Set objRange = objwb.UsedRange
 objRange.EntireColumn.Autofit()


'Clean up.
adoRecordSet.Close
adoConnection.Close

' Display Massage All Done

MsgBox "Done"

It will open excel file and write all user information in to excel file the format it. Time Saving Job.:-)