Prev: Using a typelib
Next: Shell ???
From: Francois Houde on 27 May 2010 17:43 Hi all, I have the following code that works great on my computer. But when we are putting the same exact code on a Citrix server the following command doesn't work : Set SW = New ShellWindows Err.Number = -2147024894 Err.Description = unable to find the specified file. Any idea on what could be the problem and a way to correct it ? Also please note that it should work in Visual basic for application (VBA) Thanks in advance Francois Houde Sub CreateIE() Dim sNull As String Dim lSuccess As Long Dim lRetValue As Long Dim lngExit As Long sInfo.dwFlags = STARTF_USESHOWWINDOW sInfo.wShowWindow = SW_HIDE sInfo.cb = Len(sInfo) lSuccess = CreateProcess(sNull, "C:\Program Files\Internet Explorer\iexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo) Dim web As InternetExplorer Dim SW As ShellWindows Dim ie As Object Dim ret As Long Dim lProcID As Long Set SW = New ShellWindows For Each web In SW ret = GetWindowThreadProcessId(ie.hwnd, lProcID) If lProcID = pInfo.dwProcessId Then Set web = ie Exit for End If Next web.Navigate "some url", vFlags, vTarget, vPost, vHeaders Set web = Nothing ProcessTerminate pInfo.dwProcessId end sub Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow As Long) As Boolean Dim lhwndProcess As Long Dim lExitCode As Long Dim lRetVal As Long Dim lhThisProc As Long Dim lhTokenHandle As Long Dim tLuid As LUID Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES Dim lBufferNeeded As Long Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" Const SE_PRIVILEGE_ENABLED = &H2 On Error Resume Next If lHwndWindow Then 'Get the process ID from the window handle lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) End If If lProcessID Then 'Give Kill permissions to this process lhThisProc = GetCurrentProcess OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, lhTokenHandle LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid 'Set the number of privileges to be change tTokenPriv.PrivilegeCount = 1 tTokenPriv.TheLuid = tLuid tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED 'Enable the kill privilege in the access token of this process AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded 'Open the process to kill lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) If lhwndProcess Then 'Obtained process handle, kill the process ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) CloseHandle lhwndProcess End If End If On Error GoTo 0 End Function
From: mscir on 28 May 2010 04:56 On 5/27/2010 2:43 PM, Francois Houde wrote: > > Hi all, I have the following code that works great on my computer. But when > we are putting the same exact code on a Citrix server the following command > doesn't work : > > Set SW = New ShellWindows > > Err.Number = -2147024894 > Err.Description = unable to find the specified file. > > Any idea on what could be the problem and a way to correct it ? Also please > note that it should work in Visual basic for application (VBA) > > Thanks in advance > > Francois Houde > > > Sub CreateIE() > Dim sNull As String > Dim lSuccess As Long > Dim lRetValue As Long > Dim lngExit As Long > > sInfo.dwFlags = STARTF_USESHOWWINDOW > sInfo.wShowWindow = SW_HIDE > sInfo.cb = Len(sInfo) > > lSuccess = CreateProcess(sNull, "C:\Program Files\Internet > Explorer\iexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal > 0&, sNull, sInfo, pInfo) > > Dim web As InternetExplorer > Dim SW As ShellWindows > Dim ie As Object > Dim ret As Long > Dim lProcID As Long > > Set SW = New ShellWindows > > For Each web In SW > ret = GetWindowThreadProcessId(ie.hwnd, lProcID) > If lProcID = pInfo.dwProcessId Then > Set web = ie > Exit for > End If > Next > > web.Navigate "some url", vFlags, vTarget, vPost, vHeaders > > Set web = Nothing > > ProcessTerminate pInfo.dwProcessId > end sub > > Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow > As Long) As Boolean > Dim lhwndProcess As Long > Dim lExitCode As Long > Dim lRetVal As Long > Dim lhThisProc As Long > Dim lhTokenHandle As Long > Dim tLuid As LUID > Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES > Dim lBufferNeeded As Long > > Const PROCESS_ALL_ACCESS =&H1F0FFF, PROCESS_TERMINATE =&H1 > Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES =&H20 > Const TOKEN_QUERY =&H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" > Const SE_PRIVILEGE_ENABLED =&H2 > > On Error Resume Next > If lHwndWindow Then > 'Get the process ID from the window handle > lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) > End If > > If lProcessID Then > 'Give Kill permissions to this process > lhThisProc = GetCurrentProcess > > OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, > lhTokenHandle > LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid > 'Set the number of privileges to be change > tTokenPriv.PrivilegeCount = 1 > tTokenPriv.TheLuid = tLuid > tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED > 'Enable the kill privilege in the access token of this process > AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, > Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded > > 'Open the process to kill > lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) > > If lhwndProcess Then > 'Obtained process handle, kill the process > ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) > CloseHandle lhwndProcess > End If > End If > On Error GoTo 0 > End Function Do you have a copy of shdocvw.dll installed on the server? Will this help? http://www.thinworld.net/blog/2010/02/appsense-memory-optmization-servicesmsc.html --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Nobody on 28 May 2010 00:15 "Francois Houde" <FrancoisHoude(a)discussions.microsoft.com> wrote in message news:B070A5B7-F844-4FF3-97B4-B0C91C5EF436(a)microsoft.com... > Hi all, I have the following code that works great on my computer. But > when > we are putting the same exact code on a Citrix server the following > command > doesn't work : > > Set SW = New ShellWindows > > Err.Number = -2147024894 > Err.Description = unable to find the specified file. > > Any idea on what could be the problem and a way to correct it ? Also > please > note that it should work in Visual basic for application (VBA) > > Thanks in advance > > Francois Houde > > > Sub CreateIE() > Dim sNull As String > Dim lSuccess As Long > Dim lRetValue As Long > Dim lngExit As Long > > sInfo.dwFlags = STARTF_USESHOWWINDOW > sInfo.wShowWindow = SW_HIDE > sInfo.cb = Len(sInfo) > > lSuccess = CreateProcess(sNull, "C:\Program Files\Internet > Explorer\iexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, > ByVal > 0&, sNull, sInfo, pInfo) One undocumented change that it seems to be in Vista+ is that when you don't add double quotes to the command line in CreateProcess(), the OS doesn't guess anymore where the file name ends and the arguments begins when the path contains spaces, so always include the double quotes themselves in the command line, so in the above line, change the string to: Chr(34) & "C:\Program Files\Internet Explorer\iexplore.exe" & Chr(34) Or: """C:\Program Files\Internet Explorer\iexplore.exe"""
From: Mayayana on 28 May 2010 00:49 Maybe I'm missing something, but I don't get your code. You're referencing ie.hWnd, yet you haven't assigned anything to the ie variable. And why would you go through all of those steps to create an IE instance and then track it down? Why not just use: Dim web as InternetExplorer Set web = New InternetExplorer web.Navigate "some url", vFlags, vTarget, vPost, vHeaders web.quit Set web = Nothing For that matter, why do you navigate to a URL and then quit IE before the page is even loaded? That may not address the problem on Citrix, but as far as I can see your code doesn't make sense in the first place. | Hi all, I have the following code that works great on my computer. But when | we are putting the same exact code on a Citrix server the following command | doesn't work : | | Set SW = New ShellWindows | | Err.Number = -2147024894 | Err.Description = unable to find the specified file. | | Any idea on what could be the problem and a way to correct it ? Also please | note that it should work in Visual basic for application (VBA) | | Thanks in advance | | Francois Houde | | | Sub CreateIE() | Dim sNull As String | Dim lSuccess As Long | Dim lRetValue As Long | Dim lngExit As Long | | sInfo.dwFlags = STARTF_USESHOWWINDOW | sInfo.wShowWindow = SW_HIDE | sInfo.cb = Len(sInfo) | | lSuccess = CreateProcess(sNull, "C:\Program Files\Internet | Explorer\iexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal | 0&, sNull, sInfo, pInfo) | | Dim web As InternetExplorer | Dim SW As ShellWindows | Dim ie As Object | Dim ret As Long | Dim lProcID As Long | | Set SW = New ShellWindows | | For Each web In SW | ret = GetWindowThreadProcessId(ie.hwnd, lProcID) | If lProcID = pInfo.dwProcessId Then | Set web = ie | Exit for | End If | Next | | web.Navigate "some url", vFlags, vTarget, vPost, vHeaders | | Set web = Nothing | | ProcessTerminate pInfo.dwProcessId | end sub | | Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow | As Long) As Boolean | Dim lhwndProcess As Long | Dim lExitCode As Long | Dim lRetVal As Long | Dim lhThisProc As Long | Dim lhTokenHandle As Long | Dim tLuid As LUID | Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES | Dim lBufferNeeded As Long | | Const PROCESS_ALL_ACCESS = &H1F0FFF, PROCESS_TERMINATE = &H1 | Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES = &H20 | Const TOKEN_QUERY = &H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" | Const SE_PRIVILEGE_ENABLED = &H2 | | On Error Resume Next | If lHwndWindow Then | 'Get the process ID from the window handle | lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) | End If | | If lProcessID Then | 'Give Kill permissions to this process | lhThisProc = GetCurrentProcess | | OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, | lhTokenHandle | LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid | 'Set the number of privileges to be change | tTokenPriv.PrivilegeCount = 1 | tTokenPriv.TheLuid = tLuid | tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED | 'Enable the kill privilege in the access token of this process | AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, | Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded | | 'Open the process to kill | lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) | | If lhwndProcess Then | 'Obtained process handle, kill the process | ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) | CloseHandle lhwndProcess | End If | End If | On Error GoTo 0 | End Function
From: Francois Houde on 28 May 2010 10:09
I will check with our Citrix admin if it is installed. "mscir" wrote: > On 5/27/2010 2:43 PM, Francois Houde wrote: > > > > Hi all, I have the following code that works great on my computer. But when > > we are putting the same exact code on a Citrix server the following command > > doesn't work : > > > > Set SW = New ShellWindows > > > > Err.Number = -2147024894 > > Err.Description = unable to find the specified file. > > > > Any idea on what could be the problem and a way to correct it ? Also please > > note that it should work in Visual basic for application (VBA) > > > > Thanks in advance > > > > Francois Houde > > > > > > Sub CreateIE() > > Dim sNull As String > > Dim lSuccess As Long > > Dim lRetValue As Long > > Dim lngExit As Long > > > > sInfo.dwFlags = STARTF_USESHOWWINDOW > > sInfo.wShowWindow = SW_HIDE > > sInfo.cb = Len(sInfo) > > > > lSuccess = CreateProcess(sNull, "C:\Program Files\Internet > > Explorer\iexplore.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal > > 0&, sNull, sInfo, pInfo) > > > > Dim web As InternetExplorer > > Dim SW As ShellWindows > > Dim ie As Object > > Dim ret As Long > > Dim lProcID As Long > > > > Set SW = New ShellWindows > > > > For Each web In SW > > ret = GetWindowThreadProcessId(ie.hwnd, lProcID) > > If lProcID = pInfo.dwProcessId Then > > Set web = ie > > Exit for > > End If > > Next > > > > web.Navigate "some url", vFlags, vTarget, vPost, vHeaders > > > > Set web = Nothing > > > > ProcessTerminate pInfo.dwProcessId > > end sub > > > > Function ProcessTerminate(Optional lProcessID As Long, Optional lHwndWindow > > As Long) As Boolean > > Dim lhwndProcess As Long > > Dim lExitCode As Long > > Dim lRetVal As Long > > Dim lhThisProc As Long > > Dim lhTokenHandle As Long > > Dim tLuid As LUID > > Dim tTokenPriv As TOKEN_PRIVILEGES, tTokenPrivNew As TOKEN_PRIVILEGES > > Dim lBufferNeeded As Long > > > > Const PROCESS_ALL_ACCESS =&H1F0FFF, PROCESS_TERMINATE =&H1 > > Const ANYSIZE_ARRAY = 1, TOKEN_ADJUST_PRIVILEGES =&H20 > > Const TOKEN_QUERY =&H8, SE_DEBUG_NAME As String = "SeDebugPrivilege" > > Const SE_PRIVILEGE_ENABLED =&H2 > > > > On Error Resume Next > > If lHwndWindow Then > > 'Get the process ID from the window handle > > lRetVal = GetWindowThreadProcessId(lHwndWindow, lProcessID) > > End If > > > > If lProcessID Then > > 'Give Kill permissions to this process > > lhThisProc = GetCurrentProcess > > > > OpenProcessToken lhThisProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, > > lhTokenHandle > > LookupPrivilegeValue "", SE_DEBUG_NAME, tLuid > > 'Set the number of privileges to be change > > tTokenPriv.PrivilegeCount = 1 > > tTokenPriv.TheLuid = tLuid > > tTokenPriv.Attributes = SE_PRIVILEGE_ENABLED > > 'Enable the kill privilege in the access token of this process > > AdjustTokenPrivileges lhTokenHandle, False, tTokenPriv, > > Len(tTokenPrivNew), tTokenPrivNew, lBufferNeeded > > > > 'Open the process to kill > > lhwndProcess = OpenProcess(PROCESS_TERMINATE, 0, lProcessID) > > > > If lhwndProcess Then > > 'Obtained process handle, kill the process > > ProcessTerminate = CBool(TerminateProcess(lhwndProcess, lExitCode)) > > CloseHandle lhwndProcess > > End If > > End If > > On Error GoTo 0 > > End Function > > Do you have a copy of shdocvw.dll installed on the server? > > Will this help? > http://www.thinworld.net/blog/2010/02/appsense-memory-optmization-servicesmsc.html > > > --- news://freenews.netfront.net/ - complaints: news(a)netfront.net --- > . > |