Executer en tant que

remifalcon Messages postés 62 Date d'inscription mercredi 22 février 2006 Statut Membre Dernière intervention 20 novembre 2008 - 11 juil. 2008 à 11:39
cs_eldim Messages postés 956 Date d'inscription lundi 30 mai 2005 Statut Membre Dernière intervention 21 août 2014 - 17 juil. 2008 à 15:54
Bonjour à tous

Je souhaiterai faire un programme qui permette d'exécuter un autre prog en tant que admin avec le mon de passe
j'utilise la fonction System.Diagnostics.Process.Start()
Mais ca ne marche pas, ça me met en debug que le nom d'utilisateur ou mdp n'est pas le bon . (alors qu' ils sont bons)

Quelqu'un aurait une solution?
---------------------------------------------------------------------------------------
String passwordPre = "monPass";
System.Security.SecureString password = new System.Security.SecureString();
        
        char[] monArray = passwordPre.ToCharArray();
           
            foreach (char c in monArray)
            {
                password.AppendChar(c);
                Console.WriteLine("->"+c);
            }

        System.Diagnostics.Process.Start(@"C:\configvisio.reg", "admin", password,"monDomain");

Merci!

5 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
11 juil. 2008 à 12:05
Salut,

regarde cette source : http://www.csharpfr.com/codes/LANCEUR-PROGRAMME_38787.aspx

j'utilise la syntaxe suivante :

Process p = new Process();

// On renseigne les informations nécessaires

ProcessStartInfo psi = new ProcessStartInfo(this.programName, this.txtParameters.Text);

psi.UserName = this.username;

psi.Password = this.password;

p.StartInfo = psi;

p.Start();

Sébastien FERRAND (blog)
Consultant Sénior
[Microsoft Visual C# MVP]
0
remifalcon Messages postés 62 Date d'inscription mercredi 22 février 2006 Statut Membre Dernière intervention 20 novembre 2008
11 juil. 2008 à 13:05
Comme je te le disais en mp, aurais tu un exemple de code fonctionnel?
Merci
0
remifalcon Messages postés 62 Date d'inscription mercredi 22 février 2006 Statut Membre Dernière intervention 20 novembre 2008
11 juil. 2008 à 13:16
Re
Bon j'ai regardé je galère à fond.
Le code à pourtant l'air de compilé
Peux tu me dire ce que tu aurais rajouté?
voici mon fichier cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ConsoleApplication1
{

  
    class Program
    {

        [DllImport("advapi32.dll", EntryPoint = "CreateProcessAsUser")]
        public static extern int CreateProcessAsUserA(int hToken, string lpApplicationName, string lpCommandLine, SECURITY_ATTRIBUTES lpProcessAttributes, SECURITY_ATTRIBUTES lpThreadAttributes, int bInheritHandles, int dwCreationFlags, string lpEnvironment, string lpCurrentDirectory, STARTUPINFO lpStartupInfo, PROCESS_INFORMATION lpProcessInformation);

        public struct PROCESS_INFORMATION
        {
            int hProcess;
            int hThread;
            int dwProcessId;
            int dwThreadId;
        }
        public struct STARTUPINFO
        {
            int cb;
            string lpReserved;
            string lpDesktop;
            string lpTitle;
            int dwX;
            int dwY;
            int dwXSize;
            int dwYSize;
            int dwXCountChars;
            int dwYCountChars;
            int dwFillAttribute;
            int dwFlags;
            short wShowWindow;
            short cbReserved2;
            byte lpReserved2;
            int hStdInput;
            int hStdOutput;
            int hStdError;
        }
        public struct SECURITY_ATTRIBUTES
        {
            int nLength;
            int lpSecurityDescriptor;
            int bInheritHandle;
        }

        static void Main(string[] args)
        {

        String passwordPre = "monPass";
        System.Security.SecureString password = new System.Security.SecureString();
        
        char[] monArray = passwordPre.ToCharArray();
           
            foreach (char c in monArray)
            {
                password.AppendChar(c);
               
              
            }
            String test = password.ToString();
            Console.WriteLine("->" + test);
          
        //System.Diagnostics.Process.Start(@"C:\configvisio.reg","cbadmin",password,"CBINFO");

        Process p = new Process();
        //// On renseigne les informations nécessaires
        ProcessStartInfo psi = new ProcessStartInfo(@"C:\configvisio.reg");
        psi.UserName = "cbadmin";
        psi.Password = password;

        psi.UseShellExecute = false;
        p.StartInfo = psi;
        p.Start();
        }
    }
}
0
Vulkan51 Messages postés 10 Date d'inscription samedi 2 décembre 2006 Statut Membre Dernière intervention 16 juillet 2008
11 juil. 2008 à 17:18
il faudrait aussi peut etre regarder du coté d'une authentification windows integrée avec impersonnation (=heritage des droits du compte avec lekel tu te log)  ;)

mais il faudrait alors se logger avec ton log et mot de passe admin windows dès que tu veut utiliser ton programme
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_eldim Messages postés 956 Date d'inscription lundi 30 mai 2005 Statut Membre Dernière intervention 21 août 2014 1
17 juil. 2008 à 15:54
sinon tu peux regarder sur code project
là bas y a tout ce qu'il te faut sur ce sujet...

-- Pourquoi faire simple quand on peut faire compliquer --
0
Rejoignez-nous