Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
AnswerRe: DllImport() with flexible DLL name? Pin
Dave Kreskowiak10-Feb-05 6:52
mveDave Kreskowiak10-Feb-05 6:52 
AnswerRe: DllImport() with flexible DLL name? Pin
Phil Hobgen10-Feb-05 7:32
Phil Hobgen10-Feb-05 7:32 
GeneralRe: DllImport() with flexible DLL name? Pin
mav.northwind10-Feb-05 8:40
mav.northwind10-Feb-05 8:40 
GeneralCollections and ISerializable Pin
Clickok10-Feb-05 5:09
Clickok10-Feb-05 5:09 
GeneralFast Fourier Tarnsformation Pin
9-Feb-05 23:31
suss9-Feb-05 23:31 
GeneralRe: Fast Fourier Tarnsformation Pin
Jon Sagara10-Feb-05 6:00
Jon Sagara10-Feb-05 6:00 
GeneralCombo Box in Datagrid Cell Pin
Glaivas9-Feb-05 23:02
Glaivas9-Feb-05 23:02 
GeneralWMI Win32_Process Pin
skrishnasarma9-Feb-05 21:51
skrishnasarma9-Feb-05 21:51 
Hi
I am having small problem in WMI related question.
The folowing function will accept username,password and process executable path as input parameter, and it will launch a new process in the host.and finally I will fetch Process ID and process name.
This code is working fine for the current user, that means passing username and password as null.

My requrement is I wand to run a process for a different user( with username and password)
Can any one guide me in this rehgard?

void LaunchProcess(string filename,string username,string password)
{

bool currentUser = false;
string processName = "";
uint processID = 0;


if( (username != null)&& (password != null))
currentUser = true; // LaunchProcess got username and Password.

ConnectionOptions objConnectionOptions = new ConnectionOptions();
if(currentUser ==true)
{
objConnectionOptions.Username = username;
objConnectionOptions.Password = password;
}

ManagementScope objManagementScope = new ManagementScope("root\\cimv2", objConnectionOptions);
objManagementScope.Connect();
ManagementClass processClass = new ManagementClass("Win32_Process");
processClass.Scope = objManagementScope;
//Get an input parameters object for this method
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
//Fill in input parameter values
inParams["CommandLine"] = filename;
// this will execute the command.
ManagementBaseObject outParams = processClass.InvokeMethod("Create",inParams, null);
// Wait for 1 Second to start the Process
System.Threading.Thread.Sleep(1000);

// Get the Unique Process ID after Process Creation
processID = (uint)outParams["processId"];

//Query based on the received processID and get the Process Name .
ObjectQuery objObjectQuery = new ObjectQuery("Select name from Win32_Process Where ProcessID = '" + processID + "'");

ManagementObjectSearcher objMagObjSearcher = new ManagementObjectSearcher( objManagementScope, objObjectQuery );
ManagementObjectCollection objMagObjCollection = objMagObjSearcher.Get();


foreach( ManagementObject objManagementObject in objMagObjCollection )
{
if(objManagementObject["name"] != null)
processName = objManagementObject["name"].ToString();

} // foreach




}

}
GeneralCapturing global keystrokes Pin
SnuhEyeless9-Feb-05 21:12
SnuhEyeless9-Feb-05 21:12 
GeneralRe: Capturing global keystrokes Pin
SnuhEyeless9-Feb-05 21:29
SnuhEyeless9-Feb-05 21:29 
GeneralRe: Capturing global keystrokes Pin
Stefan Troschuetz9-Feb-05 21:51
Stefan Troschuetz9-Feb-05 21:51 
Generalcreate a screen program same as like report from a xml file Pin
dhol9-Feb-05 19:35
dhol9-Feb-05 19:35 
GeneralRe: create a screen program same as like report from a xml file Pin
Dave Kreskowiak10-Feb-05 5:17
mveDave Kreskowiak10-Feb-05 5:17 
GeneralRe: create a screen program same as like report from a xml file Pin
dhol10-Feb-05 16:36
dhol10-Feb-05 16:36 
GeneralRe: create a screen program same as like report from a xml file Pin
Michael P Butler10-Feb-05 8:18
Michael P Butler10-Feb-05 8:18 
GeneralRe: create a screen program same as like report from a xml file Pin
dhol10-Feb-05 16:36
dhol10-Feb-05 16:36 
Generalretreiving metadata information of s database Pin
padvit9-Feb-05 18:10
padvit9-Feb-05 18:10 
Generalwebservice needed for sending sms from web 2 mob Pin
iramg9-Feb-05 17:48
iramg9-Feb-05 17:48 
GeneralRe: webservice needed for sending sms from web 2 mob Pin
S. Senthil Kumar9-Feb-05 19:25
S. Senthil Kumar9-Feb-05 19:25 
GeneralRe: webservice needed for sending sms from web 2 mob Pin
Dave Kreskowiak10-Feb-05 5:14
mveDave Kreskowiak10-Feb-05 5:14 
GeneralProblem calling Matlab from ASP.net Pin
malcolmmc9-Feb-05 16:53
malcolmmc9-Feb-05 16:53 
QuestionHow to get Messages When Clicking CheckBox in DataGrid? Pin
pubududilena9-Feb-05 16:25
pubududilena9-Feb-05 16:25 
AnswerRe: How to get Messages When Clicking CheckBox in DataGrid? Pin
Gleb Belov9-Feb-05 22:13
Gleb Belov9-Feb-05 22:13 
Generalupdating an edited Datalist to an Access DB Pin
fortyonejb9-Feb-05 16:17
fortyonejb9-Feb-05 16:17 
Questioncan we use two diffrent namespaces Pin
nagarajuepuri9-Feb-05 15:53
nagarajuepuri9-Feb-05 15:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.