Kamis, 26 April 2018

TUTORIAL MEMBUAT HOTSPOT ENGINE DI C#

TUTORIAL MEMBUAT HOTSPOT ENGINE DI C#







1. Buka Application  Microsoft Visual Studio.
2.Pilih New > File > Project.






3.Pilih "Windows Forms Application" dan beri namanya. Kemudian pilih "OK".







4.Komponen yang digunakan :






5.Desain Form dengan memasukkan semua component hingga seperti di bawah ini dan ubah nama form menjadi "Hotspot Engine".




6.Masuk ke bagian Form1.cs

Masukkan Coding

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.Security.Principal;
using System.Net;
using System.Diagnostics;


namespace Virtual_Hotspot
{
    public partial class Form1 : Form
    {
        bool connect = false;
        public Form1()
        {
            InitializeComponent();
            
        }


    private void Hotspot (string ssid,string key, bool Status)
    {
        ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
        processStartInfo.RedirectStandardInput = true;
        processStartInfo.RedirectStandardOutput = true;
        processStartInfo.CreateNoWindow = true;
        processStartInfo.UseShellExecute = false;
        Process process = Process.Start(processStartInfo);
        if (process != null)
        {
            if (Status)
            {
                process.StandardInput.WriteLine("netsh wlan set hostednetwork mode=allow ssid=" + ssid + " key=" + key);
                process.StandardInput.WriteLine("netsh wlan start hostednetwork");
                process.StandardInput.Close();
            }

            else
            
            {
                process.StandardInput.WriteLine("netsh  stop hostednetwork");
                process.StandardInput.Close();
            }
        }
    }

        public static bool IsAdmin()
        {
            WindowsIdentity id = WindowsIdentity.GetCurrent();
            WindowsPrincipal p = new WindowsPrincipal(id);
            return p.IsInRole(WindowsBuiltInRole.Administrator);
        }


