Asked by:
Suggestions to execute the file remotely

Question
-
I am a learner in C#, need some suggestions for the follwoing task.
I am in Machine A. I have a batch file in machine B. I need to execute this batch file from Machine A. Need to achieve this in C# so that i could include this in my SSIS package.
Machines A and B are in the same network.- Moved by Bin-ze Zhao Thursday, December 24, 2009 2:56 AM ssis related (From:Visual C# General)
Thursday, December 17, 2009 10:34 PM
All replies
-
something like this
object[] theProcessToRun = { "notepad.exe" }; ConnectionOptions theConnection = new ConnectionOptions(); theConnection.Username = "username"; theConnection.Password = "password"; ManagementScope theScope = new ManagementScope("\\\\" + IP + "\\root\\cimv2", theConnection); ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()); theClass.InvokeMethod("Create", theProcessToRun);
Friday, December 18, 2009 1:38 AM -
Do i need to have any library included for this?
using System.Management;
But the classes / Methods are not at all recognizedFriday, December 18, 2009 11:15 PM -
are you using .net 2.0 or 3.0/5?Saturday, December 19, 2009 2:21 AM
-
3.5 SP1. this C# code is for SQL server2008 SSIS. I am trying to do something like below with no use. Its running successfully but the schedule is not creating
public void Main()
{
DateTime dtToday = DateTime.Now;
DateTime dtToday1 = dtToday.AddMinutes(10);
String curDate;
String curTime;
String ScheduleCommand;
string s;
String j;
string t;
string k;
string l;
string s1;
s1 = "servername";
s = "My Script3";
j="g:\\1.bat";
k = "12/18/2009";
l = "14:19";
t = "cmd /c SCHTASKS /create /tn \"" + s + "\" /tr \"" + j + "\" /sc ONCE /S " + s1 + " /RU domain\\login /RP abcdef /sd " + k + " /st "+l+"";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
MessageBox.Show(t);
proc.StartInfo.FileName = t;
proc.Start();
Dts.TaskResult = (int)ScriptResults.Success;
}
I even tried the \AT also.Saturday, December 19, 2009 3:07 PM -
sorry, I have never uses SSIS.Saturday, December 19, 2009 8:49 PM