Sandy S
Sandy S

Reputation: 11

NSIS script not able to find the file from Windir folder

IfFileExists $windir\system32\drivers\pcitdrv.sys file_found file_not_found
file_found:
MessageBox MB_OK FileFound
file_not_found:
MessageBox MB_OK FileNotFound

This code always executing file_not_found portion of code even though the that file exists in respective path.

Also tried the below way:

Function AB
Var /GLOBAL OnlineOrOffline
${Locate} "$windir\system32\drivers\" "/L=F /M=pcitdrv.sys" "SetOnlineOfflineVarliable"
MessageBox MB_OK $OnlineOrOffline
FunctionEnd

Function SetOnlineOfflineVarliable
StrCpy $R0 $R9
StrCpy $OnlineOrOffline "Found"
StrCpy $0 StopLocate
Push $0
FunctionEnd

In this scenario also the callback function is not called.

Need help regarding this.

Or simply

My requirement is suppose a PC with $windir/system32/drivers/pcitdrv.sys file present and another PC is not having that file. During installation, there is a check for some license. Can we skip the license check based on the file presence?

Upvotes: 0

Views: 717

Answers (2)

Sandy S
Sandy S

Reputation: 11

One more doubt is actually
${DisableX64FSRedirection}
StrCpy $0 ""
IfFileExists "$windir\system32\drivers\pcitdrv.sys" 0 +2
StrCpy $0 "1"
${EnableX64FSRedirection}
StrCmp $0 "" 0 file_found
${DisableX64FSRedirection}
StrCpy $0 ""
IfFileExists "$windir\system32\drivers\tcitdrv.sys" 0 +2
StrCpy $0 "1"
${EnableX64FSRedirection}
StrCmp $0 "" 0 file_found
goto done
file_found:

done:
I would like to check two files pcit and tcit.
Is this correct?

Upvotes: 0

Anders
Anders

Reputation: 101569

Parts of the filesystem is redirected when running on a 32-bit application on a 64-bit version of Windows.

$windir\system32 is redirected to $windir\SysWOW64.

You can turn off the redirection when performing the check:

!include x64.nsh
Section

${DisableX64FSRedirection}
StrCpy $0 ""
IfFileExists "$windir\system32\drivers\pcitdrv.sys" 0 +2
StrCpy $0 "1"
${EnableX64FSRedirection}

StrCmp $0 "" 0 file_found
MessageBox MB_OK FileNotFound
goto done
file_found:
MessageBox MB_OK FileFound
done:

SectionEnd

If you don't care about Windows XP 64-bit support you can use a special pseudo folder that always accesses the "real" system32 folder:

Section

IfFileExists "$windir\system32\drivers\pcitdrv.sys" file_found ; Check on 32-bit Windows
IfFileExists "$windir\sysnative\drivers\pcitdrv.sys" file_found ; Check on 64-bit Windows

MessageBox MB_OK FileNotFound
goto done
file_found:
MessageBox MB_OK FileFound
done:

SectionEnd 

Upvotes: 1

Related Questions