PDA

View Full Version : سوال: دانلود و اجرا



AHRIMANSEFID
یک شنبه 08 اردیبهشت 1392, 13:30 عصر
من یه برنامه دارم که می خوام برای فعال سازی بعد از نصب برنامه به اینترنت متصل بشه + اینکه هر روز یا هر موقعه سیستم ریست شد اجرا بشه و فایلی را از 3 یا چند آدرس مشخص دانلود کنه و اگه فایل با فیال اصلی یکی بود برنامه را اجرا کنه.

حالا مشکل اصلی من در قسمت دانلود و اجرا برنامه هست.
برای مثال یک فایل .reg دانلود کنه و بعد اجرا کنه بدون این که کاربر متوجه بشه.

متشکر می شم با مثال بگید.

webeloper
یک شنبه 08 اردیبهشت 1392, 14:26 عصر
سلام
اول اینکه باید کلید یک کلید رجیستری در مسیر HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Run رجیستری ویندوز ایجاد کنید و مسیر فایل اجرایی نرم افزارتون رو اضافه کنید تا در زمان استارت آپ سیستم عامل برنامه اجرا شه

برای وارد کردن کلید رجیستری بدون اینکه کار بر متوجه بشه به صورت زیر عمل کنید:
Process addreg = Process.Start("regedit.exe", "/s file.reg");
addreg.WaitForExit();

namespace زیر هم باید اضافه کنید:
System.Diagnostics.Process

برای دانلود هم می تونید از webClient استفاده کنید.

AHRIMANSEFID
دوشنبه 09 اردیبهشت 1392, 09:12 صبح
این رو می دونم.
می خوام از 3 URL مختلف دانلود + اگه هر کدوم از سرور ها مشکل داشت یا قطع شد از رو سرور بعدی یعنی بین 3 سرور سویچ کنه.

danialafshari
دوشنبه 09 اردیبهشت 1392, 09:31 صبح
سلام
برای دانلود می تونی از این کد استفاده کنی :
System.Net.WebClient WebClient = new System.Net.WebClient();
WebClient.DownloadFile("آدرس فایل مبدا", @"آدرس فایل مقصد");
برای اتصال به سرور های بعد هم در صورت قطع بودن می تونی از بلوک try , Catch استفاده کنی
try
{
//server1
}
catch
{
try
{
//server2
}
catch
{
//server3
}
}
موفق باشی

AHRIMANSEFID
دوشنبه 09 اردیبهشت 1392, 13:56 عصر
این کد درست اما مشکل اینه که تیام یا timeout نداره بخاطر همین هی داره تو لوپ داره تکرار مه کنه و نه می ره رو سرور بعدی.


try
{
//server1
}
catch
{
try
{
//server2
}
catch
{
//server3
}
}

AHRIMANSEFID
سه شنبه 07 خرداد 1392, 10:28 صبح
متشکر می شم یه نمونه کد کامل بزارید.
حالا 2 تغییر جدید :
1 بعد از بالا آومدن ویندوز ران بشه.
2 فایل .reg رو دانلود و اینپورت کنه + ارسال پیغام موفق و غیر موفق هم بده.

mehrdad1991h
سه شنبه 07 خرداد 1392, 12:41 عصر
متشکر می شم یه نمونه کد کامل بزارید.
حالا 2 تغییر جدید :
1 بعد از بالا آومدن ویندوز ران بشه.
2 فایل .reg رو دانلود و اینپورت کنه + ارسال پیغام موفق و غیر موفق هم بده.

فکر میکنم نیاز به این هست که برنامه نویسیش را خودت انجام بدی !!
اخه دانلود که وبکلاینت استفاده میکنی
اینپورت کردن هم که نمونش را گذاشتن برات برای فایل های ریجستری
ارسال پیام هم دیگه خودت تویه کدت باید بزاری

کدش را میخوای برات بنوین ؟

AHRIMANSEFID
سه شنبه 07 خرداد 1392, 13:05 عصر
بله من خودم نوشتم اما می خوام ببینم دیگران چطور می نویسن.
این کد من 2 قسمت جدید شامل نه می شه.



