여기 새로 생겼습니다. 콘솔 응용 프로그램에 문제가 있습니다. 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();
}
}
Windows 로그인 전에 콘솔 응용 프로그램을 실행할 수 없습니다. Windows 서비스를 만들어야합니다. [MSDN의 문서는 꽤 좋습니다] (http://msdn.microsoft.com/en-us/library/zt39148a (v = vs.110) .aspx) –
사용자가 로그인 할 때마다 스크립트를 실행 하시겠습니까 창문 기계? 레지스트리를 편집하고 경로를 추가하거나 그룹 정책 편집기를 사용하는 등 여러 가지 방법이 있습니다. 비슷한 게시물을보십시오 : https://superuser.com/questions/15596/automatically-run-a-script-when-i-log-on-to-windows –
그래, Windows 로그인 전에 실행해야합니다 ... 하지만 Windows 서비스 용 콘솔을 사용하거나 다른 것을 만들어야합니까 ?? –