none
Can't run StikyNot.exe from Excel Macro RRS feed

  • Question

  • OS is Windows 7 Home Premium.  Application is Excel 2007.
    On my PC the program I'm trying to run from the macro is named StikyNot.exe, and yes, the spelling is correct.  It's in the Windows\System32 folder.  When I enter this name in Run..., or double click the file, it runs fine.  Strange thing, though.  When I try to run it from a macro in Excel, using the Shell function, I get "File Not Found."  Any other exe I run from the same folder in the same macro runs just fine (eg notepad.exe).  Has Microsoft disabled the StikyNot.exe file from being called from a program?  Any thoughts or info would be appreciated.
    Also, assuming I can run the program, how do I send a text string (to be displayed on the Sticky Note) as an argument?
    Saturday, February 27, 2010 1:58 AM

Answers

  • Hello,

    I could figure this out, the code goes like this:

     Sub RunYourProgram()
       
          Dim RetVal As Long
          On Error Resume Next
          Dim tmp As Long
         
        RetVal = Wow64DisableWow64FsRedirection(tmp)
       
        RetVal = ShellExecute(0, "open", "stikynot", "", _
                                "", SW_SHOWMAXIMIZED)
         Wow64EnableWow64FsRedirection (True)
      
        End Sub

    The reason why we could not call stikynot is that  Office 2007 is a 32-bit application and stikynot is a 64 bit application, if we directly call it the request to system32 will be redirected to folder Wow64, thus, the call fails.

    In order to call this 64-bit application without redirect, we need to temporarily turn off the redirect, we need a API Wow64DisableWow64FsRedirection(http://msdn.microsoft.com/en-us/library/aa365743%28VS.85%29.aspx), and a API to restore this Wow64EnableWow64FsRedirection(http://msdn.microsoft.com/en-us/library/aa365744%28VS.85%29.aspx)

    Also we need to consider if this a 64-bit process, beacuse if we run this script in 64-bit process it is not necessary to disable the folder redirection.
    The API for this is :
    IsWow64Process
    http://msdn.microsoft.com/en-us/library/ms684139%28VS.85%29.aspx

    Thanks.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Proposed as answer by Shasur Thursday, March 4, 2010 10:43 AM
    • Marked as answer by Tim Li Friday, March 5, 2010 10:29 AM
    Thursday, March 4, 2010 10:25 AM
  • Hi,

    We could call the Windows APIs by declare them in out VBA code in a special form like this:

    Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
    Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
    Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
    Private Declare Function IsWow64Process Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean

    Thanks.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 5, 2010 1:58 AM

All replies

  • Post your VBA code
    Saturday, February 27, 2010 10:59 PM
  • Good idea.  Thanks.

    Sub RunSN

        Dim RetVal As Double
        
        'This works
        RetVal = Shell("notepad.exe")

        'So does this
        RetVal = Shell("C:\Windows\System32\notepad.exe")

        'But neither of these do
        RetVal = Shell("stikynot.exe")
        RetVal = Shell("C:\Windows\System32\stikynot.exe")

    End Sub

    Again, the spelling is correct.

    What I'd really like to do is instantiate a Sticky Notes object and set its properties, but I doubt I could do that, even with valid code, if I can't do it with the Shell() function.
    Sunday, February 28, 2010 12:13 AM
  • I don't have Windows7 so I can't test it.  If you open a command window and type in stikynot.exe does it work.  If it does then you try

    RetVal = Shell("cmd stikynot.exe")

    Again, I am guessing on this.
    Monday, March 1, 2010 5:23 PM
  • Hello mogulman52,

    I have found this won't work if the Windows 7 is 64 bit and if the Win 7 is 32 bit it works pretty good. I have tried to use a windows api to start this program but also fails , here's the code so far:

     Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" _
        (ByVal hwnd As Long, _
           ByVal lpOperation As String, _
           ByVal lpFile As String, _
           ByVal lpParameters As String, _
           ByVal lpDirectory As String, _
           ByVal nShowCmd As Long) As Long

     


        Const SW_SHOW = 1
        Const SW_SHOWMAXIMIZED = 3

        Sub RunYourProgram()
          Dim RetVal As Long
          On Error Resume Next
          RetVal = ShellExecute(0, "open", "notepad", "", _
                                "", SW_SHOWMAXIMIZED)
        End Sub

    Thanks.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, March 3, 2010 11:10 AM
  • Hello,

    I could figure this out, the code goes like this:

     Sub RunYourProgram()
       
          Dim RetVal As Long
          On Error Resume Next
          Dim tmp As Long
         
        RetVal = Wow64DisableWow64FsRedirection(tmp)
       
        RetVal = ShellExecute(0, "open", "stikynot", "", _
                                "", SW_SHOWMAXIMIZED)
         Wow64EnableWow64FsRedirection (True)
      
        End Sub

    The reason why we could not call stikynot is that  Office 2007 is a 32-bit application and stikynot is a 64 bit application, if we directly call it the request to system32 will be redirected to folder Wow64, thus, the call fails.

    In order to call this 64-bit application without redirect, we need to temporarily turn off the redirect, we need a API Wow64DisableWow64FsRedirection(http://msdn.microsoft.com/en-us/library/aa365743%28VS.85%29.aspx), and a API to restore this Wow64EnableWow64FsRedirection(http://msdn.microsoft.com/en-us/library/aa365744%28VS.85%29.aspx)

    Also we need to consider if this a 64-bit process, beacuse if we run this script in 64-bit process it is not necessary to disable the folder redirection.
    The API for this is :
    IsWow64Process
    http://msdn.microsoft.com/en-us/library/ms684139%28VS.85%29.aspx

    Thanks.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Proposed as answer by Shasur Thursday, March 4, 2010 10:43 AM
    • Marked as answer by Tim Li Friday, March 5, 2010 10:29 AM
    Thursday, March 4, 2010 10:25 AM
  • Tim,
    I'm not sure how to implement this.  The functions referred to are in C++, and I'm writing VBA code.  Also, as I mentioned, I'd like to send the text I want to display on the Sticky Note as an argument.  Is there a way that I can do this? 

    Mogulman52,
    Just FYI, the code you proposed opens the command prompt.

    Thanks to all for your ongoing help.


    Thursday, March 4, 2010 3:48 PM
  • Hi,

    We could call the Windows APIs by declare them in out VBA code in a special form like this:

    Private Declare Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
    Private Declare Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByVal OldValue As Long) As Boolean
    Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean
    Private Declare Function IsWow64Process Lib "kernel32.dll" (ByVal IsEnable As Boolean) As Boolean

    Thanks.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, March 5, 2010 1:58 AM
  • Just use

    Shell ("C:\Windows\SysNative\StikyNot.exe")

    Instead of

    Shell ("StikyNot.exe")


    • Edited by Brent_M_ Thursday, October 4, 2018 7:45 PM
    Thursday, October 4, 2018 7:45 PM