2014-02-12 6 views
0

여기 새로 생겼습니다. 콘솔 응용 프로그램에 문제가 있습니다. Windows 서비스로 로그인하기 전에 콘솔 응용 프로그램을 실행할 수 있다는 것을 알았습니다. 많은 프로세스를 시도했지만 해결할 수 없으며 일부는 코드를 추가해야한다고 말합니다. 다른 사람들은 단지 추가가 필요하다고 말합니다. 누군가가 나를 도울 수 있으면 제발, gpedit.msc하십시오. 이것은 내 프로그램의 코드입니다.Windows 로그온 전에 .exe를 실행하십시오.

public static void Main(string[] args) 
    { 

     try 
     { 

      ///Method Begins. 

      Console.WriteLine("Please wait, we are recording your access..."); 
      Console.WriteLine("Connecting with the DataBase"); 

      PCRegister.PcRegisterSoapClient cliente = new PCRegister.PcRegisterSoapClient(); 

      cliente.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["username"], ConfigurationSettings.AppSettings["password"]); 

      cliente.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 
      cliente.ClientCredentials.Windows.AllowNtlm = true; 
      Console.WriteLine(); 

      ///This Method Gets the HOST IP 
      Console.Write("Getting your IP"); 
      Console.WriteLine(); 
      IPGlobalProperties network = IPGlobalProperties.GetIPGlobalProperties(); 
      TcpConnectionInformation[] connections = network.GetActiveTcpConnections(); 
      string ipAddress = connections[0].LocalEndPoint.Address.ToString(); 

      ///This Method Send the HostName to the DataBase and look if exist or not. 
      PCRegister.CriteriaDataSet criteriaDataSet = new PCRegister.CriteriaDataSet(); 

      PCRegister.CriteriaDataSet.CriteriaRow criteriaRow = criteriaDataSet.Criteria.NewCriteriaRow(); 

      criteriaRow.ColumnName = "HostName"; 

      criteriaRow.Value = Environment.MachineName; 

      criteriaDataSet.Criteria.AddCriteriaRow(criteriaRow); 

      criteriaDataSet.Criteria.AcceptChanges(); 

      PCRegister.PcRegisterListDataSet getList = new PCRegister.PcRegisterListDataSet(); 
       getList = cliente.GetList(criteriaDataSet); 

      Console.WriteLine("Sending Information"); 

      ///Create a New Full DataSet. 
      PCRegister.PcRegisterFullDataSet pcRegisterFullDataSet = new PCRegister.PcRegisterFullDataSet(); 

      ///Here the Get List will go to Data Base and look if are another HostName with the same name. 
      ///If Yes, this will make an update in the Data Base. 
      ///If Not, this will insert a new row. 
      Console.WriteLine("Connected");  
      if (getList.PcRegisterList.Count > 0) 
       { 
        ///Get the PrimaryKey from PcRegisterListDataset that was filled by the GetList. 
        Guid primaryKey = getList.PcRegisterList[0].ComputerID; 
        pcRegisterFullDataSet = cliente.GetByID(primaryKey); 
        Console.WriteLine(); 
        pcRegisterFullDataSet.PcRegister[0].HostName = criteriaRow.Value; 
        pcRegisterFullDataSet.PcRegister[0].IPAddress = ipAddress; 
        pcRegisterFullDataSet.PcRegister[0].ChangeDate = System.DateTime.Today; 
        Console.WriteLine("HostName:" + Environment.MachineName); 
        Console.WriteLine("Your New Host IP: " + ipAddress); 
        Console.WriteLine("Date: " + System.DateTime.Now); 
        Console.WriteLine(); 
        Console.WriteLine("You are already Registred"); 
        //Console.WriteLine("You are already registred, press ENTER to exit"); 
        cliente.Update(pcRegisterFullDataSet); 
        //Console.ReadLine(); 
       } 
       else 
       { 
        pcRegisterFullDataSet = cliente.GetNew(); 
        pcRegisterFullDataSet.PcRegister[0].HostName = criteriaRow.Value; 
        pcRegisterFullDataSet.PcRegister[0].IPAddress = ipAddress; 
        pcRegisterFullDataSet.PcRegister[0].ChangeDate = System.DateTime.Today; 
        Console.WriteLine(); 
        Console.WriteLine("HostName: " + criteriaRow.Value); 
        Console.WriteLine("Host IP: " + ipAddress); 
        Console.WriteLine("Date: " + System.DateTime.Now); 
        Console.WriteLine(); 
        Console.WriteLine("You are already Registred"); 
        //Console.WriteLine("You are already registred, press ENTER to exit"); 
        cliente.Update(pcRegisterFullDataSet); 
        //Console.ReadLine(); 
       } 
     }    

     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
      Console.ReadLine(); 
     } 
    } 
+1

Windows 로그인 전에 콘솔 응용 프로그램을 실행할 수 없습니다. Windows 서비스를 만들어야합니다. [MSDN의 문서는 꽤 좋습니다] (http://msdn.microsoft.com/en-us/library/zt39148a (v = vs.110) .aspx) –

+0

사용자가 로그인 할 때마다 스크립트를 실행 하시겠습니까 창문 기계? 레지스트리를 편집하고 경로를 추가하거나 그룹 정책 편집기를 사용하는 등 여러 가지 방법이 있습니다. 비슷한 게시물을보십시오 : https://superuser.com/questions/15596/automatically-run-a-script-when-i-log-on-to-windows –

+0

그래, Windows 로그인 전에 실행해야합니다 ... 하지만 Windows 서비스 용 콘솔을 사용하거나 다른 것을 만들어야합니까 ?? –

답변

1

질문을 올바르게 이해하면 Windows 서비스를 만드는 방법을 모르십니까? 권리? Visual Studio의 Professional Edition에는 Windows 서비스를 만들기위한 템플릿이 있습니다. Codeproject에서 C#으로 기본 Windows 서비스를 만드는 방법에 대한 기사를 찾을 수 있습니다.

Windows Services에서는 Output 용 콘솔 창이 없지만 로그 파일을 쓸 수는 있습니다.

+0

나는이 Windows 서비스를 시도 할 것이다, 내가 할 수있는 일이 –

0

날씨가 시스템 구성 시작시 사용할 수 있는지 확인할 수 있습니다.

확인해보십시오. RUN으로 이동하여 "Msconfig"를 입력하십시오. 실행하려는 응용 프로그램을 선택했는지 확인하십시오.

+0

하지만 이것은 Windows의 인증을 우회 한 후에 만 ​​작동합니다 ... 나는 우회 전에 필요합니다. –

+0

@ManuelFdz 당신이 요구하는 것은 Windows 서비스입니다. –

+0

프로그래밍 세계에서 새로운 I 'm는 내 작업에서 C#을 배웠습니다. 저는 메카트로닉스 엔지니어입니다. 그리고 lenguages는 매우 다르지만 여러 가지를 배우고 그것을 혼합하고 싶습니다 ... Windows Service가 해결책입니다. 내가 읽은 기사 –

관련 문제