Tuesday, December 30, 2008

Remote Shut down-Script

******Shutdown, power off or restart the machine remotely ******

Dim x, y
Set objWShell = CreateObject("WScript.Shell")
Set x =CreateObject("WScript.Shell")

'wait for 10 Sec for confirmation,if not confirm it as "Yes"

y=x.Popup("System about to shutdown in 10 seconds",10,"Answer This Question:",4 + 32)

if y=7 then


Set objCmd = objWShell.Exec("shutdown /l /a /y")
else

Set objCmd = objWShell.Exec("shutdown -s -t 01")

end if

*******Other Arguments ********





Argument detials


-s shutdown the computer

-f Forces the applications to close ,close the hung/busy application instantly without prompting you to end the application manually(end now)

-a Aborts system Shut down instantly (if confirmation is no,"shutdown /l /a /y" in above example)

-t Interval for shutdown.

-r Restarts

-l Local Machine

-m \\computer_name_or_IP_Address Remote Machine

shutdown -s -f -t 10 -m \\10 indicates seconds to wait before shutdown




Friday, December 12, 2008

Sending mails from sql server

Configure datqabase email in the server...


USE MyDB
GO
Declare @tableHTML NVARCHAR(MAX)
-- @query='select * from Employee where Id=78';
SET @tableHTML =
N '<>Employee Entry Details Report' +
N '< border="1">' +
N '<><>Id< /th><>Date< /th><>EmployeeName' +
N '<>Intime< /tr>' +
CAST ( ( SELECT td =H_Id, '',
td =convert(varchar,getdate(),106), '',
td = (H_Firstname + ' ' + rtrim(H_LAstname)),'',
td = (mydb.acsuser.getFirstInTime(H_Id,convert(varchar,getdate(),106))), ''
FROM mydb.dbo.employee where H_Manager_Id=2034
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'< /table>' ;


EXEC msdb.dbo.sp_send_dbmail @profile_name='Pname',

mailto:recipients=,
--@query='select rtrim(H_Id),cast((H_Firstname + '' '' + rtrim(H_LAstname)) as varchar(100)) as Employeename,cast(mydb.acsuser.getFirstInTime(H_Id,convert(varchar,getdate(),106)) as varchar(20)) as FirstIntime from mydb.Employeed where H_Manager_Id=2034',
@subject='Employee Entry Timings',
@body= @tableHTML,
@body_format = 'HTML',
--Attach output inside the body
-- @attach_query_result_as_file = 0 ,
--seperator
@query_result_separator = '',
--@query_result_separator ='char(10)',
--@query_result_width =880,
@query_result_header =0,
--exclude output message
@exclude_query_output = 1,
@query_no_truncate =1;


''''''''''Usefull links for the concept''''''''''''''''''''''''''''
http://msdn.microsoft.com/en-us/library/ms190307.aspx
http://msdn.microsoft.com/en-us/library/bb510680.aspx
http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/