contoh tampilan aplikasi :
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,,,