AutoHotkey Community

It is currently May 27th, 2012, 4:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Win 7 issue
PostPosted: July 19th, 2011, 2:20 pm 
Offline

Joined: January 9th, 2009, 12:06 am
Posts: 85
Location: Oklahoma City
I have an interesting issue that seems to only occur on Windows 7 machines. I wrote an application that manages SQL installs for our company, basically it can install, uninstall, reinstall, or upgrade our instance of SQL on XP, NT, 2003, vista, 2008, and Win 7 machines using either MSDE or SQL 2005. It also has some backup and restore options for the database files themselves.

All of that works really well, the issue that I have is that I have the application minimize all windows and kill explorer.exe so that other applications shouldn't interfere with the program and so that the end customer, (that's who this is designed for) is unable to start any other apps or do anything else on the machine until the application is finished because it can cause other issues.

Now on all machines the closing of explorer.exe works great and on all machines but 7, when I call explorer.exe, the shell reloads; however, on Win 7, calling explorer just opens an explorer window, it does not reload the shell and I cannot figure out why.

Does anyone have any experience with this or any ideas on how I could call explorer to reload as a shell properly on Win 7?


Here is the code I use to end explorer.exe:
Code:
   Runwait, %comspec% /c "taskkill /IM explorer.exe /F" ,,Hide ;Closes explorer.exe to prevent conflicts with running applications and stop users from trying to run other things while the utility is running, explorer will be restored automatically once the program is finished
   Runwait, Pskill.exe explorer.exe,,Hide ;Redundant, called a couple of times using an alternative method to make sure that all explorer windows and the shell are closed and antivirus/firewalls didnt't block the previous method
   Runwait, Pskill.exe explorer.exe,,Hide
   ExplorerClosed = 1


I have tried the following for reloading the shell:
Code:
Run, %comspec% /c "%A_homedrive%\alasql\Restart Shell.bat" ,,Hide

Code:
Run, %comspec% /c "%A_windir%\explorer.exe" ,,Hide

Code:
Run, %comspec% /c "Start explorer" ,,Hide


The code for the above bat file:
Code:
@echo OFF
CLS
PING 127.0.0.1 -n 8 >NUL
taskkill /f /im explorer.exe
start explorer.exe


Any help is appreciated

_________________
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2011, 5:10 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Something like the below works for me using Windows 7 Pro (32-bit). No comspec, pkill or taskkill required in my case :)

Code:
MsgBox, Please wait while blablabla is installed.  To allow installation to take place, please press "YES" if Windows promts you for confirmation that this program should be allowed to run.

if not A_IsAdmin ; need to be running as admin.
{
   DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
      , str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
   ExitApp
}

OldRestartShellVal := ""
OnExit, ExitSub ; clean up on exit.

; read the current system setting for AutoRestartShell so we can restore it correctly afterwards.
RegRead, OldRestartShellVal, HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, AutoRestartShell
if ( ErrorLevel )
{
   MsgBox, couldn't read old AutoRestartShell value!  Defaulting to TRUE
   OldRestartShellVal := 1
}

if ( OldRestartShellVal != 0 ) ; if it is set to Auto Restart the shell, then disable this temporarily
{
   RegWrite, REG_DWORD, HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, AutoRestartShell, 0 ; set to FALSE temporarily
   if ( ErrorLevel )
   {
      MsgBox, Could not write new registry entry!  Check permissions...
      ExitApp ; will automatically restore old setting via the OnExit routine
   }
}

Process, close, explorer.exe ; try to get rid of explorer.exe
while ( ErrorLevel )
{
   ToolTip, Attempt %A_Index% to close explorer.exe
   Sleep, 100
   Process, close, explorer.exe ; try again to get rid of explorer.exe
}
   ToolTip, ; get rid of the tooltip
   MsgBox, explorer closed and should NOT have restarted.  Do some stuff here
   
   ; #############
   ; do whatever here that you needed explorer closed for
   ; ############
   
   ExitApp ; optionally, you can call ExitApp here if you are done and you want the shell/registry to be restored.

Return
   
Esc::ExitApp ; press escape to exit

ExitSub:
   OnExit, ; clear this
   if OldRestartShellVal is integer ; make sure we are writing a valid value
      RegWrite, REG_DWORD, HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, AutoRestartShell, %OldRestartShellVal%
     
      ; now restore the shell
   Run, %A_windir%\explorer.exe
   MsgBox, Explorer restarted.  Hopefully the shell too?

   ExitApp

_________________
My code is written for AHK Basic unless otherwise specified. This means it may not work in AHK_L (especially Unicode), due to a few known compatibility issues.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Looks good
PostPosted: July 19th, 2011, 7:31 pm 
Offline

Joined: January 9th, 2009, 12:06 am
Posts: 85
Location: Oklahoma City
The code looks good, I do have one question for you, are you running with UAC on or off? I realized after reading your post that I neglected to mention that this is primarily with UAC ON. Unfortunetly because of the app running on customer systems, turning UAC off is not an option.

_________________
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2011, 12:16 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
UAC is on. That is why I put a msgbox up telling the user to answer YES to the UAC prompt if they are shown it.

If AHK determines that the current script is not running as an Admin, it will restart and ask for elevated privileges, which will of course cause the UAC prompt.

I do have the permission to "Run as Administrator" on my test machine, not sure if this possible for you? I think this is probably required for what you are doing anyway, so I'm sure you will be fine with this.

HTH.

_________________
My code is written for AHK Basic unless otherwise specified. This means it may not work in AHK_L (especially Unicode), due to a few known compatibility issues.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], rbrtryn, Yahoo [Bot] and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group