|
As in below artical i had been try to get info from another computer;
Collecting Remote System Information With WMI[^]
However, i had created class Systeminfo and followed the steps infact i had embed the provided source and run my script but received error (Object reference not set to an instance of an object.)
|
|
|
|
|
Huh, too bad. Sure wish we could see your code so we could help.
|
|
|
|
|
here is my script;
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.Globalization;
namespace Computer_system
{
public partial class Form1 : Form
{
private RemoteSysInformation.SystemInformation sysinfo;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (sysinfo.Get("textBox4.text") != 0)
{
MessageBox.Show("Error getting system information.", "System Information");
}
else
{
textBox3.Text = ("" + Computer_system.win32_computer_system.GetDomain());
textBox2.Text = ("" + Computer_system.win32_computer_system.GetUserName());
textBox1.Text = ("" + Computer_system.win32_computer_system.GetPSComputerName());
textBox5.Text = ("" + Computer_system.win32_computer_system.GetManufacturer());
textBox6.Text = ("" + Computer_system.win32_computer_system.GetModel());
listBox1.Text = ("" + Computer_system.win32_printer.GetName());
}
}
private void button4_Click(object sender, EventArgs e)
{
Process.Start("Cmd.exe", @"/C mstsc.exe /v:");
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("Cmd.exe", @"/C RC.exe 1");
}
private void button3_Click(object sender, EventArgs e)
{
Process.Start("Cmd.exe", @"/C MSRA.exe /OfferRA");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Among other things, it appears you don't instantiate the sysinfo .
Run it in the debugger, step through, and see where (else) the problem is.
And what's with the "" + ?
|
|
|
|
|
i do run debug and received below
Object reference not set to an instance of an object
|
|
|
|
|
Yes, but where? Which statement caused it?
|
|
|
|
|
if (sysinfo.Get("textBox4.text") != 0)
|
|
|
|
|
Just as I thought. You need to initialize sysinfo .
|
|
|
|
|
how do i initialize sysinfo
|
|
|
|
|
You SERIOUSLY need to pickup a beginners book on C# an d work through it.
If your code, you need to add the line:
sysinfo = new SysInfo();
to the Form_Load method.
SERIOUSLY, pickup a book! You desperately need it.
|
|
|
|
|
i had refer but unfortunate fail.
Dear Exprt,
Would mine to guide to archive this on button.
|
|
|
|
|