Progged programming site

Programming source code, articles, tutorials, links and chat

Display MAC addresses

This example will display the MAC address(es) on your system.
Private Sub Form_Load()
‘add a reference to the Microsoft WMI Scripting 1.2 library
On Error Resume Next
strComputer = “.”
Set objWMIService = GetObject(”winmgmts:\\” & strComputer & “\root\cimv2″)
Set colItems = objWMIService.ExecQuery(”Select * from Win32_NetworkAdapter”, , 48)
For Each objItem In colItems
Form1.Print “MACAddress: ” & objItem.MACAddress
‘MsgBox (”MACAddress: ” & objItem.MACAddress)
Next
End Sub

Bookmark It

Hide [...]

[ Back to top ]

display the html of a web page

This example will display the html source of a given web page, should be easy to create an app with this if you wished.
using System;
using System.IO;
using System.Net;
using System.Text;
namespace web
{
/// <summary>
/// Summary description for web.
/// </summary>
public class WMI
{
static void Main(string[] args)
{
WebClient MyClient = new WebClient();
Stream MyStream = MyClient.OpenRead(”http://www.google.com”);
StreamReader MyReader = new StreamReader(MyStream);
Console.WriteLine(MyReader.ReadLine());
MyStream.Close();
}
}
}

Bookmark It

Hide Sites

[ Back to top ]

create an XML file in C#

This example shows how to create an XML file in C#.
using System;
using System.Xml;
namespace ConsoleApplication3
{
class Class1
{
static void Main(string[] args)
{
string filename = @”d:\test.xml”;
XmlTextWriter textwriter = new XmlTextWriter(filename,null);
textwriter.Formatting = Formatting.Indented;
textwriter.WriteStartDocument();
textwriter.WriteStartElement(”links”);
textwriter.WriteStartElement(”category”,”programming”);
textwriter.WriteElementString(”address”,”www.progged.net”);
textwriter.WriteElementString(”description”,”programming site”);
textwriter.WriteEndElement();
textwriter.WriteEndElement();
textwriter.WriteEndDocument();
textwriter.Flush();
textwriter.Close();
}
}
}

Bookmark It

Hide Sites

[ Back to top ]

Empty the recycle bin

This example shows how to empty the recycle bin with C.
#include <windows.h>
#include <shlobj.h>
#define WIN32_LEAN_AND_MEAN
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
if(MessageBox(NULL, “Press ok to empty the Recycle Bin.”, “recycler”, MB_YESNO | MB_ICONINFORMATION) != IDYES)
return FALSE;
SHEmptyRecycleBin(NULL, “”, 0);
return FALSE ;
}

Bookmark It

Hide Sites

[ Back to top ]

Sponsors