Thursday, May 14, 2015

Image Split

public static void ImageSplit(string Filname)
        {
            // string Filname = @"E:\dodge_image\2.tif";
            Image img = Image.FromFile(Filname); // a.png has 312X312 width and height
            //int widthThird = (int)((double)img.Width / 3.0 + 0.5);
            //int heightThird = (int)((double)img.Height / 3.0 + 0.5);

            int widthThird = (int)((double)img.Width / 8.0 + 3.0);
            int heightThird = (int)((double)img.Height / 8.0 + 3.0);

            int k = 0;
            Bitmap[,] bmps = new Bitmap[8, 8];
            for (int i = 0; i < 8; i++)
                for (int j = 0; j < 8; j++)
                {
                    bmps[i, j] = new Bitmap(widthThird, heightThird);
                    Graphics g = Graphics.FromImage(bmps[i, j]);
                    g.DrawImage(img, new Rectangle(0, 0, widthThird, heightThird), new Rectangle(j * widthThird, i * heightThird, widthThird, heightThird), GraphicsUnit.Pixel);
                    g.Dispose();
                    if (!Directory.Exists("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname)))
                        Directory.CreateDirectory("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname));
                    bmps[i, j].Save("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname) + "\\" + Path.GetFileNameWithoutExtension(Filname) + "_" + k + ".bmp", ImageFormat.Bmp);
                    k++;
                }

        }

Wednesday, May 6, 2015

Read from SQL Table and Write as XML File




Read from SQL Table and Write as XML File:

 string Coon = ConfigurationManager.ConnectionStrings["ConnectionSQL"].ConnectionString;

            SqlDataAdapter DA = null;
            DataSet ds = new DataSet();
            DataTable dt = null;
            SqlConnection Con = new SqlConnection(Coon);
            string Query = "SELECT ID,NAME,SALARY,CITY FROM Customer FOR XML                    RAW('Customer'), ROOT('Customers'), ELEMENTS";

            XmlReader reader;
            XmlDocument xmlDoc;
            SqlCommand cmd = null;

            cmd = new SqlCommand(Query, Con);
            Con.Open();
            reader = cmd.ExecuteXmlReader();
            xmlDoc = new XmlDocument();
            while (reader.Read())
            {
                xmlDoc.Load(reader);
            }
            if (File.Exists(@"C:\sample.xml"))
            {
                File.Delete(@"C:\sample.xml");
                xmlDoc.Save(@"C:\sample.xml");
            }
            else
            {
                xmlDoc.Save(@"C:\sample.xml");
            }

            Con.Close();

            MessageBox.Show("Completed");


Read XML File and  Display in List

     XmlReader xReader = XmlReader.Create(@"E:\sample.xml");
            while (xReader.Read())
            {
                switch (xReader.NodeType)
                {
                    case XmlNodeType.Element:
                        listBox1.Items.Add("<" + xReader.Name + ">");
                        break;
                    case XmlNodeType.Text:
                        listBox1.Items.Add(xReader.Value);
                        break;
                    case XmlNodeType.EndElement:
                        listBox1.Items.Add("</" + xReader.Name + ">");
                        break;
                }
            }

Encrypt and Decrypt Web.config File

For Encryption:


Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSection =config.GetSection("connectionStrings");
            if (!configSection.SectionInformation.IsProtected)
            {
                configSection.SectionInformation.
                    ProtectSection("DataProtectionConfigurationProvider");
                config.Save();
                Response.Write("ConnectionStrings has been encryted successfully.");
            }
            else
            {
                Response.Write("ConnectionStrings has been encryted, this action has been cancled");
            }





For Decryption:

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = config.GetSection("connectionStrings");
            if (configSect.SectionInformation.IsProtected)
            {
                configSect.SectionInformation.UnprotectSection();
                config.Save();
                Response.Write("ConnectionStrings has been Decrypted successfully.");

            }

Thursday, May 9, 2013

Sql Injection Reference

http://resources.infosecinstitute.com/dumping-a-database-using-sql-injection/

RUN Command ShortCuts



1. Accessibility Controls - access.cpl
2. Accessibility Wizard - accwiz
3. Add Hardware Wizard - hdwwiz.cpl
4. Add/Remove Programs - appwiz.cpl
5. Administrative Tools - control admintools
6. Automatic Updates - wuaucpl.cpl
7. Bluetooth Transfer Wizard - fsquirt
8. Calculator - calc
9. Certificate Manager - certmgr.msc
10. Character Map - charmap
11. Check Disk Utility - chkdsk
12. Clipboard Viewer - clipbrd
13. Command Prompt - cmd
14. Component Services - dcomcnfg
15. Computer Management - compmgmt.msc
16. Control Panel - control
17. Date and Time Properties - timedate.cpl
18. DDE Shares - ddeshare
19. Device Manager - devmgmt.msc
20. Direct X Troubleshooter - dxdiag
21. Disk Cleanup Utility - cleanmgr
22. Disk Defragment - dfrg.msc
23. Disk Management - diskmgmt.msc
24. Disk Partition Manager - diskpart
25. Display Properties - control desktop
26. Display Properties - desk.cpl
27. Dr. Watson System Troubleshooting­ Utility - drwtsn32
28. Driver Verifier Utility - verifier
29. Event Viewer - eventvwr.msc
30. Files and Settings Transfer Tool - migwiz
31. File Signature Verification Tool - sigverif
32. Findfast - findfast.cpl
33. Firefox - firefox
34. Folders Properties - control folders
35. Fonts - control fonts
36. Fonts Folder - fonts
37. Free Cell Card Game - freecell
38. Game Controllers - joy.cpl
39. Group Policy Editor (for xp professional) - gpedit.msc
40. Hearts Card Game - mshearts
41. Help and Support - helpctr
42. HyperTerminal - hypertrm
43. Iexpress Wizard - iexpress
44. Indexing Service - ciadv.msc
45. Internet Connection Wizard - icwconn1
46. Internet Explorer - iexplore
47. Internet Properties - inetcpl.cpl
48. Keyboard Properties - control keyboard
49. Local Security Settings - secpol.msc
50. Local Users and Groups - lusrmgr.msc
51. Logs You Out Of Windows - logoff
52. Malicious Software Removal Tool - mrt
53. Microsoft Chat - winchat
54. Microsoft Movie Maker - moviemk
55. Microsoft Paint - mspaint
56. Microsoft Syncronization Tool - mobsync
57. Minesweeper Game - winmine
58. Mouse Properties - control mouse
59. Mouse Properties - main.cpl
60. Netmeeting - conf
61. Network Connections - control netconnections
62. Network Connections - ncpa.cpl
63. Network Setup Wizard - netsetup.cpl
64. Notepad - notepad
65. Object Packager - packager
66. ODBC Data Source Administrator - odbccp32.cpl
67. On Screen Keyboard - osk
68. Outlook Express - msimn
69. Paint - pbrush
70. Password Properties - password.cpl
71. Performance Monitor - perfmon.msc
72. Performance Monitor - perfmon
73. Phone and Modem Options - telephon.cpl
74. Phone Dialer - dialer
75. Pinball Game - pinball
76. Power Configuration - powercfg.cpl
77. Printers and Faxes - control printers
78. Printers Folder - printers
79. Regional Settings - intl.cpl
80. Registry Editor - regedit
81. Registry Editor - regedit32
82. Remote Access Phonebook - rasphone
83. Remote Desktop - mstsc
84. Removable Storage - ntmsmgr.msc
85. Removable Storage Operator Requests - ntmsoprq.msc
86. Resultant Set of Policy (for xp professional) - rsop.msc
87. Scanners and Cameras - sticpl.cpl
88. Scheduled Tasks - control schedtasks
89. Security Center - wscui.cpl
90. Services - services.msc
91. Shared Folders - fsmgmt.msc
92. Shuts Down Windows - shutdown
93. Sounds and Audio - mmsys.cpl
94. Spider Solitare Card Game - spider
95. SQL Client Configuration - cliconfg
96. System Configuration Editor - sysedit
97. System Configuration Utility - msconfig
98. System Information - msinfo32
99. System Properties - sysdm.cpl
100. Task Manager - taskmgr
101. TCP Tester - tcptest
102. Telnet Client - telnet
103. User Account Management - nusrmgr.cpl
104. Utility Manager - utilman
105. Windows Address Book - wab
106. Windows Address Book Import Utility - wabmig
107. Windows Explorer - explorer
108. Windows Firewall - firewall.cpl
109. Windows Magnifier - magnify
110. Windows Management Infrastructure - wmimgmt.msc
111. Windows Media Player - wmplayer
112. Windows Messenger - msmsgs
113. Windows System Security Tool - syskey
114. Windows Update Launches - wupdmgr
115. Windows Version - winver
116. Wordpad - write

Monday, November 7, 2011

Auto start/stop timer when keyboard& Mouse idle mode

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;


namespace afp_Login
{
public partial class Form2 : Form
{
int Timecounter = 0;
Stopwatch stopwarch;
TimeSpan ts;

public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
stopwarch = new Stopwatch();
stopwarch.Start();

}
private void timer1_Tick(object sender, EventArgs e)
{
ts = stopwarch.Elapsed;
string Elapsedtime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
lblTime.Text = Elapsedtime.ToString();

}

private void timer2_Tick(object sender, EventArgs e)
{
Timecounter++;
if (Timecounter > 30 && timer1.Enabled == true)
{
stopwarch.Stop();
timer1.Stop();
}
else if (Timecounter < 30 && timer1.Enabled == false)
{
stopwarch.Start();
timer1.Start();
}

}

private void Form2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
Timecounter = 0;
}

private void Form2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Timecounter = 0;
}

}
}

Friday, July 29, 2011

Nth Highest salary

declare @empsal int
set @empsal=3
select * from [Employee-new] e1 where @empsal =( select count(distinct e2.empsal) from [Employee-new] e2 where e2.empsal >= e1.empsal)