原文 NSIS常用代码整理
这是一些常用的NSIS代码,少轻狂特意整理出来,方便大家随时查看使用。不定期更新哦~~~
2 |
ReadEnvStr $R0 SYSTEMDRIVE |
4 |
CreateDirectory "$R0\log"
|
|
2 |
FindWindow $0 "shell_traywnd"
|
3 |
SendMessage $0 273 506 0 |
|
2 |
FindWindow $0 "shell_traywnd"
|
3 |
SendMessage $0 273 503 0 |
|
2 |
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
|
|
3 |
;-1 主题 0 壁纸 1 屏保 2 外观 3 设置 |
4 |
Exec 'Rundll32.exe shell32.dll,Control_RunDLL Desk.cpl,0,3' ;打开 "设置"
|
|
2 |
System::Call 'kernel32::GetCurrentDirectory(i 1024,t .R1)'
|
3 |
MessageBox MB_OK '安装程序所在目录:$R1'
|
5 |
MessageBox MB_OK '文件名$EXEFILE,所在文件夹$EXEDIR,完整路径$EXEPATH。'
|
|
2 |
System::Call 'kernel32::GetCurrentProcessId()i .R0'
|
3 |
MessageBox MB_OK '安装程序进程PID:$R0'
|
|
3 |
System::Call 'kernel32::GetVolumeInformationA(t R0,t .R1,i 100,i .R3,i .R4,i .R5,t .R6,i 100)'
|
4 |
MessageBox MB_OK '盘符:$R0$\n卷标:$R1$\n文件格式:$R6'
|
|
4 |
System::Call 'kernel32::SetVolumeLabelA(t R0,t R1)'
|
|
02 |
StrCpy $R0 "C:\1.EXE" ;文件
|
04 |
System::Call 'kernel32::SetFileAttributesA(t R0,i 0x100)'
|
06 |
;0x20 FILE_ATTRIBUTE_ARCHIVE,存档 |
07 |
;0x2 FILE_ATTRIBUTE_HIDDEN,隐藏 |
08 |
;0x80 FILE_ATTRIBUTE_NORMAL,正常 |
09 |
;0x2000 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,不索引 |
10 |
;0x1000 FILE_ATTRIBUTE_OFFLINE,离线 |
11 |
;0x1 FILE_ATTRIBUTE_READONLY,只读 |
12 |
;0x4 FILE_ATTRIBUTE_SYSTEM,系统 |
13 |
;0x100 FILE_ATTRIBUTE_TEMPORARY,;临时属性(一般无效) |
|
3 |
CreateShortcut "$DESKTOP\记事本.lnk" "$WINDIR\notepad.exe"
|
4 |
ExecShell taskbarpin "$DESKTOP\记事本.lnk"
|
|
1 |
;指定在 WIN7 下安装程序需要的执行级别。 |
2 |
RequestExecutionLevel admin |
|
1 |
;安装结束后调用HTTP下载插件下载文件并运行 |
5 |
StrCmp $R0 "success" +3
|
6 |
MessageBox MB_OK "下载失败,原因: $R0"
|
|
1 |
;隐藏/显示文件扩展名实时生效,写入 0 (0x00000000) 显示或 1 (0x00000001) 来隐藏 |
2 |
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "HideFileExt" 0x00000001
|
3 |
SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:ShellState"
|
4 |
System::Call "shell32::SHChangeNotify(i0x08000000,i0,i0,i0)"
|
|
01 |
OutFile "ScreenRes.exe"
|
07 |
System::Call 'user32::GetSystemMetrics(i 0) i .r0'
|
08 |
System::Call 'user32::GetSystemMetrics(i 1) i .r1'
|
09 |
MessageBox MB_OK|MB_ICONINFORMATION "当前屏幕分辨率为: $\r$\n$0 X $1"
|
|
1 |
;调用 Windows API 来获取运行时间 |
3 |
System::Call kernel32::GetLocalTime(isR0) |
4 |
System::Call *$R0(&i2.R1,&i2.R2,&i2.R3,&i2.R4,&i2.R5,&i2.R6,&i2.R7,&i2.R8) |
6 |
MessageBox MB_OK "$R1年$R2月$R4日,星期$R3,$R5:$R6:$R7.$R8"
|
|
1 |
;使用MiscButtonText修改按钮文本 |
2 |
;分别对应[上一步]、[下一步]、[取消]、[关闭],如果留空参数,则使用默认值 |
3 |
MiscButtonText "" "" "" "完成(&G)"
|
5 |
!insertmacro MUI_PAGE_INSTFILES |
|
2 |
AccessControl::DisableFileInheritance "$INSTDIR" ;禁止继承
|
3 |
AccessControl::ClearOnFile "$INSTDIR" "(S-1-1-0)" "FullAccess" ;设置Everyone权限
|
|
08 |
ReadRegStr $0 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "VendorIdentifier"
|
09 |
ReadRegStr $1 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "ProcessorNameString"
|
10 |
ReadRegStr $2 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "Identifier"
|
11 |
ReadRegStr $3 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "~MHz"
|
13 |
ReadRegStr $4 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BaseBoardManufacturer"
|
14 |
ReadRegStr $5 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BIOSVersion"
|
15 |
ReadRegStr $6 HKLM "HARDWARE\DESCRIPTION\System\BIOS" "BIOSReleaseDate"
|
16 |
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"
|
|
02 |
OutFile "判断操作系统位宽.exe"
|
|
03 |
SetFileAttributes "$SYSDIR\drivers\etc\hosts" NORMAL ;去只读属性
|
04 |
FileOpen $9 $SYSDIR\drivers\etc\hosts a ;追加数据 |
05 |
;FileSeek $9 0 END ;指针定位到相对于文件结尾 |
06 |
FileWrite $9 "127.0.0.1 adcount.sandai.net $\r$\n"
|
07 |
FileWrite $9 "127.0.0.1 biz4.sandai.net $\r$\n"
|
09 |
SetFileAttributes "$SYSDIR\drivers\etc\hosts" READONLY ;加只读属性
|
|
1 |
;对比两个文件的时间,如两个时间相等,就返回0;如R0小于R1,返回-1;如R1小于R0,返回1 |
2 |
StrCpy $R0 "C:\boot.ini"
|
3 |
StrCpy $R1 "C:\AUTOEXEC.BAT"
|
4 |
System::Call 'kernel32::CompareFileTime(t R0,t R1) i.R2'
|
5 |
MessageBox MB_OK '文件$R0与$R1时间比较结果$R2'
|
|