jackylee0908 Posted April 27, 2023 Posted April 27, 2023 (edited) Hi sir, I'm writing a script for test purpose, I need the script to install Intel imb driver if the driver file does not exist, but if it does exist, then the script will ignore the driver installation to prevent the OS BSOD, so I just write below code to the script. If Not FileExists("C:\Windows\System32\drivers\imbdrv.sys") Then GUICtrlSetData($msgbox, "Installing imb driver, please wait......") RunWait(@ComSpec & " /c" & "C:\host\install_imbdrv.bat", @WorkingDir, @SW_HIDE) Else GUICtrlSetData($msgbox, "Intel imb driver has already been installed, skip the driver installation.") EndIf But when I run the script, the script also present the message "Installing imb driver, please wait......" and start to install the driver, even the driver file 'C:\Windows\System32\drivers\imbdrv.sys' is still there, and this would cause the system BSOD during the driver installation, since the driver is existed, and that's why I need the script to check the driver is existed or not, but seems it does not work for me. I have also tried to use 'run as administrator' to run the script but it still is failed. Please guide me if anything is wrong or any other way can do it, thank you. Edited April 27, 2023 by jackylee0908
Solution jackylee0908 Posted April 27, 2023 Author Solution Posted April 27, 2023 Just searched from this forum and understand that since my script is compiled with x86 so it does not work, if I compile it as x64 then it does work for me.
mistersquirrle Posted April 27, 2023 Posted April 27, 2023 And have you confirmed that the file does exist at that specific path? It might be better to use @SystemDir macro instead of hardcoding "C:\Windows\System32". Otherwise it's hard to say, it could certainly be some issue with 32-bit vs 64-bit. I do not have this driver installed, so I can't check it specifically, but I picked the first file in that folder, and it works just fine for me: ConsoleWrite(@SystemDir & @CRLF) ConsoleWrite('Full: ' & FileExists("C:\Windows\System32\drivers\1394ohci.sys") & @CRLF) ConsoleWrite('Macro: ' & FileExists(@SystemDir & "\drivers\1394ohci.sys") & @CRLF) If Not FileExists(@SystemDir & "\drivers\imbdrv.sys") Then ConsoleWrite('Driver does NOT exist' & @CRLF) EndIf Output: C:\WINDOWS\system32 Full: 1 Macro: 1 Driver does NOT exist So it works just fine for me, I'd confirm that you have the correct path. We ought not to misbehave, but we should look as though we could.
jackylee0908 Posted April 27, 2023 Author Posted April 27, 2023 3 minutes ago, mistersquirrle said: And have you confirmed that the file does exist at that specific path? It might be better to use @SystemDir macro instead of hardcoding "C:\Windows\System32". Otherwise it's hard to say, it could certainly be some issue with 32-bit vs 64-bit. I do not have this driver installed, so I can't check it specifically, but I picked the first file in that folder, and it works just fine for me: ConsoleWrite(@SystemDir & @CRLF) ConsoleWrite('Full: ' & FileExists("C:\Windows\System32\drivers\1394ohci.sys") & @CRLF) ConsoleWrite('Macro: ' & FileExists(@SystemDir & "\drivers\1394ohci.sys") & @CRLF) If Not FileExists(@SystemDir & "\drivers\imbdrv.sys") Then ConsoleWrite('Driver does NOT exist' & @CRLF) EndIf Output: C:\WINDOWS\system32 Full: 1 Macro: 1 Driver does NOT exist So it works just fine for me, I'd confirm that you have the correct path. Thank you for your reply, I found that it was caused by my test script is with x86 architecture, when I re-compile to x64 then it does work for me.
mistersquirrle Posted April 27, 2023 Posted April 27, 2023 I still recommend that you use the @SystemDir macro, instead of compiling as x64. When I use the @SystemDir macro as x64, it gives: C:\WINDOWS\system32 When I run as x86/32bit it gives: C:\WINDOWS\SysWOW64 If the macro works, then this will make your script more universal/compatible than just compiling as x64. We ought not to misbehave, but we should look as though we could.
jackylee0908 Posted April 27, 2023 Author Posted April 27, 2023 (edited) 1 hour ago, mistersquirrle said: I still recommend that you use the @SystemDir macro, instead of compiling as x64. When I use the @SystemDir macro as x64, it gives: C:\WINDOWS\system32 When I run as x86/32bit it gives: C:\WINDOWS\SysWOW64 If the macro works, then this will make your script more universal/compatible than just compiling as x64. Yep you are right, thanks for your comment, I will think about this, very appreciated! I just tried it on my laptop with Windows 11 Pro 64bit, but when I execute below command, it output with C:\Windows\SysWOW64, why it is not the C:\Windows\System32? _WinAPI_Wow64EnableWow64FsRedirection(False) ConsoleWrite(@SystemDir & @CRLF) If Not FileExists(@SystemDir & "\drivers\1394ohci.sys") Then ConsoleWrite('Driver does NOT exist' & @CRLF) Else ConsoleWrite('Driver does exist' & @CRLF) EndIf Output C:\WINDOWS\SysWOW64 Driver does NOT exist And, if I change the code to below: _WinAPI_Wow64EnableWow64FsRedirection(False) ConsoleWrite(@SystemDir & @CRLF) If Not FileExists("C:\Windows\System32\drivers\1394ohci.sys") Then ConsoleWrite('Driver does NOT exist' & @CRLF) Else ConsoleWrite('Driver does exist' & @CRLF) EndIf It also does not work. C:\WINDOWS\SysWOW64 Driver does exist But if I change to below code: _WinAPI_Wow64EnableWow64FsRedirection(False) ; ConsoleWrite(@SystemDir & @CRLF) If Not FileExists("C:\Windows\System32\drivers\1394ohci.sys") Then ConsoleWrite('Driver does NOT exist' & @CRLF) Else ConsoleWrite('Driver does exist' & @CRLF) EndIf Then I can get workable output. Driver does exist Edited April 27, 2023 by jackylee0908
mistersquirrle Posted April 27, 2023 Posted April 27, 2023 I'm not very familiar with _WinAPI_Wow64EnableWow64FsRedirection and its related outcome/purpose, and I don't have a x86 system to test on. However, it may just be that you need to check both directories for the driver. Something like this, maybe? expandcollapse popupGlobal $sSystemDir, $sFullDriverPath = '' Global $sDriverPath = '\drivers\1394ohci.sys' Global $aRet ConsoleWrite('Running ' & (@AutoItX64 ? 'x64' : 'x86') & @CRLF) For $i = 0 To 1 ConsoleWrite('Setting Wow64EnableWow64FsRedirection = ' & $i & @CRLF) _WinAPI_Wow64EnableWow64FsRedirection($i) ; https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya $aRet = DllCall('kernel32.dll', 'int', 'GetSystemDirectoryA', 'str', '', 'int', 260) If Not @error Then ConsoleWrite('GetSystemDirectoryA: ' & $aRet[1] & @CRLF) $sSystemDir = $aRet[1] EndIf #Region Test calls ;~ $aRet = DllCall('kernel32.dll', 'int', 'GetSystemWindowsDirectoryA', 'str', '', 'int', 260) ;~ If Not @error Then ;~ ConsoleWrite('GetSystemWindowsDirectoryA: ' & $aRet[1] & @CRLF) ;~ EndIf ;~ $aRet = DllCall('kernel32.dll', 'int', 'GetWindowsDirectoryA', 'str', '', 'int', 260) ;~ If Not @error Then ;~ ConsoleWrite('GetWindowsDirectoryA: ' & $aRet[1] & @CRLF) ;~ EndIf #EndRegion ConsoleWrite('$sSystemDir: ' & $sSystemDir & @CRLF) ConsoleWrite('@SystemDir: ' & @SystemDir & @CRLF) Select Case FileExists($sSystemDir & $sDriverPath) ConsoleWrite('Found with $sSystemDir' & @CRLF) $sFullDriverPath = $sSystemDir & $sDriverPath Case FileExists(@SystemDir & $sDriverPath) ConsoleWrite('Found with @SystemDir' & @CRLF) $sFullDriverPath = @SystemDir & $sDriverPath Case Else ConsoleWrite('Not found' & @CRLF) $sFullDriverPath = '' EndSelect If $sFullDriverPath <> '' Then ConsoleWrite('Driver found, full path: ' & $sFullDriverPath & @CRLF) ExitLoop EndIf Next And the output when running as x86 (on a x64 system): Running x86 Setting Wow64EnableWow64FsRedirection = 0 GetSystemDirectoryA: C:\WINDOWS\system32 $sSystemDir: C:\WINDOWS\system32 @SystemDir: C:\WINDOWS\SysWOW64 Found with $sSystemDir Driver found, full path: C:\WINDOWS\system32\drivers\1394ohci.sys You could also likely get away with not using the Macro or DllCall to GetSystemDirectoryA, however using them again just makes things a bit more 'stable' incase the system has some weird/non-standard setup. We ought not to misbehave, but we should look as though we could.
jackylee0908 Posted April 27, 2023 Author Posted April 27, 2023 5 hours ago, mistersquirrle said: I'm not very familiar with _WinAPI_Wow64EnableWow64FsRedirection and its related outcome/purpose, and I don't have a x86 system to test on. However, it may just be that you need to check both directories for the driver. Something like this, maybe? expandcollapse popupGlobal $sSystemDir, $sFullDriverPath = '' Global $sDriverPath = '\drivers\1394ohci.sys' Global $aRet ConsoleWrite('Running ' & (@AutoItX64 ? 'x64' : 'x86') & @CRLF) For $i = 0 To 1 ConsoleWrite('Setting Wow64EnableWow64FsRedirection = ' & $i & @CRLF) _WinAPI_Wow64EnableWow64FsRedirection($i) ; https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya $aRet = DllCall('kernel32.dll', 'int', 'GetSystemDirectoryA', 'str', '', 'int', 260) If Not @error Then ConsoleWrite('GetSystemDirectoryA: ' & $aRet[1] & @CRLF) $sSystemDir = $aRet[1] EndIf #Region Test calls ;~ $aRet = DllCall('kernel32.dll', 'int', 'GetSystemWindowsDirectoryA', 'str', '', 'int', 260) ;~ If Not @error Then ;~ ConsoleWrite('GetSystemWindowsDirectoryA: ' & $aRet[1] & @CRLF) ;~ EndIf ;~ $aRet = DllCall('kernel32.dll', 'int', 'GetWindowsDirectoryA', 'str', '', 'int', 260) ;~ If Not @error Then ;~ ConsoleWrite('GetWindowsDirectoryA: ' & $aRet[1] & @CRLF) ;~ EndIf #EndRegion ConsoleWrite('$sSystemDir: ' & $sSystemDir & @CRLF) ConsoleWrite('@SystemDir: ' & @SystemDir & @CRLF) Select Case FileExists($sSystemDir & $sDriverPath) ConsoleWrite('Found with $sSystemDir' & @CRLF) $sFullDriverPath = $sSystemDir & $sDriverPath Case FileExists(@SystemDir & $sDriverPath) ConsoleWrite('Found with @SystemDir' & @CRLF) $sFullDriverPath = @SystemDir & $sDriverPath Case Else ConsoleWrite('Not found' & @CRLF) $sFullDriverPath = '' EndSelect If $sFullDriverPath <> '' Then ConsoleWrite('Driver found, full path: ' & $sFullDriverPath & @CRLF) ExitLoop EndIf Next And the output when running as x86 (on a x64 system): Running x86 Setting Wow64EnableWow64FsRedirection = 0 GetSystemDirectoryA: C:\WINDOWS\system32 $sSystemDir: C:\WINDOWS\system32 @SystemDir: C:\WINDOWS\SysWOW64 Found with $sSystemDir Driver found, full path: C:\WINDOWS\system32\drivers\1394ohci.sys You could also likely get away with not using the Macro or DllCall to GetSystemDirectoryA, however using them again just makes things a bit more 'stable' incase the system has some weird/non-standard setup. Yap I totally understand it, and thank you for the suggestion, that is a good point.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now