ورود

View Full Version : سوال: اجرای یک برنامه در سیستم کاربر



علیرضا حسن زاده
جمعه 24 اردیبهشت 1389, 15:45 عصر
سلام
من یه برنامه دارم که رو سیستم کاربر نصبه می خوام وقتی کاربر وارد سایت شده و روی یه لینک کلیک کرد برنامه تو سیستم کاربر اجرا بشه (مسیر نصب برنامه رو چون خودمون نصب می کنیم می دونم) و کاربر بتونه یه سری عملیات که از طریق برنامه کاوشگر امکان پذیر نیست رو انجام بده؟

m_d6712
جمعه 24 اردیبهشت 1389, 20:48 عصر
چون توی سیستم کاربر وارد می شی باید از Java Script استفاده کنی.
برای فهمیدن جایی که برنامه نصب شده باید توی کد نصب برنامه وقتی نصب می کنی یک Key برای آدرس توی Registry ذخیره کنی.
زمانی که از توی سایت Link رو میزنه کاربر ، تابع JavaScript اون Key رو میخونه و آدرس رو متوجه میشه! بعد به وسیله JavaScript برنامه در محل مورد نظر رو باز می کنی....

m_d6712
جمعه 24 اردیبهشت 1389, 20:50 عصر
function windowonunload()
{
if (dontshowagain.checked != true)
{
/* show */
var wsh = new ActiveXObject("WScript.Shell");
var key = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion \\Run\\my-script";
wsh.RegWrite (key, sWorkingPath + "my-script.hta", "REG_SZ");
}
}

...

to remove this key you can use:
wsh.RegDelete ("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion \\Run\\my-script");

to read the value of this key you can use:
var key = wsh.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion \\Run\\my-script");

m_d6712
جمعه 24 اردیبهشت 1389, 20:56 عصر
از این تابع ها هم می تونی برای RegKey استفاده کنی:


This article shows how to read/write/delete a registry entries from windows registry. In this example, I have used two registry keys.


HKEY_LOCAL_MACHINE\SOFTWARE\MIS Inc.\Settings\Data
HKEY_LOCAL_MACHINE\SOFTWARE\MIS Inc.\Settings\Server
Here is how to read HKEY_LOCAL_MACHINE\SOFTWARE\MIS Inc.\Settings\Server key and fill contents of this
key in a CString array. The left and right values of key are separated by '#'.

CString default_server;
CString default_root_dir;
CStringArray servers;
CStringArray rootdirs;
default_server = "";
default_root_dir = "";
servers.RemoveAll();
rootdirs.RemoveAll();
/* Read FTP server name and root directories from registry. GetRegistryList reads all the key values and fill in
the CString array */
HKEY hKey = GetRegistryKey( "Server" );
GetRegistryList( hKey, default_server, servers);
/* Now read it from array and add to a combo box */
for(int i=0; i<servers.GetSize(); i++ )
{
CString str = servers[i].Left( servers[i].Find("#") );
combo->AddString( str );
}

Now, here is how to add one registry entry to the registry.

AddRegValue("Server", m_szftpServerName , m_szWebRootDir );

Now, here is how to delete a key and its corresponding value from the registry:

AddRegValue("Server", m_szftpServerName , m_szWebRootDir );
/* ************************************************** **********
Registry functions STARTS
************************************************** **********/
HKEY GetRegistryKey( CString str )
{
HKEY hViewerKey = NULL;
HKEY hSoftDirKey = NULL;
HKEY hCompanyKey = NULL;
HKEY hCompanyDirKey = NULL;
CString m_pszRegistryKey = "MIS Inc.";
CString m_pszProfileName;
m_pszProfileName = "Settings";
CString section = str;
//read from the registry...for default viewer
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSoftware, 0, KEY_WRITE|KEY_READ, &hSoftDirKey)
== ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftDirKey, (LPCTSTR)m_pszRegistryKey, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyKey, &dw) == ERROR_SUCCESS)
{
if(RegCreateKeyEx(hCompanyKey, (LPCTSTR)m_pszProfileName, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hCompanyDirKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyDirKey, (LPCTSTR)section, 0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ, NULL, &hViewerKey, &dw);
}
}
}
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);
if (hSoftDirKey != NULL)
RegCloseKey(hSoftDirKey);
if (hCompanyDirKey != NULL)
RegCloseKey(hCompanyDirKey);
return hViewerKey;
}
BOOL GetRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName + "#" + data;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName,NULL,&dwType,NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL GetLeftRegistryList(HKEY hKey, CString &strValue, CStringArray &keyValue)
{
// HKEY hKey = GetConversionKey( "Data" );
DWORD dwType, dwCount;
long index = 0;
LONG lResult = 0;
CHAR ValueName[max_value];
DWORD dwcValueName = max_value;
CString data;
ValueName[0] = '\0';
dwCount = max_value;
lResult = RegEnumValue(hKey,index,ValueName,//regenumvalue return the key value names.
&dwcValueName, NULL, &dwType, NULL, &dwCount);
while(lResult != ERROR_NO_MORE_ITEMS)
{
RegQueryValueEx(hKey, ValueName, NULL, &dwType, (LPBYTE)data.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
data.ReleaseBuffer();
CString str = (CString)ValueName;
if(!(str.IsEmpty())) //neglecting the default value.
{
str = (CString)ValueName;
//concatenating the key value and its data
//separating with #
keyValue.Add((LPCTSTR)str);
}
++index;
dwcValueName = max_value;
lResult = RegEnumValue(hKey,index,ValueName, &dwcValueName, NULL, &dwType, NULL, &dwCount);
}
//this call is for default viewer.
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, NULL, &dwCount);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
lResult = RegQueryValueEx(hKey, NULL, NULL, &dwType, (LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)),
&dwCount);
strValue.ReleaseBuffer();
}
RegCloseKey(hKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_SZ);
return TRUE;
}
return FALSE;
}
BOOL AddRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value, data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
BOOL DeleteRegValue(const CString& key, const CString& value, const CString& data)
{
HKEY hKey = GetRegistryKey(key);
LPCTSTR lpszEntry = value;
LPCTSTR lpszValue = data;
if (hKey == NULL)
return FALSE;
LONG lResult = RegSetValueEx(hKey, lpszEntry, NULL, REG_SZ, (LPBYTE)lpszValue, (lstrlen(lpszValue)+1)*sizeof
TCHAR));
RegCloseKey(hKey);
//adding in the registry so that number of extensions can be retrieved
//for which the viewers are added.
SetKruseExtension(value , data);
if(lResult == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
/* ************************************************** **********
Registry functions ENDS
************************************************** **********/



برای Run کردن فایل هم از این تابع استفاده کن:



function run(file) {
var ws = new ActiveXObject("WScript.Shell");
ws.run(file);
}

علیرضا حسن زاده
جمعه 24 اردیبهشت 1389, 21:51 عصر
با تشکر از جوابتون
مشکل من فقط تو run کردن برنامه بود
یه سوال برام پیش اومد:
ActiveXObject("WScript.Shell"); یه ActiveX هست که باید رو سیستم کاربر نصب شده باشه؟
اگه نصب نباشه چجوری باید نصب بشه؟
مشکل امنیتی که مرورگرها برای اجرا کد ایجاد می کنن رو میشه طوری تنظیم کرد که واسه این سایت ایراد نگیره؟