    public void RestartElevated()
    {
        ProcessStartInfo startinfo = new ProcessStartInfo();
        startinfo.UseShellExecute = true;
        startinfo.CreateNoWindow = true;
        startinfo.WorkingDirectory = Environment.CurrentDirectory;
        startinfo.FileName = System.Windows.Forms.Application.ExecutablePath;
        startinfo.Verb = "runas";
        
        try
        {
            Process p = Process.Start(startinfo);

        }

        catch
        { }
        System.Windows.Forms.Application.Exit();
    }



--------------------------------------------------------------------------------------------------------------------------


6A. Coding button1 :

private void button1_Click(object sender, EventArgs e)
    {
        string ssid = textBox1.Text,key = textBox2.Text;            
        if (!connect)
            {
                if (textBox1.Text == null || textBox1.Text == "")
                {
                    MessageBox.Show("Anda belum mengisi SSID", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                    else 
                    { 
                        if (textBox2.Text == null || textBox2.Text == "") 
                        { 
                            MessageBox.Show("Anda Belum Mengisi Password!", "Informasi"MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        }
                    else 
                    {
                    if (key.Length >= 6)
                    {
                        Hotspot(ssid, key, true);
                        textBox1.Enabled = false;
                        textBox2.Enabled = false;
                        button1.Text = "Berhenti";
                        connect = true;
                    }
                    else
                    {
                        MessageBox.Show("Password harus 6 karakter atau lebih!", "informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }   
            }
        }
            else
            {
                Hotspot(nullnull, false);
                textBox1.Enabled = true;
                textBox2.Enabled = true;
                button1.Text = "Start";
                connect = false;
            }

        }


----------------------------------------------------------------------------------------------------------------------------------------------------


6B. Coding Form1


 private void Form1_Load(object sender, EventArgs e)
    {
        if (!IsAdmin())
        {
            RestartElevated();
        }

    }

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        Hotspot(nullnullfalse);
        Application.Exit();

    }

}

}


----------------------------------------------------------------------------------------------------------------------------------------------------


7.Setelah semua Coding dimasukkan, mulai running program. klik icon "➤" pada toolbar atau F5 pada keyboard.


-Masukkan SSID dan Password. kemudian klik tombol "Start".
-Jika ingin berhenti klik tombol "Berhenti".

8.



-Masuk ke Control Panel\Network and Internet\Network Connections pada laptop dan Enabled "Wifi Network Connections 2".
-Maka Hotspot telah tersambung otomatis pada laptop. 
-Masukkan SSID dan Password jika menggunakan Smartphone.

Selasa, 20 Maret 2018

TUTORIAL MEMBUAT SHUTDOWN MANAGER DENGAN TIMER COUNTDOWN DI C#.

TUTORIAL MEMBUAT SHUTDOWN MANAGER DENGAN TIMER COUNTDOWN DI C#.





1. Buka Application  Microsoft Visual Studio.
2.Pilih New > File > Project.


3.Pilih "Windows Forms Application" dan beri namanya. Kemudian pilih "OK".




4. Komponen yang digunakan :



5.Desain Form dengan memasukkan semua component hingga seperti di bawah ini dan ubah nama form menjadi "Shutdown Manager".



6.Pada comboBox1, kita bisa isikan perintah yang akan dieksekusi oleh program. kita bisa klik comboBox dan pilih "Edit items" atau pilih properties yang ada disebelah kanan aplikasi dan klik "..." disamping tabel |Items |(Collection).


Setelah kita isi seperti pada gambar diatas ini, pilih "OK".





7.Masuk ke bagian Form1.cs

Masukkan Coding

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.Tasks;
using Microsoft.Win32;

namespace Shutdown_Manager
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        
        int hours, mins, secs;
        String shutdown;

--------------------------------------------------------------------------------------------------------------------------

7A. Coding button1 :

private void button1_Click(object sender, EventArgs e)
        {
            hours = int.Parse(textBox2.Text);
            mins = int.Parse(textBox3.Text);
            secs = int.Parse(textBox4.Text);
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            button1.Enabled = false;
            Process.Start("Shutdown", shutdown + " -t ");
            timer1.Start();
RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);      reg.SetValue("My Application", Application.ExecutablePath.ToString());
MessageBox.Show("The Computer will shut down immediately.", "Shutdown", MessageBoxButtons.OK, MessageBoxIcon.Information); 
 }

--------------------------------------------------------------------------------------------------------------------------

7B. Coding button2 :

private void button2_Click(object sender, EventArgs e)
        {

            button1.Enabled = true;
            Process.Start("Shutdown", "-a");
            timer1.Stop();
            textBox1.Clear();
            textBox2.Clear();           
            textBox3.Clear();
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            labelHour.Text = "00";
            labelMin.Text = "00";
            labelSec.Text = "00";
        }

--------------------------------------------------------------------------------------------------------------------------

7C. Coding comboBox1 :

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0: shutdown = "-s"; break;
                case 1: shutdown = "-r"break;
                case 2: shutdown = "-l"break;
            }
        }

--------------------------------------------------------------------------------------------------------------------------

7D. Coding timer1 :

private void timer1_Tick(object sender, EventArgs e)
        {
            {
               if (secs < 1)
                {
                    secs = 59;
                    if (mins < 1)
                    {
                        mins = 59;
                        if (hours != 0)
                            hours -= 1;
                    }
                    else mins -= 1;

                }
                else secs -= 1;
                if (hours > 9)
                    labelHour.Text = hours.ToString();
                else labelHour.Text = "0" + hours.ToString();

                if (mins > 9)
                    labelMin.Text = mins.ToString();
                else labelMin.Text = "0" + mins.ToString();

                if (secs > 9)
                    labelSec.Text = secs.ToString();
                else labelSec.Text = "0" + secs.ToString();
                
            }
            
        }
       
    }
}

--------------------------------------------------------------------------------------------------------------------------

8.Setelah semua Coding dimasukkan, mulai running program. klik icon "➤" pada toolbar atau F5 pada keyboard.


-Masukkan durasi pada textbox1, textbox2, textbox 3. contoh "01, 02, 03, dst."
-Pilih perintah apa yang akan dieksekusi pada tabel comboBox " Shutdown, Restart, Log off".
-klik button "Start" untuk memulai eksekusi perintah.
-klik button "Abort" untuk membatalkan eksekusi perintah.

9.Setelah Running selesai, buka regedit dan mengecek registry key apakah sudah masuk untuk menampilkan Aplikasi Autorun saat windows mulai dinyalakan.

10. Pilih HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Run.



11.Running Program.

-Versi Blog :

-Versi Youtube :

https://youtu.be/0Iw6FcoBS7g