Microsoft MVPs inside





 MCSEboard.de – IT Pro Forum zu Windows Server 2008 R2 / 2008 / 2003 & Windows 7 / Vista / XP
Registrieren Hilfe Regeln Benutzerliste Suchen Heutige Beiträge Alle Foren als gelesen markieren

Windows Forum — Scripting


Alles zum Thema System Administration Scripting — Q & A zum Thema Scripting: Batch, VBS, WMI, PowerShell


Antwort
     
Themen-Optionen
Alt 29.03.2008, 22:58   #1
Newbie
 
Offline
Registriert seit: 12-2007
Beiträge: 9
Per Script über WMI eine neue VLAN Schnittstelle installieren

Hintergrund:
http://www.mcseboard.de/windows-foru...ic-132144.html

Vorweg, ich bin kein Entwickler, daher brauche ich euere Hilfe beim Erstellen eines Scripts. Das Script soll ein VLAN auf einem PC erstellen. Das kann ich nur per WMI machen.
Ich habe mit dem WMI Code Creator (von Microsoft ein Tool) folgenden Code erstellt:

Code für C#
Code:
using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class CallWMIMethod
    {
        public static void Main()
        {
            try
            {
                ManagementObject classInstance = 
                    new ManagementObject("root\\IntelNCS2", 
                    "IANet_802dot1QVLANService.CreationClassName='IANet_802dot1QVLANService',Name='{8AAEE732-49A0-43B3-A5C1-B36CDD16E79E}',SystemCreationClassName='Win32_ComputerSystem',SystemName='W-4DE-0004'",
                    null);

                // Obtain in-parameters for the method
                ManagementBaseObject inParams = 
                    classInstance.GetMethodParameters("CreateVLAN");

                // Add the input parameters.
                inParams["Name"] =  "VLAN1";
                inParams["VLANNumber"] =  1;

                // Execute the method and obtain the return values.
                ManagementBaseObject outParams = 
                    classInstance.InvokeMethod("CreateVLAN", inParams, null);

                // List outParams
                Console.WriteLine("Out parameters:");
                Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
                Console.WriteLine("VLANpath: " + outParams["VLANpath"]);
            }
            catch(ManagementException err)
            {
                MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
            }
        }
    }
}
Code mit VBS:
Code:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\IntelNCS2") 
' Obtain an instance of the the class 
' using a key property value.
Set objShare = objWMIService.Get("IANet_802dot1QVLANService.CreationClassName='IANet_802dot1QVLANService',Name='{8AAEE732-49A0-43B3-A5C1-B36CDD16E79E}',SystemCreationClassName='Win32_ComputerSystem',SystemName='W-4DE-0004'")

' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("CreateVLAN"). _
    inParameters.SpawnInstance_()


' Add the input parameters.
objInParam.Properties_.Item("Name") =  "VLAN1"
objInParam.Properties_.Item("VLANNumber") =  1

' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("IANet_802dot1QVLANService.CreationClassName='IANet_802dot1QVLANService',Name='{8AAEE732-49A0-43B3-A5C1-B36CDD16E79E}',SystemCreationClassName='Win32_ComputerSystem',SystemName='W-4DE-0004'", "CreateVLAN", objInParam)

' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue
Wscript.echo "VLANpath: " & objOutParams.VLANpath
Ich erhalte leider nur folgende Meldung:
---------------------------

---------------------------
An error occurred while trying to execute the WMI method: Allgemeiner Fehler
---------------------------
OK
---------------------------

Intel stellt folgendes Dokument für die Entwicklung bereit:
(muss ich erst raussuchen, in dem Wildwuchs von Schrott finde ich das da jetzt nicht auf die Schnelle)
    Mit Zitat antworten
Antwort


Themen-Optionen


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
VLAN Management - was für eine Augabe moonjumper Cisco Forum — Allgemein 6 23.04.2009 16:22
ADSL Verbindung über Ethernet Schnittstelle mels Cisco Forum — Allgemein 10 30.03.2007 12:55
Netzwerkomponenten über Script installieren? itomix Windows Server Forum 0 09.01.2006 12:27
USB 2.0 Stick an eine 1.1 Schnittstelle? Microdemis Windows Forum — LAN & WAN 6 11.04.2005 12:58
2K - Über logon script Dateien Installieren dnotte Windows Forum — LAN & WAN 1 20.11.2003 19:26


Alle Zeitangaben in MEZ/CET. Es ist jetzt 15:16 Uhr. Seite generiert in 0,025 Sekunden.

- Unsere Partner -

Copyright © 2000 – 2012 MCSEboard.de

Sprung zum Seitenanfang