WebClient 指定Cookies下载页面

作者:freethy 发布于:2015-7-18 15:29 Saturday


            string url = "http://www.xxxx.com/xxx.php?id=123456";
            string cookies = "PHPSESSID=xxx;xxxxxxxxxxxxxxxxxxxxxxxxxx";
           
            WebClient wc = new WebClient();
            wc.Headers.Add("Cookie", cookies);
            wc.Encoding = System.Text.Encoding.UTF8;
            string html = wc.DownloadString(url);

评论(0) 引用(0) 浏览(1609)

NSIS安装脚本

作者:freethy 发布于:2015-7-1 18:52 Wednesday

${PRODUCT_NAME}; 安装程序初始定义常量
!define PRODUCT_NAME "软件名"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_WEB_SITE "http://www.google.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"


SetCompressor /SOLID lzma
SetCompressorDictSize 32


; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"


; MUI 预定义常量
!define MUI_ABORTWARNING ;当用户要关闭安装程序时, 显示一个警告消息框
!define MUI_UNABORTWARNING ;当用户要关闭卸载程序时, 显示一个警告消息框
!define MUI_ICON "install.ico" ;安装程序图标
!define MUI_UNICON "uninst.ico" ;卸载程序图标
!define MUI_FINISHPAGE_NOAUTOCLOSE ;不自动跳到完成页面, 允许用户检查安装记录
!define MUI_UNFINISHPAGE_NOAUTOCLOSE ;不自动跳到完成页面, 允许用户检查卸载记录
!define MUI_WELCOMEFINISHPAGE_BITMAP "welcome.bmp" ;用于欢迎页面和完成页面的位图(推荐尺寸: 164x314 象素).
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "welcome.bmp" ;用于卸载页面的位图(推荐尺寸: 164x314 象素).
!define MUI_COMPONENTSPAGE_SMALLDESC ;较小的页面底部的描述区域
!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "鼠标移到组件上可查看相应说明" ;当没有选择区段时, 显示于描述框中的文本


; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 组件选择页面
!insertmacro MUI_PAGE_COMPONENTS
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 开始菜单设置页面
var ICONS_GROUP
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "PRODUCTNAME"!define MUISTARTMENUPAGEREGISTRYROOT "{PRODUCT_NAME}" !define MUI_STARTMENUPAGE_REGISTRY_ROOT "{PRODUCT_UNINST_ROOT_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "PRODUCTUNINSTKEY"!define MUISTARTMENUPAGEREGISTRYVALUENAME "{PRODUCT_UNINST_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "{PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe"
!define MUI_FINISHPAGE_RUN_NOTCHECKED ;默认不选中 '运行程序' 复选框
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Readme.txt"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED ;默认不选中 '自述文件' 复选框
!define MUI_FINISHPAGE_LINK "【欢迎访问作者主页】"
!define MUI_FINISHPAGE_LINK_LOCATION "${PRODUCT_WEB_SITE}"
!insertmacro MUI_PAGE_FINISH


; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES


; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "English"


; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------




Name "PRODUCTNAME{PRODUCT_NAME} {PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "PROGRAMFILES$PRODUCTNAME"InstallDirRegKey HKLM "PROGRAMFILES\${PRODUCT_NAME}" InstallDirRegKey HKLM "{PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails hide ;设置是否显示安装详细信息
ShowUnInstDetails hide
BrandingText "作者:"


Section "!主程序" SEC01
SectionIn RO ;必选组件灰色
  SetOutPath "$INSTDIR"
  SetOverwrite on
  File "Readme.txt"


; 创建开始菜单快捷方式
  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  CreateShortCut "DESKTOP$PRODUCTNAME.lnk" "DESKTOP\${PRODUCT_NAME}.lnk" "INSTDIR\PRODUCTNAME.exe"  CreateDirectory "{PRODUCT_NAME}.exe"   CreateDirectory "SMPROGRAMS\ICONSGROUP"  CreateShortCut "ICONS_GROUP"   CreateShortCut "SMPROGRAMS\ICONSGROUP$PRODUCTNAME.lnk" "ICONS_GROUP\${PRODUCT_NAME}.lnk" "INSTDIR\${PRODUCT_NAME}.exe"
  !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd


; 安装.NET Framework
Section "Microsoft .NET Framework 2.0" SEC02
  File "DotNet.exe"
  ExecWait '"DotNet.exe" /q:a /c:"install.exe /q"'
SectionEnd


Section -AdditionalIcons
  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  WriteIniStr "INSTDIR$PRODUCTNAME.url" "InternetShortcut" "URL" "INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "{PRODUCT_WEB_SITE}"
  CreateShortCut "SMPROGRAMS$ICONSGROUP\欢迎访问作者主页.lnk" "SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk" "INSTDIR\PRODUCTNAME.url"  CreateShortCut "{PRODUCT_NAME}.url"   CreateShortCut "SMPROGRAMS\ICONSGROUP\卸载.lnk" "ICONS_GROUP\卸载.lnk" "INSTDIR\uninst.exe"
  !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd


Section -Post
  WriteUninstaller "INSTDIR\uninst.exe"  WriteRegStr HKLM "INSTDIR\uninst.exe"   WriteRegStr HKLM "{PRODUCT_DIR_REGKEY}" "" "$INSTDIR\PRODUCTNAME.exe"  WriteRegStr{PRODUCT_NAME}.exe"   WriteRegStr {PRODUCT_UNINST_ROOT_KEY} "PRODUCTUNINSTKEY" "DisplayName" "{PRODUCT_UNINST_KEY}" "DisplayName" "(^Name)"
  WriteRegStr PRODUCTUNINSTROOTKEY "{PRODUCT_UNINST_ROOT_KEY} "{PRODUCT_UNINST_KEY}" "UninstallString" "INSTDIR\uninst.exe"  WriteRegStrINSTDIR\uninst.exe"   WriteRegStr {PRODUCT_UNINST_ROOT_KEY} "PRODUCTUNINSTKEY" "DisplayIcon" "{PRODUCT_UNINST_KEY}" "DisplayIcon" "INSTDIR\PRODUCTNAME.exe"  WriteRegStr{PRODUCT_NAME}.exe"   WriteRegStr {PRODUCT_UNINST_ROOT_KEY} "PRODUCTUNINSTKEY" "DisplayVersion" "{PRODUCT_UNINST_KEY}" "DisplayVersion" "{PRODUCT_VERSION}"
  WriteRegStr PRODUCTUNINSTROOTKEY "{PRODUCT_UNINST_ROOT_KEY} "{PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
SectionEnd


#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#


; 区段组件描述
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT SEC01 "必备组件"  !insertmacro MUIDESCRIPTIONTEXT{SEC01} "必备组件"   !insertmacro MUI_DESCRIPTION_TEXT {SEC02} "运行主程序必需的框架,如果确认已经安装,则不必勾选"
!insertmacro MUI_FUNCTION_DESCRIPTION_END


/******************************
 *  以下是安装程序的卸载部分  *
 ******************************/


Section Uninstall
  !insertmacro MUI_STARTMENU_GETFOLDER "Application" ICONSGROUP  Delete "ICONS_GROUP   Delete "INSTDIR\uninst.exe"


  Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
  
  SetShellVarContext current ;当前用户开始菜单
  Delete "SMPROGRAMS$ICONSGROUP\卸载.lnk"  Delete "SMPROGRAMS\$ICONS_GROUP\卸载.lnk"   Delete "SMPROGRAMS\ICONSGROUP$PRODUCTNAME.lnk"  Delete "ICONS_GROUP\${PRODUCT_NAME}.lnk"   Delete "SMPROGRAMS\ICONSGROUP\欢迎访问作者主页.lnk"  RMDir /r "ICONS_GROUP\欢迎访问作者主页.lnk"   RMDir /r "SMPROGRAMS\$ICONS_GROUP"
    SetShellVarContext all ;全部用户开始菜单
  Delete "SMPROGRAMS$ICONSGROUP\卸载.lnk"  Delete "SMPROGRAMS\$ICONS_GROUP\卸载.lnk"   Delete "SMPROGRAMS\ICONSGROUP$PRODUCTNAME.lnk"  Delete "ICONS_GROUP\${PRODUCT_NAME}.lnk"   Delete "SMPROGRAMS\ICONSGROUP\欢迎访问作者主页.lnk"    RMDir /r "ICONS_GROUP\欢迎访问作者主页.lnk"      RMDir /r "SMPROGRAMS\ICONSGROUP"  RMDir /r "ICONS_GROUP"    RMDir /r "INSTDIR"


  DeleteRegKey PRODUCTUNINSTROOTKEY "{PRODUCT_UNINST_ROOT_KEY} "{PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "{PRODUCT_DIR_REGKEY}"   SetAutoClose false SectionEnd  #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#  Function un.onInit   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除{PRODUCT_DIR_REGKEY}"   SetAutoClose false SectionEnd  #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#  Function un.onInit   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 (^Name) ,及其所有的组件?" IDYES +2
  Abort
FunctionEnd


Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd

评论(0) 引用(0) 浏览(1896)

Powered by emlog 苏ICP备11068260号-3