Click here to Skip to main content
15,916,702 members
Home / Discussions / C#
   

C#

 
Generalunique identifier on a thread Pin
sameerhanda10-Feb-05 8:30
sameerhanda10-Feb-05 8:30 
GeneralRe: unique identifier on a thread Pin
C# Genius10-Feb-05 8:44
C# Genius10-Feb-05 8:44 
GeneralRe: unique identifier on a thread Pin
Dave Kreskowiak10-Feb-05 9:02
mveDave Kreskowiak10-Feb-05 9:02 
GeneralRe: unique identifier on a thread Pin
Stefan Troschuetz11-Feb-05 0:18
Stefan Troschuetz11-Feb-05 0:18 
GeneralClient/Server Pin
Soumya Mulukutla10-Feb-05 6:58
Soumya Mulukutla10-Feb-05 6:58 
GeneralRe: Client/Server Pin
Michael P Butler10-Feb-05 8:15
Michael P Butler10-Feb-05 8:15 
GeneralRe: Client/Server Pin
S. Senthil Kumar10-Feb-05 8:15
S. Senthil Kumar10-Feb-05 8:15 
GeneralRe: Client/Server Pin
Judah Gabriel Himango10-Feb-05 9:01
sponsorJudah Gabriel Himango10-Feb-05 9:01 
GeneralRe: Client/Server Pin
Soumya Mulukutla10-Feb-05 9:46
Soumya Mulukutla10-Feb-05 9:46 
GeneralRe: Client/Server Pin
Judah Gabriel Himango10-Feb-05 9:59
sponsorJudah Gabriel Himango10-Feb-05 9:59 
QuestionDllImport() with flexible DLL name? Pin
mav.northwind10-Feb-05 6:41
mav.northwind10-Feb-05 6:41 
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 

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.