■趣味
□C# リモートプロセス起動(8)
1-  最新50  


1 ☆シゲ☆(4029476 2012/04/12 00:49:26
C# リモートプロセス起動
2 ☆シゲ☆(4029476 2012/04/12 00:50:39
ConnectionOptions options = new ConnectionOptions();
options.Username = @"ユーザ名";
options.Password = @"パスワード";

string mPath = @"\\" + "コンピュータ名" + @"\root\cimv2";

ManagementScope scope = new ManagementScope(mPath, options);
scope.Connect();

ObjectGetOptions o = new ObjectGetOptions();
ManagementPath p = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(scope, p, o);

object[] methodArgs = { "notepad.exe", null, null, 0 };

// Execute the method
object result = processClass.InvokeMethod("Create", methodArgs);

3 ☆シゲ☆(4029476 2012/04/17 01:33:04
Option Explicit

Sub Sink_OnObjectReady(oInst, oCtx)
instcount = instCount+1
Wscript.echo "Event " & cstr(instCount) & vbTab & _
oInst.GetObjectText_ & vbNewLine
End Sub

Sub Sink_OnCompleted(Hresult, oErr, oCtx)
End Sub

'msftTroubleShooting.vbs starts here

DIM oLctr, oSvc, OSink, instCount, SrvName, SrvUserName, SrvPswd, args, argcount

Set args = wscript.arguments

SrvName = "."
SrvUserName = Null
SrvPswd = Null
instcount = 0

4 ☆シゲ☆(4029476 2012/04/17 01:34:32
argcount = args.Count

If (argcount > 0) Then
If args(0) = "/?" or args(0) = "?" Then
Wscript.Echo "Usage: cscript msftTroubleShooting.vbs " _
[ServerName=Null|?] [UserName=Null] [Password=Null]"
Wscript.Echo "Example: cscript msftTroubleShooting.vbs "
Wscript.Echo "Example: cscript msftTroubleShooting.vbs computerABC"
Wscript.Echo "Example: cscript msftTroubleShooting.vbs "
Wscript.Echo "computerABC admin adminPswd"
Wscript.Quit 1
End If
End If

Set oLctr = createObject("WbemScripting.Swbemlocator")

On Error Resume Next

5 ☆シゲ☆(4029476 2012/04/17 01:35:00
If argcount = 0 Then
Set oSvc = oLctr.ConnectServer(,"root\cimv2")
SrvName = " Local Computer "
Else
srvname = args(0)
If argcount >= 2 Then
SrvUserName = args(1)
End If
If argcount >= 3 Then
SrvPswd = args(2)
End If
Set oSvc = oLctr.ConnectServer(srvname,"root\cimv2",SrvUserName,SrvPswd)
End If

If Err = 0 Tthen
Wscript.Echo "Connection to " & srvname & " is thru" & vbNewLine
Else
Wscript.Echo "The Error is " & err.description & _
" and the Error number is " & err.number
Wscript.Quit 1
End If

6 ☆シゲ☆(4029476 2012/04/17 01:35:31
On Error Goto 0

Set oSink = WScript.CreateObject("WbemScripting.SWbemSink","Sink_")
oSvc.ExecNotificationQueryAsync oSink, _
"Select * From MSFT_WmiProvider_OperationEvent Where " & _
"provider = 'WMIPingProvider'"

Wscript.Echo "To stop the script press ctrl + C" & vbNewLine
Wscript.Echo "Waiting for events......" & vbNewLine

While True
Wscript.Sleep 10000
Wend

7 ☆シゲ☆(4029476 2012/04/17 02:31:35
・既定の接続オプションを使用してリモート コンピュータに接続する
// Build an options object for the remote connection
// if you plan to connect to the remote
// computer with a different user name
// and password than the one you are currently using.
// This example uses the default values.
ConnectionOptions options = new ConnectionOptions();

// Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope = new
ManagementScope(
"\\\\FullComputerName\\root\\cimv2", options );
scope.Connect();

8 ☆シゲ☆(4029476 2012/04/17 02:58:31
// Query system for Operating System information
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,query);

ManagementObjectCollection queryCollection = searcher.Get();
foreach ( ManagementObject m in queryCollection) {
// Display the remote computer information
Console.WriteLine("Computer Name : {0}", m["csname"]);
Console.WriteLine("Windows Directory : {0}", m["WindowsDirectory"]);
Console.WriteLine("Operating System: {0}", m["Caption"]);
Console.WriteLine("Version: {0}", m["Version"]);
Console.WriteLine("Manufacturer : {0}", m["Manufacturer"]);
}


1-  最新50  
1.スレッド一覧に戻る
2.カテゴリ一覧に戻る
3.利用規約を読む