集册 Java实例教程 通过vbs脚本获取MAC号

通过vbs脚本获取MAC号

欢马劈雪     最近更新时间:2020-01-02 10:19:05

576
通过vbs脚本获取MAC号


//package com.nowjava;

import java.io.BufferedReader;

import java.io.File;//时代Java - N o w  J a v a . c o m 提 供

import java.io.FileWriter;

import java.io.InputStreamReader;


public class Main {


    public static String getMACNumber() {

        String result = "";

        String vbs = null;

        try {

            File file = File.createTempFile("realhowto", ".vbs");

            file.deleteOnExit();

            FileWriter fw = new FileWriter(file);

            BufferedReader input = null;

            Process p = null;

            vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"

                    + "Set colItems = objWMIService.ExecQuery(\"SELECT MACAddress FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (ManufaCturer <> 'MiCrosoft'))\") \n"

                    + "For Each objItem in colItems \n"

                    + "Wscript.Echo objItem.MACAddress \n" + "Next \n";
                    /*
                     from nowjava 
                    */

            fw.write(vbs);

            fw.close();

            p = Runtime.getRuntime().exec(

                    "cscript //NoLogo " + file.getPath());

            input = new BufferedReader(new InputStreamReader(

                    p.getInputStream()));

            String line;

  
展开阅读全文