Jump to content

Yaliang

Members
  • Posts

    18
  • Joined

  • Last visited

  • Days Won

    7

Reputation Activity

  1. Like
    Yaliang got a reaction from SunLion in [inno setup] A way to pin a shortcut onto taskbar in code   
    It is a very good change.
    Regards... ;-)
     
  2. Like
    Yaliang got a reaction from SunLion in [inno setup] A way to pin a shortcut onto taskbar in code   
    Maybe U can see the [uninstallDelete] section in InnoSetup documentation.
    I am trying to find a way in
    section.but not finished.In theory, pin or unpin is the same way.
  3. Like
    Yaliang got a reaction from SunLion in [inno setup] A way to pin a shortcut onto taskbar in code   
    Use COM methods and properties via the COM Automation objects support.
    So I translate a Delphi script to Inno Setup
    section.And it work! 
     
    Here is a part of script in [code] section:
    [code]
    http://www.jrsoftware.org)
    There are someway to pin taskbar depend on one's choice.
    We can add a [task] section in InnoSetup.
    if one do not want to see the "task selected page"(like me ),
    the second way is to create a new CheckBox in Inno [code] section.
    And in the second way one need to control the CheckBox show or hide inprocedure CurPageChanged().
    then call the function like:   zylPinAppToTaskbar('c:\window', 'notepad.exe'); 
     
    An example project for Unicode Inno Setup is provided as download.
    The attachment "pintaskbar.zip" is the script.
    Unzip the file pintaskbar.zip,you can get two files named "PinShortcutOntoTaskbar-task.iss"
    and "PinShortcutOntoTaskbar-checkbox.iss".
    Please copy the *.iss files to the directory:  ./Inno Setup 5/Examples
    Then build the program and run PinTaskbar.exe.
     
    References
    http://blog.csdn.net/ccrun/article/details/6906471
    http://gallery.technet.microsoft.com/ScriptCenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750/
    http://www.codeproject.com/Tips/713824/Pin-a-shortcut-onto-the-Taskbar-or-Start-Menu 
     
    The following is the script of the second way, I think you can modify it to the first way.
    If the attachment was broken, copy the following script to a *.iss file.
     
    ; -- PinShortcutOntoTaskbar.iss --
    ; Pin a shortcut onto taskbar on Win7 & Win8.
    ; @author: Yaliang.Zhao <shuangxiang2008@google.com>
    ; @brief: I test is on 32-bit  Win7 & Win8, but
    ;         I thins it will work on X64 version.
    [setup]
    AppName=PinTaskbar
    AppVersion=1.0
    OutputBaseFilename=PinTaskbar
    DefaultDirName={pf}\PinTaskbar
    OutputDir=./
    DisableStartupPrompt=yes
    DisableReadyPage=yes
    [Files]
    Source: "MyProg.exe"; DestDir: "{app}"
    ;[Tasks]
    ;Name: pintaskbar; Description: "Pin shortcut onto taskbar"
    ;Following is how to use
    [Code]
    var
    PinTaskBarCheck : TNewCheckBox;
    //the function is work well on Unicode Inno Setup,
    //if Non Unicode Inno Setup, one need to modify,
    //and I think you can do it!
    //Inno use Win32 API
    function LoadLibrary(lpFilename : String) : LongInt;
    external 'LoadLibraryW@kernel32.dll stdcall delayload';  //if Non Unicode Inno Setup, use LoadLibraryA
    function FreeLibrary(hModule : LongInt) : BOOL;
    external 'FreeLibrary@kernel32.dll stdcall delayload';
    function LoadString(hInstance:LongInt; uId:UINT; lpBuffer:String; nBufferMax:Integer) : Integer;
    external 'LoadStringW@user32.dll stdcall delayload';  //if Non Unicode Inno Setup, use LoadStringA
    //here is the function
    //@param strPath The App's directory,
    //@param strApp The App's name
    //@example zylPinAppToTaskbar('c:\window', 'notepad.exe');
    procedure zylPinAppToTaskbar(strPath, strApp: string); 
    var 
      vShell, vFolder, vFolderItem, vItemVerbs: Variant; 
      vPath, vApp: Variant; 
      i: Integer; 
      sItem: String;  
      h: LongInt;
      szPinName: String;
      filenameEnd : Integer;
      filename    : String;
      strEnd    : String;
    begin
      SetLength(szPinName, 255);
      h := LoadLibrary(ExpandConstant('{sys}\Shell32.dll')); 
      LoadString(h, 5386, szPinName, 255); 
      FreeLibrary(h); 
      strEnd := #0;
      filenameEnd := Pos(strEnd, szPinName);
      filename := Copy(szPinName, 1, filenameEnd - 1);
      if (Length(filename) > 0) then  //WinXp or lower, no pin taskbar function
      begin
        vShell := CreateOleObject('Shell.Application'); 
        vPath := strPath; 
        vFolder := vShell.NameSpace(vPath); 
        vApp := strApp; 
        vFolderItem := vFolder.ParseName(vApp); 
        vItemVerbs := vFolderItem.Verbs; 
        
      for i := 1 to vItemVerbs.Count do 
      begin 
        sItem := vItemVerbs.Item(i).Name;
        if (sItem = filename) then
        begin
          // 63 63 72 75 6E 2E 63 6F 6D 
          vItemVerbs.Item(i).DoIt;
          break;
         end;
        end; 
      end;
    end; 
    //You can use zylPinAppToTaskbar like this
    procedure CurPageChanged(CurPageID: Integer);
    begin
      //When Finished page is shown, call the function
      //You can also call is when the "Finish" button clicked.
      if CurPageID <> wpWelcome then
        PinTaskBarCheck.hide
      else begin
        PinTaskBarCheck.show;
      end;
      if  CurPageID = wpFinished then 
      begin
      //if IsTaskSelected('pintaskbar') then  //if Selected the [task]
      //   zylPinAppToTaskbar(ExpandConstant('{app}'), 'MyProg.exe');
      if PinTaskBarCheck.Checked then
        zylPinAppToTaskbar(ExpandConstant('{app}'), 'MyProg.exe');
      end;
    end;
    procedure InitializeWizard;
    begin
      PinTaskBarCheck := TNewCheckBox.Create(WizardForm);
       with PinTaskBarCheck do begin
        Parent  := WizardForm;
        Caption := 'Pin it onto taskbar';
        Top     := 200;
        Left    := 200;
        Width   := ScaleY(200);
        Height  := ScaleY(15);
        State   := cbChecked;
        //Hide;
      end;
    end;
    pintaskbar.zip
  4. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    Maybe it is helpful for someone.
  5. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    sorry to head that
  6. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    hi,too late to replay. hope you finished your problems.:)
  7. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    thank you. Your problems and solutions are very helpful. 
    When I write the code, I just on Win7_x86 OS.
  8. Like
    Yaliang got a reaction from generalp in [inno setup]Check app(*.exe) is running in Code section   
    There are some ways to do this. Such as using a external DLL.But I do not like this way.
    The Inno surport Pascal script. The Pascal script can call standard Win32 API functions inside standard Windows DLLs. So we can check the app is whether running.
    Here is a part of script in
    section:; Any question, let me know.
    ;It work on 32 and 64 modules!
    [code]
    type HANDLE = LongInt;
    HMODULE = HANDLE;
    pHMODULE = Array[0..255] of HMODULE;
    LPDWORD = DWORD; PDWORD = Array[0..255] of DWORD;
    LPTSTR = String;
    const PROCESS_QUERY_INFORMATION = $400;
    PROCESS_VM_READ = $10;
    MAX_LENGTH = 255;
    function OpenProcess(dwDesiredAccess : DWORD; bInheritHandle : Boolean; dwProcessId : DWORD) : HANDLE;
    external 'OpenProcess@kernel32.dll stdcall delayload';
    function CloseHandle(hObject : HANDLE) : BOOL;
    external 'CloseHandle@kernel32.dll stdcall delayload';
    function EnumProcesses(var pProcessIds : PDWORD; cb : DWORD; var pBytesReturned : DWORD) : BOOL;
    external 'EnumProcesses@psapi.dll stdcall delayload';
    //notice:delayload EnumProcessModules and EnumProcessModulesEx functions
    //64-bit using EnumProcessModulesEx; 32-bite using EnumProcessModules
     
    function EnumProcessModulesEx(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD; dwFilterFlag : DWORD) : BOOL;
    external 'EnumProcessModulesEx@psapi.dll stdcall delayload';function EnumProcessModules(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD) : BOOL;
    external 'EnumProcessModules@psapi.dll stdcall delayload';
    function GetModuleFileNameExW(hProcess : HANDLE; hModule : HMODULE; lpFilename : LPTSTR; nSize : DWORD) : DWORD;
    external 'GetModuleFileNameExW@psapi.dll stdcall delayload';
    //here is the functionfunction
    zylIsAppRunning(procName : String; fullPath : Boolean) : Boolean;
    var found : Boolean;
    filenameEnd : Integer;
    filename : String;
    NA : DWORD;
    entry : DWORD;
    maxEntries : DWORD;
    processes : PDWORD;
    lpFilename : LPTSTR;
    hProcess : HANDLE;
    hMod : pHMODULE;
    isModuleShot: Boolean;
    begin
    SetLength(lpFilename, MAX_LENGTH);
    found := False;
    if (EnumProcesses(processes, SizeOf(processes), maxEntries)) then
    begin
    entry := 0;
    maxEntries := maxEntries / SizeOf(maxEntries);
    while ((not found) and (entry < maxEntries)) do begin
    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processes[entry]);
    if (hProcess <> 0) then
    begin
    isModuleShot := False;
    if IsWin64 then
    begin //EnumProcessModulesEx @param $3,surport 32-bit modules and 64-bit modules the sametiem
    isModuleShot := EnumProcessModulesEx(hProcess, hMod, SizeOf(hMod), NA, $3);
    end else begin
    isModuleShot := EnumProcessModules(hProcess, hMod, SizeOf(hMod), NA);
    end;
    if (isModuleShot) then
    if (GetModuleFileNameExW(hProcess, hMod[0], lpFilename, Length(lpFilename)) > 0)
    then begin
    filenameEnd := Pos(#0, lpFilename);
    filename := Copy(Lowercase(lpFilename), 1, filenameEnd - 1);
    if (not fullpath) then
    filename := ExtractFileName(filename);
    if (AnsiLowercase(filename) = AnsiLowercase(procName)) then
    found := True;
    end;
    CloseHandle(hProcess);
    end;
    entry := entry + 1;
    end;
    end;
    Result := found;
    end;//function end
     
    How to use:
    I wish you have installed the Unicode Inno Setup (the 5.5.x version or more).(If not, you can download it from the home page http://www.jrsoftware.org)
    You can use it where you need just like:zylIsAppRunning('notdpad.exe', false);
    An example project for Unicode Inno Setup is provided as download.

    The attachment "CheckAppRunning.zip" is the script.
    Unzip the file CheckAppRunning.zip,
    you can get a file named "CheckAppRunning.iss".
    Please copy the *.iss files to the directory: ./Inno Setup 5/Examples
    Then build the program and run it.
    CheckAppRunning.zip
  9. Like
    Yaliang got a reaction from meoit in [inno setup]Check app(*.exe) is running in Code section   
    There are some ways to do this. Such as using a external DLL.But I do not like this way.
    The Inno surport Pascal script. The Pascal script can call standard Win32 API functions inside standard Windows DLLs. So we can check the app is whether running.
    Here is a part of script in
    section:; Any question, let me know.
    ;It work on 32 and 64 modules!
    [code]
    type HANDLE = LongInt;
    HMODULE = HANDLE;
    pHMODULE = Array[0..255] of HMODULE;
    LPDWORD = DWORD; PDWORD = Array[0..255] of DWORD;
    LPTSTR = String;
    const PROCESS_QUERY_INFORMATION = $400;
    PROCESS_VM_READ = $10;
    MAX_LENGTH = 255;
    function OpenProcess(dwDesiredAccess : DWORD; bInheritHandle : Boolean; dwProcessId : DWORD) : HANDLE;
    external 'OpenProcess@kernel32.dll stdcall delayload';
    function CloseHandle(hObject : HANDLE) : BOOL;
    external 'CloseHandle@kernel32.dll stdcall delayload';
    function EnumProcesses(var pProcessIds : PDWORD; cb : DWORD; var pBytesReturned : DWORD) : BOOL;
    external 'EnumProcesses@psapi.dll stdcall delayload';
    //notice:delayload EnumProcessModules and EnumProcessModulesEx functions
    //64-bit using EnumProcessModulesEx; 32-bite using EnumProcessModules
     
    function EnumProcessModulesEx(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD; dwFilterFlag : DWORD) : BOOL;
    external 'EnumProcessModulesEx@psapi.dll stdcall delayload';function EnumProcessModules(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD) : BOOL;
    external 'EnumProcessModules@psapi.dll stdcall delayload';
    function GetModuleFileNameExW(hProcess : HANDLE; hModule : HMODULE; lpFilename : LPTSTR; nSize : DWORD) : DWORD;
    external 'GetModuleFileNameExW@psapi.dll stdcall delayload';
    //here is the functionfunction
    zylIsAppRunning(procName : String; fullPath : Boolean) : Boolean;
    var found : Boolean;
    filenameEnd : Integer;
    filename : String;
    NA : DWORD;
    entry : DWORD;
    maxEntries : DWORD;
    processes : PDWORD;
    lpFilename : LPTSTR;
    hProcess : HANDLE;
    hMod : pHMODULE;
    isModuleShot: Boolean;
    begin
    SetLength(lpFilename, MAX_LENGTH);
    found := False;
    if (EnumProcesses(processes, SizeOf(processes), maxEntries)) then
    begin
    entry := 0;
    maxEntries := maxEntries / SizeOf(maxEntries);
    while ((not found) and (entry < maxEntries)) do begin
    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processes[entry]);
    if (hProcess <> 0) then
    begin
    isModuleShot := False;
    if IsWin64 then
    begin //EnumProcessModulesEx @param $3,surport 32-bit modules and 64-bit modules the sametiem
    isModuleShot := EnumProcessModulesEx(hProcess, hMod, SizeOf(hMod), NA, $3);
    end else begin
    isModuleShot := EnumProcessModules(hProcess, hMod, SizeOf(hMod), NA);
    end;
    if (isModuleShot) then
    if (GetModuleFileNameExW(hProcess, hMod[0], lpFilename, Length(lpFilename)) > 0)
    then begin
    filenameEnd := Pos(#0, lpFilename);
    filename := Copy(Lowercase(lpFilename), 1, filenameEnd - 1);
    if (not fullpath) then
    filename := ExtractFileName(filename);
    if (AnsiLowercase(filename) = AnsiLowercase(procName)) then
    found := True;
    end;
    CloseHandle(hProcess);
    end;
    entry := entry + 1;
    end;
    end;
    Result := found;
    end;//function end
     
    How to use:
    I wish you have installed the Unicode Inno Setup (the 5.5.x version or more).(If not, you can download it from the home page http://www.jrsoftware.org)
    You can use it where you need just like:zylIsAppRunning('notdpad.exe', false);
    An example project for Unicode Inno Setup is provided as download.

    The attachment "CheckAppRunning.zip" is the script.
    Unzip the file CheckAppRunning.zip,
    you can get a file named "CheckAppRunning.iss".
    Please copy the *.iss files to the directory: ./Inno Setup 5/Examples
    Then build the program and run it.
    CheckAppRunning.zip
  10. Like
    Yaliang got a reaction from HJSC in [inno setup]Check app(*.exe) is running in Code section   
    There are some ways to do this. Such as using a external DLL.But I do not like this way.
    The Inno surport Pascal script. The Pascal script can call standard Win32 API functions inside standard Windows DLLs. So we can check the app is whether running.
    Here is a part of script in
    section:; Any question, let me know.
    ;It work on 32 and 64 modules!
    [code]
    type HANDLE = LongInt;
    HMODULE = HANDLE;
    pHMODULE = Array[0..255] of HMODULE;
    LPDWORD = DWORD; PDWORD = Array[0..255] of DWORD;
    LPTSTR = String;
    const PROCESS_QUERY_INFORMATION = $400;
    PROCESS_VM_READ = $10;
    MAX_LENGTH = 255;
    function OpenProcess(dwDesiredAccess : DWORD; bInheritHandle : Boolean; dwProcessId : DWORD) : HANDLE;
    external 'OpenProcess@kernel32.dll stdcall delayload';
    function CloseHandle(hObject : HANDLE) : BOOL;
    external 'CloseHandle@kernel32.dll stdcall delayload';
    function EnumProcesses(var pProcessIds : PDWORD; cb : DWORD; var pBytesReturned : DWORD) : BOOL;
    external 'EnumProcesses@psapi.dll stdcall delayload';
    //notice:delayload EnumProcessModules and EnumProcessModulesEx functions
    //64-bit using EnumProcessModulesEx; 32-bite using EnumProcessModules
     
    function EnumProcessModulesEx(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD; dwFilterFlag : DWORD) : BOOL;
    external 'EnumProcessModulesEx@psapi.dll stdcall delayload';function EnumProcessModules(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD) : BOOL;
    external 'EnumProcessModules@psapi.dll stdcall delayload';
    function GetModuleFileNameExW(hProcess : HANDLE; hModule : HMODULE; lpFilename : LPTSTR; nSize : DWORD) : DWORD;
    external 'GetModuleFileNameExW@psapi.dll stdcall delayload';
    //here is the functionfunction
    zylIsAppRunning(procName : String; fullPath : Boolean) : Boolean;
    var found : Boolean;
    filenameEnd : Integer;
    filename : String;
    NA : DWORD;
    entry : DWORD;
    maxEntries : DWORD;
    processes : PDWORD;
    lpFilename : LPTSTR;
    hProcess : HANDLE;
    hMod : pHMODULE;
    isModuleShot: Boolean;
    begin
    SetLength(lpFilename, MAX_LENGTH);
    found := False;
    if (EnumProcesses(processes, SizeOf(processes), maxEntries)) then
    begin
    entry := 0;
    maxEntries := maxEntries / SizeOf(maxEntries);
    while ((not found) and (entry < maxEntries)) do begin
    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processes[entry]);
    if (hProcess <> 0) then
    begin
    isModuleShot := False;
    if IsWin64 then
    begin //EnumProcessModulesEx @param $3,surport 32-bit modules and 64-bit modules the sametiem
    isModuleShot := EnumProcessModulesEx(hProcess, hMod, SizeOf(hMod), NA, $3);
    end else begin
    isModuleShot := EnumProcessModules(hProcess, hMod, SizeOf(hMod), NA);
    end;
    if (isModuleShot) then
    if (GetModuleFileNameExW(hProcess, hMod[0], lpFilename, Length(lpFilename)) > 0)
    then begin
    filenameEnd := Pos(#0, lpFilename);
    filename := Copy(Lowercase(lpFilename), 1, filenameEnd - 1);
    if (not fullpath) then
    filename := ExtractFileName(filename);
    if (AnsiLowercase(filename) = AnsiLowercase(procName)) then
    found := True;
    end;
    CloseHandle(hProcess);
    end;
    entry := entry + 1;
    end;
    end;
    Result := found;
    end;//function end
     
    How to use:
    I wish you have installed the Unicode Inno Setup (the 5.5.x version or more).(If not, you can download it from the home page http://www.jrsoftware.org)
    You can use it where you need just like:zylIsAppRunning('notdpad.exe', false);
    An example project for Unicode Inno Setup is provided as download.

    The attachment "CheckAppRunning.zip" is the script.
    Unzip the file CheckAppRunning.zip,
    you can get a file named "CheckAppRunning.iss".
    Please copy the *.iss files to the directory: ./Inno Setup 5/Examples
    Then build the program and run it.
    CheckAppRunning.zip
  11. Like
    Yaliang got a reaction from niTe_RiDeR_Pr0 in [inno setup]Check app(*.exe) is running in Code section   
    There are some ways to do this. Such as using a external DLL.But I do not like this way.
    The Inno surport Pascal script. The Pascal script can call standard Win32 API functions inside standard Windows DLLs. So we can check the app is whether running.
    Here is a part of script in
    section:; Any question, let me know.
    ;It work on 32 and 64 modules!
    [code]
    type HANDLE = LongInt;
    HMODULE = HANDLE;
    pHMODULE = Array[0..255] of HMODULE;
    LPDWORD = DWORD; PDWORD = Array[0..255] of DWORD;
    LPTSTR = String;
    const PROCESS_QUERY_INFORMATION = $400;
    PROCESS_VM_READ = $10;
    MAX_LENGTH = 255;
    function OpenProcess(dwDesiredAccess : DWORD; bInheritHandle : Boolean; dwProcessId : DWORD) : HANDLE;
    external 'OpenProcess@kernel32.dll stdcall delayload';
    function CloseHandle(hObject : HANDLE) : BOOL;
    external 'CloseHandle@kernel32.dll stdcall delayload';
    function EnumProcesses(var pProcessIds : PDWORD; cb : DWORD; var pBytesReturned : DWORD) : BOOL;
    external 'EnumProcesses@psapi.dll stdcall delayload';
    //notice:delayload EnumProcessModules and EnumProcessModulesEx functions
    //64-bit using EnumProcessModulesEx; 32-bite using EnumProcessModules
     
    function EnumProcessModulesEx(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD; dwFilterFlag : DWORD) : BOOL;
    external 'EnumProcessModulesEx@psapi.dll stdcall delayload';function EnumProcessModules(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD) : BOOL;
    external 'EnumProcessModules@psapi.dll stdcall delayload';
    function GetModuleFileNameExW(hProcess : HANDLE; hModule : HMODULE; lpFilename : LPTSTR; nSize : DWORD) : DWORD;
    external 'GetModuleFileNameExW@psapi.dll stdcall delayload';
    //here is the functionfunction
    zylIsAppRunning(procName : String; fullPath : Boolean) : Boolean;
    var found : Boolean;
    filenameEnd : Integer;
    filename : String;
    NA : DWORD;
    entry : DWORD;
    maxEntries : DWORD;
    processes : PDWORD;
    lpFilename : LPTSTR;
    hProcess : HANDLE;
    hMod : pHMODULE;
    isModuleShot: Boolean;
    begin
    SetLength(lpFilename, MAX_LENGTH);
    found := False;
    if (EnumProcesses(processes, SizeOf(processes), maxEntries)) then
    begin
    entry := 0;
    maxEntries := maxEntries / SizeOf(maxEntries);
    while ((not found) and (entry < maxEntries)) do begin
    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processes[entry]);
    if (hProcess <> 0) then
    begin
    isModuleShot := False;
    if IsWin64 then
    begin //EnumProcessModulesEx @param $3,surport 32-bit modules and 64-bit modules the sametiem
    isModuleShot := EnumProcessModulesEx(hProcess, hMod, SizeOf(hMod), NA, $3);
    end else begin
    isModuleShot := EnumProcessModules(hProcess, hMod, SizeOf(hMod), NA);
    end;
    if (isModuleShot) then
    if (GetModuleFileNameExW(hProcess, hMod[0], lpFilename, Length(lpFilename)) > 0)
    then begin
    filenameEnd := Pos(#0, lpFilename);
    filename := Copy(Lowercase(lpFilename), 1, filenameEnd - 1);
    if (not fullpath) then
    filename := ExtractFileName(filename);
    if (AnsiLowercase(filename) = AnsiLowercase(procName)) then
    found := True;
    end;
    CloseHandle(hProcess);
    end;
    entry := entry + 1;
    end;
    end;
    Result := found;
    end;//function end
     
    How to use:
    I wish you have installed the Unicode Inno Setup (the 5.5.x version or more).(If not, you can download it from the home page http://www.jrsoftware.org)
    You can use it where you need just like:zylIsAppRunning('notdpad.exe', false);
    An example project for Unicode Inno Setup is provided as download.

    The attachment "CheckAppRunning.zip" is the script.
    Unzip the file CheckAppRunning.zip,
    you can get a file named "CheckAppRunning.iss".
    Please copy the *.iss files to the directory: ./Inno Setup 5/Examples
    Then build the program and run it.
    CheckAppRunning.zip
  12. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    It is a very good change.
    Regards... ;-)
     
  13. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    It is my pleasure.
    Any question u can post here and we can work it out.
  14. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    I had reuploaded the example as download. 
    The script costed me lot of time. And I try many ways.
    but share with other is happy.
  15. Like
    Yaliang got a reaction from alfreire in [inno setup]Check app(*.exe) is running in Code section   
    There are some ways to do this. Such as using a external DLL.But I do not like this way.
    The Inno surport Pascal script. The Pascal script can call standard Win32 API functions inside standard Windows DLLs. So we can check the app is whether running.
    Here is a part of script in
    section:; Any question, let me know.
    ;It work on 32 and 64 modules!
    [code]
    type HANDLE = LongInt;
    HMODULE = HANDLE;
    pHMODULE = Array[0..255] of HMODULE;
    LPDWORD = DWORD; PDWORD = Array[0..255] of DWORD;
    LPTSTR = String;
    const PROCESS_QUERY_INFORMATION = $400;
    PROCESS_VM_READ = $10;
    MAX_LENGTH = 255;
    function OpenProcess(dwDesiredAccess : DWORD; bInheritHandle : Boolean; dwProcessId : DWORD) : HANDLE;
    external 'OpenProcess@kernel32.dll stdcall delayload';
    function CloseHandle(hObject : HANDLE) : BOOL;
    external 'CloseHandle@kernel32.dll stdcall delayload';
    function EnumProcesses(var pProcessIds : PDWORD; cb : DWORD; var pBytesReturned : DWORD) : BOOL;
    external 'EnumProcesses@psapi.dll stdcall delayload';
    //notice:delayload EnumProcessModules and EnumProcessModulesEx functions
    //64-bit using EnumProcessModulesEx; 32-bite using EnumProcessModules
     
    function EnumProcessModulesEx(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD; dwFilterFlag : DWORD) : BOOL;
    external 'EnumProcessModulesEx@psapi.dll stdcall delayload';function EnumProcessModules(hProcess : HANDLE; var lphModule : pHMODULE; cb : DWORD; var lpcbNeeded : LPDWORD) : BOOL;
    external 'EnumProcessModules@psapi.dll stdcall delayload';
    function GetModuleFileNameExW(hProcess : HANDLE; hModule : HMODULE; lpFilename : LPTSTR; nSize : DWORD) : DWORD;
    external 'GetModuleFileNameExW@psapi.dll stdcall delayload';
    //here is the functionfunction
    zylIsAppRunning(procName : String; fullPath : Boolean) : Boolean;
    var found : Boolean;
    filenameEnd : Integer;
    filename : String;
    NA : DWORD;
    entry : DWORD;
    maxEntries : DWORD;
    processes : PDWORD;
    lpFilename : LPTSTR;
    hProcess : HANDLE;
    hMod : pHMODULE;
    isModuleShot: Boolean;
    begin
    SetLength(lpFilename, MAX_LENGTH);
    found := False;
    if (EnumProcesses(processes, SizeOf(processes), maxEntries)) then
    begin
    entry := 0;
    maxEntries := maxEntries / SizeOf(maxEntries);
    while ((not found) and (entry < maxEntries)) do begin
    hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, processes[entry]);
    if (hProcess <> 0) then
    begin
    isModuleShot := False;
    if IsWin64 then
    begin //EnumProcessModulesEx @param $3,surport 32-bit modules and 64-bit modules the sametiem
    isModuleShot := EnumProcessModulesEx(hProcess, hMod, SizeOf(hMod), NA, $3);
    end else begin
    isModuleShot := EnumProcessModules(hProcess, hMod, SizeOf(hMod), NA);
    end;
    if (isModuleShot) then
    if (GetModuleFileNameExW(hProcess, hMod[0], lpFilename, Length(lpFilename)) > 0)
    then begin
    filenameEnd := Pos(#0, lpFilename);
    filename := Copy(Lowercase(lpFilename), 1, filenameEnd - 1);
    if (not fullpath) then
    filename := ExtractFileName(filename);
    if (AnsiLowercase(filename) = AnsiLowercase(procName)) then
    found := True;
    end;
    CloseHandle(hProcess);
    end;
    entry := entry + 1;
    end;
    end;
    Result := found;
    end;//function end
     
    How to use:
    I wish you have installed the Unicode Inno Setup (the 5.5.x version or more).(If not, you can download it from the home page http://www.jrsoftware.org)
    You can use it where you need just like:zylIsAppRunning('notdpad.exe', false);
    An example project for Unicode Inno Setup is provided as download.

    The attachment "CheckAppRunning.zip" is the script.
    Unzip the file CheckAppRunning.zip,
    you can get a file named "CheckAppRunning.iss".
    Please copy the *.iss files to the directory: ./Inno Setup 5/Examples
    Then build the program and run it.
    CheckAppRunning.zip
  16. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    I think your program is repacked by Inno.
    If you want to automatically pins it onto the taskbar, maybe you just need to modify the function CurPageChanged() ,
    you can remove IsTaskSelected()function,and remove the [task] section.
    like following:
    procedure CurPageChanged(CurPageID: Integer);
    begin
      //When Finished page is shown, call the function
      //You can also call is when the "Finish" button clicked.
      if  CurPageID = wpFinished then  
      begin
      //if IsTaskSelected('pintaskbar') then  //if Selected the [task]
         zylPinAppToTaskbar(ExpandConstant('{app}'), 'MyProg.exe');
      end;
    end;
    Hope can help you.
    Regards... ;-)
  17. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    It is helpful...
    Regards... ;-)
  18. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    Maybe U can see the [uninstallDelete] section in InnoSetup documentation.
    I am trying to find a way in
    section.but not finished.In theory, pin or unpin is the same way.
  19. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    remove the shortcuts form taskbar, I think it need to delete the shorcuts form the special directory.
    C:\Users\Current User\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar.
    (The directory is hide.)
  20. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    I had rewriten the article, and  provided an example in the attachment "pintaskbar.zip".
  21. Like
    Yaliang got a reaction from alfreire in [inno setup] A way to pin a shortcut onto taskbar in code   
    Use COM methods and properties via the COM Automation objects support.
    So I translate a Delphi script to Inno Setup
    section.And it work! 
     
    Here is a part of script in [code] section:
    [code]
    http://www.jrsoftware.org)
    There are someway to pin taskbar depend on one's choice.
    We can add a [task] section in InnoSetup.
    if one do not want to see the "task selected page"(like me ),
    the second way is to create a new CheckBox in Inno [code] section.
    And in the second way one need to control the CheckBox show or hide inprocedure CurPageChanged().
    then call the function like:   zylPinAppToTaskbar('c:\window', 'notepad.exe'); 
     
    An example project for Unicode Inno Setup is provided as download.
    The attachment "pintaskbar.zip" is the script.
    Unzip the file pintaskbar.zip,you can get two files named "PinShortcutOntoTaskbar-task.iss"
    and "PinShortcutOntoTaskbar-checkbox.iss".
    Please copy the *.iss files to the directory:  ./Inno Setup 5/Examples
    Then build the program and run PinTaskbar.exe.
     
    References
    http://blog.csdn.net/ccrun/article/details/6906471
    http://gallery.technet.microsoft.com/ScriptCenter/b66434f1-4b3f-4a94-8dc3-e406eb30b750/
    http://www.codeproject.com/Tips/713824/Pin-a-shortcut-onto-the-Taskbar-or-Start-Menu 
     
    The following is the script of the second way, I think you can modify it to the first way.
    If the attachment was broken, copy the following script to a *.iss file.
     
    ; -- PinShortcutOntoTaskbar.iss --
    ; Pin a shortcut onto taskbar on Win7 & Win8.
    ; @author: Yaliang.Zhao <shuangxiang2008@google.com>
    ; @brief: I test is on 32-bit  Win7 & Win8, but
    ;         I thins it will work on X64 version.
    [setup]
    AppName=PinTaskbar
    AppVersion=1.0
    OutputBaseFilename=PinTaskbar
    DefaultDirName={pf}\PinTaskbar
    OutputDir=./
    DisableStartupPrompt=yes
    DisableReadyPage=yes
    [Files]
    Source: "MyProg.exe"; DestDir: "{app}"
    ;[Tasks]
    ;Name: pintaskbar; Description: "Pin shortcut onto taskbar"
    ;Following is how to use
    [Code]
    var
    PinTaskBarCheck : TNewCheckBox;
    //the function is work well on Unicode Inno Setup,
    //if Non Unicode Inno Setup, one need to modify,
    //and I think you can do it!
    //Inno use Win32 API
    function LoadLibrary(lpFilename : String) : LongInt;
    external 'LoadLibraryW@kernel32.dll stdcall delayload';  //if Non Unicode Inno Setup, use LoadLibraryA
    function FreeLibrary(hModule : LongInt) : BOOL;
    external 'FreeLibrary@kernel32.dll stdcall delayload';
    function LoadString(hInstance:LongInt; uId:UINT; lpBuffer:String; nBufferMax:Integer) : Integer;
    external 'LoadStringW@user32.dll stdcall delayload';  //if Non Unicode Inno Setup, use LoadStringA
    //here is the function
    //@param strPath The App's directory,
    //@param strApp The App's name
    //@example zylPinAppToTaskbar('c:\window', 'notepad.exe');
    procedure zylPinAppToTaskbar(strPath, strApp: string); 
    var 
      vShell, vFolder, vFolderItem, vItemVerbs: Variant; 
      vPath, vApp: Variant; 
      i: Integer; 
      sItem: String;  
      h: LongInt;
      szPinName: String;
      filenameEnd : Integer;
      filename    : String;
      strEnd    : String;
    begin
      SetLength(szPinName, 255);
      h := LoadLibrary(ExpandConstant('{sys}\Shell32.dll')); 
      LoadString(h, 5386, szPinName, 255); 
      FreeLibrary(h); 
      strEnd := #0;
      filenameEnd := Pos(strEnd, szPinName);
      filename := Copy(szPinName, 1, filenameEnd - 1);
      if (Length(filename) > 0) then  //WinXp or lower, no pin taskbar function
      begin
        vShell := CreateOleObject('Shell.Application'); 
        vPath := strPath; 
        vFolder := vShell.NameSpace(vPath); 
        vApp := strApp; 
        vFolderItem := vFolder.ParseName(vApp); 
        vItemVerbs := vFolderItem.Verbs; 
        
      for i := 1 to vItemVerbs.Count do 
      begin 
        sItem := vItemVerbs.Item(i).Name;
        if (sItem = filename) then
        begin
          // 63 63 72 75 6E 2E 63 6F 6D 
          vItemVerbs.Item(i).DoIt;
          break;
         end;
        end; 
      end;
    end; 
    //You can use zylPinAppToTaskbar like this
    procedure CurPageChanged(CurPageID: Integer);
    begin
      //When Finished page is shown, call the function
      //You can also call is when the "Finish" button clicked.
      if CurPageID <> wpWelcome then
        PinTaskBarCheck.hide
      else begin
        PinTaskBarCheck.show;
      end;
      if  CurPageID = wpFinished then 
      begin
      //if IsTaskSelected('pintaskbar') then  //if Selected the [task]
      //   zylPinAppToTaskbar(ExpandConstant('{app}'), 'MyProg.exe');
      if PinTaskBarCheck.Checked then
        zylPinAppToTaskbar(ExpandConstant('{app}'), 'MyProg.exe');
      end;
    end;
    procedure InitializeWizard;
    begin
      PinTaskBarCheck := TNewCheckBox.Create(WizardForm);
       with PinTaskBarCheck do begin
        Parent  := WizardForm;
        Caption := 'Pin it onto taskbar';
        Top     := 200;
        Left    := 200;
        Width   := ScaleY(200);
        Height  := ScaleY(15);
        State   := cbChecked;
        //Hide;
      end;
    end;
    pintaskbar.zip
×
×
  • Create New...