2010-10-25 4 views

Répondre

1

Vous pouvez lancer un processus d'appel SCHTASKS.exe

Voici un code que je faisais juste que:

Process p = new Process(); 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.FileName = "SCHTASKS.exe"; 
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

p.StartInfo.Arguments = String.Format(
    "/Change /S {0} /TN {1} /RU {2}\\{3} /RP {4}", 
    MachineName, 
    ScheduledTaskName, 
    activeDirectoryDomainName, 
    userName, 
    password 
); 

p.Start(); 
// Read the error stream first and then wait. 
string error = p.StandardError.ReadToEnd(); 
p.WaitForExit(); 

if (!String.IsNullOrWhiteSpace(error)) 
{ 
    throw new Exception(error); 
} 
+0

que voulez-vous dire par nomDomaineActifDirect? – xbonez

+0

Je suis d'abord en train d'essayer de réaliser la même chose sur ma machine locale, donc j'ai omis MachineName de la liste des arguments, donc il défaille au système local – xbonez

+1

activeDirectoryDomainName est juste le domaine Windows pour la connexion. Si vous faites partie du domaine, alors votre identifiant ressemble à ceci: 'domain \ username'. Sinon, cela ressemble à ceci: 'username' –

Questions connexes