最近遇到需要实现某个应用程序开机自动启动的功能,在网上查了一些资料,大概有两种方法:
1.通过写注册表来实现
参考一下代码:
在installshield中写注册表,让应用程序开机启动
///
// //
// Function: SetupRegistry //
// //
// Purpose: This function makes the registry entries for this setup. //
// //
///
function SetupRegistry()
NUMBER nResult;
STRING szPath3;
STRING szResult;
begin
// TODO : Add all your registry entry keys here
//
//
// RegDBCreateKeyEx, RegDBSetKeyValueEx....
//
//nResult = CreateRegistrySet( "" );
if(FindFile(TARGETDIR,"Sanc.exe",szResult)=0) then
szPath3=TARGETDIR^"Sanc.exe";
LongPathToQuote(szPath3,TRUE);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult=RegDBSetKeyValueEx("SOFTWARE//Microsoft//Windows//CurrentVersion//Run","Sanc",REGDB_STRING,szPath3,-1);
endif;
return nResult;
end;
还有一个问题就是想实现界面上Checkbox选择是否要开机启动,关键是实现一个checkbox,参考以下代码:
Disable(STATUSEX);
ShowObjWizardPages(NEXT);
bOpt1 = TRUE;
bOpt2 = TRUE;
szMsg1 = SdLoadString(IFX_SDFINISH_MSG1);
szTitle="";
szMsg1="";
szMsg2="";
szOption1="Show Readme";
szOption2="Create Shortcut on Desktop";
SdFinishEx(szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2);
写注册表的方式,在卸载时可正常的卸载掉开机启动的功能,但是用户不能在启动项中将该功能删除,
2.在启动文件夹中创建应用程序的启动快捷方式
可以在Shortout中直接建立这个快捷方式,无需编程;
但实现用户点选checkbox的方式,可写script,可使用AddFolderIcon实现快捷方式的建立,可参考:
AddFolderIcon (szProgramFolder, szItemName, szCommandLine, szWorkingDir, szIconPath, nIcon, szShortCutKey, nFlag);
/**//*--------------------------------------------------------------*
*
* InstallShield Example Script
*
* Demonstrates the AddFolderIcon function.
*
* This example places a shortcut to an executable file on the
* Start menu and the Start Programs menu.
*
* Note: Before running this script, set the preprocessor
* constants so that they reference the fully-qualified
* names of the Windows Notepad executable and a valid
* text file on the target system.
*
*--------------------------------------------------------------*/
#define PROGRAM "C:/Windows/Notepad.exe"
#define PARAM "C:/Windows/Readme.txt"
STRING szProgramFolder, szItemName, szCommandLine, szWorkingDir, szIconPath;
STRING szShortCutKey, szProgram, szParam;
NUMBER nIcon;
#include "ifx.h"
program
// Set up parameters for call to AddFolderIcon.
szProgramFolder = FOLDER_STARTMENU;
szItemName = "Notepad Example 1";
szProgram = PROGRAM;
szParam = PARAM;
LongPathToQuote (szProgram, TRUE);
LongPathToShortPath (szParam);
szCommandLine = szProgram + " " + szParam;
szWorkingDir = "";
szIconPath = "";
nIcon = 0;
szShortCutKey = "";
// Add a shortcut to the Start menu.
if (AddFolderIcon (szProgramFolder, szItemName, szCommandLine, szWorkingDir,
szIconPath, nIcon, szShortCutKey, REPLACE) < 0) then
MessageBox ("AddFolderIcon failed.", SEVERE);
else
SprintfBox (INFORMATION, "AddFolderIcon", "%s created successfully.",
szItemName);
endif;
szProgramFolder = "";
szItemName = "Notepad Example 2";
// Add a shortcut to the Programs menu.
if (AddFolderIcon (szProgramFolder, szItemName, szCommandLine, szWorkingDir,
szIconPath, nIcon, szShortCutKey, REPLACE) < 0) then
MessageBox ("AddFolderIcon failed.", SEVERE);
else
SprintfBox (INFORMATION, "AddFolderIcon", "%s created successfully.",
szItemName);
endif;
endprogram
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/leon_founder/archive/2006/08/21/1102447.aspx