;获取操作系统盘符 ReadEnvStr $R0 SYSTEMDRIVE ;创建log文件夹 CreateDirectory "$R0\log" ;递归删除log文件夹 RMDir /r "$R0\log" |
;弹出Windows关机框 FindWindow $0 "shell_traywnd" SendMessage $0 273 506 0 |
;请求Windows帮助 FindWindow $0 "shell_traywnd" SendMessage $0 273 503 0 |
;一句话刷新屏幕 System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)' |
;打开桌面属性 ;...cpl,0,3'中的3可以改为 ;-1 主题 0 壁纸 1 屏保 2 外观 3 设置 Exec 'Rundll32.exe shell32.dll,Control_RunDLL Desk.cpl,0,3' ;打开"设置" |
;获得安装程序所在目录 System::Call 'kernel32::GetCurrentDirectory(i 1024,t .R1)' MessageBox MB_OK '安装程序所在目录:$R1' ;或者直接使用变量 MessageBox MB_OK '文件名$EXEFILE,所在文件夹$EXEDIR,完整路径$EXEPATH。' |
;获得当前安装程序进程PID System::Call 'kernel32::GetCurrentProcessId()i .R0' MessageBox MB_OK '安装程序进程PID:$R0' |
;获得磁盘卷标 StrCpy $R0 "C:\" System::Call 'kernel32::GetVolumeInformationA(t R0,t .R1,i 100,i .R3,i .R4,i .R5,t .R6,i 100)' MessageBox MB_OK '盘符:$R0$\n卷标:$R1$\n文件格式:$R6' |
;设置磁盘卷标 StrCpy $R0 "C:\" ;盘符 StrCpy $R1 "系统" ;卷标 System::Call 'kernel32::SetVolumeLabelA(t R0,t R1)' |
;设置文件属性 StrCpy $R0 "C:\1.EXE" ;文件 StrCpy $R1 0x20 ;属性 System::Call 'kernel32::SetFileAttributesA(t R0,i R1)' ;属性表 ;0x20 FILE_ATTRIBUTE_ARCHIVE,存档 ;0x2 FILE_ATTRIBUTE_HIDDEN,隐藏 ;0x80 FILE_ATTRIBUTE_NORMAL,正常 ;0x2000 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,不索引 ;0x1000 FILE_ATTRIBUTE_OFFLINE,离线 ;0x1 FILE_ATTRIBUTE_READONLY,只读 ;0x4 FILE_ATTRIBUTE_SYSTEM,系统 ;0x100 FILE_ATTRIBUTE_TEMPORARY,;临时属性(一般无效) |
;在WIN7任务栏中增加图标链接 SetOutPath $WINDIR CreateShortcut "$DESKTOP\记事本.lnk" "$WINDIR\notepad.exe" ExecShell taskbarpin "$DESKTOP\记事本.lnk" |
;指定在 WIN7 下安装程序需要的执行级别。 RequestExecutionLevel admin |
;安装结束后调用HTTP下载插件下载文件并运行 Function .onGUIEnd NSISdl::download "http://www.flighty.cn/服务器文件名.exe" "本地文件名.exe" Pop $R0 ;获取返回值 StrCmp $R0 "success" +3 MessageBox MB_OK "下载失败,原因: $R0" Quit exec ""本地文件名.exe"" FunctionEnd |
;隐藏/显示文件扩展名实时生效,写入 0 (0x00000000) 显示或 1 (0x00000001) 来隐藏 WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "HideFileExt" 0x00000001 SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:ShellState" System::Call "shell32::SHChangeNotify(i0x08000000,i0,i0,i0)" |
OutFile "ScreenRes.exe" Name "获取当前屏幕分辨率" Caption "获取当前屏幕分辨率" XPStyle "on" Function ".onInit" System::Call 'user32::GetSystemMetrics(i 0) i .r0' System::Call 'user32::GetSystemMetrics(i 1) i .r1' MessageBox MB_OK|MB_ICONINFORMATION "当前屏幕分辨率为: $\r$\n$0 X $1" Quit FunctionEnd Section "轻狂志" ;您的其他代码 SectionEnd |
OutFile flighty.exe Section "将轻狂志设为首页" WriteRegStr HKCU "Software\Microsoft\Internet Explorer\Main" "Start Page" http://www.flighty.cn SectionEnd |
;调用 Windows API 来获取运行时间 System::Alloc 16 System::Call kernel32::GetLocalTime(isR0) System::Call *$R0(&i2.R1,&i2.R2,&i2.R3,&i2.R4,&i2.R5,&i2.R6,&i2.R7,&i2.R8) System::Free $R0 MessageBox MB_OK "$R1年$R2月$R4日,星期$R3,$R5:$R6:$R7.$R8" |
;使用MiscButtonText修改按钮文本 ;分别对应[上一步]、[下一步]、[取消]、[关闭],如果留空参数,则使用默认值 MiscButtonText "" "" "" "完成(&G)" ;安装过程页面 !insertmacro MUI_PAGE_INSTFILES |
;清除目录权限及设置目录权限 AccessControl::DisableFileInheritance "$INSTDIR" ;禁止继承 AccessControl::ClearOnFile "$INSTDIR" "(S-1-1-0)" "FullAccess" ;设置Everyone权限 |
Name "获得CPU和BIOS信息" OutFile "flighty.exe" Section SectionEnd Function .onInit ReadRegStr $0 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "VendorIdentifier" ReadRegStr $1 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "ProcessorNameString" ReadRegStr $2 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "Identifier" ReadRegStr $3 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "~MHz" ReadRegStr $4 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BaseBoardManufacturer" ReadRegStr $5 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BIOSVersion" ReadRegStr $6 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BIOSReleaseDate" MessageBox MB_OK|MB_ICONEXCLAMATION "CPU制造商$0 $\r$\nCPU型号$1 $\r$\nCPU标识$2 $\r$\nCPU主频$3 $\r$\n$\r$\n主板品牌$4 $\r$\n主板BIOS版本$5 $\r$\n主板BIOS日期$6" Abort FunctionEnd |
Name "判断操作系统位宽" OutFile "判断操作系统位宽.exe" !include "x64.nsh" Section SectionEnd Function .onInit ${If} ${RunningX64} MessageBox MB_OK "64" ${Else} MessageBox MB_OK "32" ${EndIf} FunctionEnd |
;在 hosts 文件中追加地址屏蔽脚本 ClearErrors SetFileAttributes "$SYSDIR\drivers\etc\hosts" NORMAL ;去只读属性 FileOpen $9 $SYSDIR\drivers\etc\hosts a ;追加数据 ;FileSeek $9 0 END ;指针定位到相对于文件结尾 FileWrite $9 "127.0.0.1 adcount.sandai.net $\r$\n" FileWrite $9 "127.0.0.1 biz4.sandai.net $\r$\n" ;下面自己加 SetFileAttributes "$SYSDIR\drivers\etc\hosts" READONLY ;加只读属性 FileClose $9 ;关闭打开的文件 |
;对比两个文件的时间,如两个时间相等,就返回0;如R0小于R1,返回-1;如R1小于R0,返回1 StrCpy $R0 "C:\boot.ini" StrCpy $R1 "C:\AUTOEXEC.BAT" System::Call 'kernel32::CompareFileTime(t R0,t R1) i.R2' MessageBox MB_OK '文件$R0与$R1时间比较结果$R2' |
;注册apache服务器, -n MyWebServer表示apache2注册服务名为MyWebServer,默认服务名为Apache2 nsExec::ExecToLog 'cmd.exe /c "$INSTDIR/apache2/bin/httpd.exe" -k install -n MyWebServer' ;注册MySQL服务器, MyDBServer表示MySQL注册服务名为MyDBServer,默认服务名为MySQL nsExec::ExecToLog 'cmd.exe /c "$INSTDIR/mysql5/bin/mysqld-nt.exe" -install MyDBServer' ;启动apache服务和MySQL服务 nsExec::ExecToLog 'cmd.exe /c "$INSTDIR/apache2/bin/httpd.exe" -k start -n MyWebServer' ;或者 nsExec::ExecToLog 'cmd.exe /c net start MyWebServer' nsExec::ExecToLog 'cmd.exe /c net start MyDBServer' |
;从注册表中读取操作系统语言 ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Nls\Language" "Default" ${If} $0 = 0804 MessageBox MB_OK "您的操作系统语言为简体中文。" ${ElseIf} $0 == 0404 MessageBox MB_OK "您的操作系统语言为繁体中文。" ${ElseIf} $0 == 0409 MessageBox MB_OK "您的操作系统语言为英文。" ${EndIf} |