private static bool UriServerIsUp(string UriStr)
{
try //Try to do the check without errors.
{
if (UriStr.ToUpper().StartsWith("FTP://")) //Check if the website procol are FTP.
{
FtpWebRequest fWebRequest = (FtpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
fWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
FtpWebResponse fWebResponse = (FtpWebResponse)fWebRequest.GetResponse(); //Get the server response.
if (fWebResponse.StatusCode == FtpStatusCode.OpeningData) //Get the server response code.
{
return true; //Return true if the response was 'OpeningData'.
}
else return false; //Return false if the response was not 'OpeningData'.
}
else //If is not FTP, check as HTTP protocol.
{
HttpWebRequest hWebRequest = (HttpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
hWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
HttpWebResponse hWebResponse = (HttpWebResponse)hWebRequest.GetResponse(); //Get the server response.
if (hWebResponse.StatusCode == HttpStatusCode.OK) //Get the server response code.
{
return true; //Return true if the response was 'OK'.
}
else return false; //Return false if the response was not 'OK'.
}
}
catch { return false; } //Return false if the there is an error with the request method.
}


foreach (string ServerUriString in
new object[] { "http://myfirstwebsite.com/regfile.reg", "ftp://ftp.mynewftp.com/regfile.reg", "http://mythserver.com/regfile.reg" }) //Make a simple forearch to check if the servers is working.
{
if (UriServerIsUp(ServerUriString)) //Check if the UriString has a valid status code.
{
DownloadAndInstallRegFile(ServerUriString); //Download and Install the registry file.
break; //Break the procedure one time that all the operation was completed successfully.
}
}

AHRIMANSEFID
سه شنبه 07 خرداد 1392, 13:07 عصر
می خوام یه سیستم جدید پیاده کنم.
اما نمی دونم.
اگه می توانید این کد های من یا کد های خوتون را کامل بزارید متشکر می شم.
کار زیاد دارم به این نمی رسم انجام بدم.

AHRIMANSEFID
سه شنبه 07 خرداد 1392, 13:08 عصر
می خوام یه سیستم جدید پیاده کنم.
اما نمی دونم.
اگه می توانید این کد های من یا کد های خوتون را کامل بزارید متشکر می شم.
کار زیاد دارم به این نمی رسم انجام بدم.

mehrdad1991h
سه شنبه 07 خرداد 1392, 16:16 عصر
بله من خودم نوشتم اما می خوام ببینم دیگران چطور می نویسن.
این کد من 2 قسمت جدید شامل نه می شه.



private static bool UriServerIsUp(string UriStr)
{
try //Try to do the check without errors.
{
if (UriStr.ToUpper().StartsWith("FTP://")) //Check if the website procol are FTP.
{
FtpWebRequest fWebRequest = (FtpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
fWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
FtpWebResponse fWebResponse = (FtpWebResponse)fWebRequest.GetResponse(); //Get the server response.
if (fWebResponse.StatusCode == FtpStatusCode.OpeningData) //Get the server response code.
{
return true; //Return true if the response was 'OpeningData'.
}
else return false; //Return false if the response was not 'OpeningData'.
}
else //If is not FTP, check as HTTP protocol.
{
HttpWebRequest hWebRequest = (HttpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
hWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
HttpWebResponse hWebResponse = (HttpWebResponse)hWebRequest.GetResponse(); //Get the server response.
if (hWebResponse.StatusCode == HttpStatusCode.OK) //Get the server response code.
{
return true; //Return true if the response was 'OK'.
}
else return false; //Return false if the response was not 'OK'.
}
}
catch { return false; } //Return false if the there is an error with the request method.
}


foreach (string ServerUriString in
new object[] { "http://myfirstwebsite.com/regfile.reg", "ftp://ftp.mynewftp.com/regfile.reg", "http://mythserver.com/regfile.reg" }) //Make a simple forearch to check if the servers is working.
{
if (UriServerIsUp(ServerUriString)) //Check if the UriString has a valid status code.
{
DownloadAndInstallRegFile(ServerUriString); //Download and Install the registry file.
break; //Break the procedure one time that all the operation was completed successfully.
}
}



و اینم سورس مطلب [+ (http://forums.mydigitallife.info/threads/44629-REQ-C-Download-And-Run-reg-Hide-amp-URL?)]
داداش حداقل یه خطش را عوض میکردی بعد میگفتی خودم نوشتم !! بهتر نبود بگی این کدی هست که استفاده میکنم ؟

موفق باشید

می خوام یه سیستم جدید پیاده کنم.
اما نمی دونم.
اگه می توانید این کد های من یا کد های خوتون را کامل بزارید متشکر می شم.
کار زیاد دارم به این نمی رسم انجام بدم.

شرمنده منم کار زیاد دارم امیدوارم بقیه کاری نداشته باشن و برات کدی که میخوای را بنویسن و بزارن شما هم استفاده کنی !!!
بابا یکم خودت کار کن بقیه هم کمکت میکنن نه اینکه کلش را از بقیه بخوای !

موفق باشی

AHRIMANSEFID
چهارشنبه 08 خرداد 1392, 08:52 صبح
این برنامه یکی از دوستام خواسته من هم وقت ندارم مثل شما.
گفتم شاید کسی باشه کد من رو کامل کنه.
اگر هم بلد نیستید بگید.