.: Mhd Irwan Meidiansyah :.

Lihat,Temukan dan Rasakan

Pada artikel berikut ini,saya ingin berbagi sedikit informasi bagaimana cara mematikan atau menrestart komputer lainnya yang terhubung dalam satu LAN. Sebagai contoh anda ingin mematikan atau menrestart komputer temen ada dalam satu ruangan.
Syarat Jaringan :
1. Masih dalam satu blok IP. Contoh : 192.168.2.20 dan 192.168.2.10
2. Masih dalam GROUP / DOMAIN yang sama. Contoh: WORKGROUP atau MSHOME
3. Anda harus mengetahui IP address, username dan password komputer yang ingin ada matikan atau restart.
4. Menggunakan bahasa pemrograman C# .Net

contoh tampilan aplikasi :


Pengen tau bagai mana Coding nya ????

Buat Fungsi seperti berikut :
public static void Shutdown(string machineName, string username, string password,string perintah)
{
ManagementScope Scope = null;
ConnectionOptions ConnOptions = null;
ObjectQuery ObjQuery = null;
ManagementObjectSearcher ObjSearcher = null;
try
{
ConnOptions = new ConnectionOptions();
ConnOptions.Impersonation = ImpersonationLevel.Impersonate;
ConnOptions.EnablePrivileges = true;
//local machine
if (machineName.ToUpper() == Environment.MachineName.ToUpper())
Scope = new ManagementScope(@"\ROOT\CIMV2", ConnOptions);

else
{
//remote machine
ConnOptions.Username = username;
ConnOptions.Password = password;
Scope = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", ConnOptions);
}
Scope.Connect();

ObjQuery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ObjSearcher = new ManagementObjectSearcher(Scope, ObjQuery);
foreach (ManagementObject operatingSystem in ObjSearcher.Get())
{
//MessageBox.Show("Caption = " + operatingSystem.GetPropertyValue("Caption"));
//MessageBox.Show("Version = " + operatingSystem.GetPropertyValue("Version"));

if(perintah == "shutdown")
{
ManagementBaseObject outParams = operatingSystem.InvokeMethod("Shutdown", null,null);
}
else if (perintah == "reboot")
{
ManagementBaseObject outParams = operatingSystem.InvokeMethod("Reboot", null,null);
}
}
}
catch (Exception)
{
MessageBox.Show("Gagal connect ke remote !!!", "INFORMASI");
}
}


Lalu panggil fungsi tersebut sesuai dengan tombol nya,
contoh tombol shutdown :

private void button1_Click(object sender, EventArgs e)
{
Shutdown(@"" + textBox4.Text + "", @"" + textBox5.Text + "", @"" + textBox6.Text + "","shutdown");
}



contoh tombol reboot :

private void button2_Click(object sender, EventArgs e)
{
Shutdown(@"" + textBox4.Text + "", @"" + textBox5.Text + "", @"" + textBox6.Text + "","reboot");
}



Selesai deh,,,
Gampang kan,,,

Silahkan Mencoba,,,

0 comment:

Posting Komentar



Artikel Terakhir

Chat With Me !!!

My Shout Mix


ShoutMix chat widget

Pengunjung

Visitor

Olark Livehelp