Just tested this...
Create a Windows Forms-based application, that never displays any windows, that will start defrag.exe with no window, but as the current user.
Then, from your application you can start this forms-based app with alternate credentials.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
|
Your Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication2
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
string program = @"yourStub.exe";
string user = "administrator";
string password = "secret";
string domain = "domain";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = program;
p.StartInfo.UserName = user;
p.StartInfo.Domain = domain;
p.StartInfo.Password = new System.Security.SecureString();
foreach (char c in password)
p.StartInfo.Password.AppendChar(c);
p.Start();
}
}
}
The stub:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
string program = @"defrag.exe";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process p = new Process();
p.StartInfo.FileName = program;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
}
}
}
|