detecting windows SMB feature + 1 more
detecting windows SMB feature + 1 more
I am trying to detect windows 10 AND smb 3.0 in freebasic. I understand that windows 8 also uses smb 3.0 HOWEVER I have seen reports that the file locking problem from smb 2.1 still affects windows 8.1.
Basically in order to overcome this silly smb 2.1 and lower bug I have to wait 10 seconds before reading the metadata (date) of a file. If I don't wait long enough the date is wrong (old date before writing to file I guess).
I have also read on this forum that detecting windows version is a mess so I am trying to avoid it. So somehow I have to detect windows 10 and smb 3.0 AND 1 other feature that only windows 10 has. What would be the best one? I don't want users to be bothered with this 10 second delay on windows 10.
Basically in order to overcome this silly smb 2.1 and lower bug I have to wait 10 seconds before reading the metadata (date) of a file. If I don't wait long enough the date is wrong (old date before writing to file I guess).
I have also read on this forum that detecting windows version is a mess so I am trying to avoid it. So somehow I have to detect windows 10 and smb 3.0 AND 1 other feature that only windows 10 has. What would be the best one? I don't want users to be bothered with this 10 second delay on windows 10.
Re: detecting windows SMB feature + 1 more
I've just decided this is overkill for my open source program. I'll just look at an environmental variable. Call it something like smblockdelay. I'll put a warning message in block letters on the console.
Re: detecting windows SMB feature + 1 more
hi,
getting the Windows Version String isn't any magic ... :
getting the Windows Version String isn't any magic ... :
Code: Select all
' GetWindowsVersion.bas -- 2017-06-02, by MrSwiss
Dim As Long fn = FreeFile
Dim As String cmd = "ver", ret
If Open Pipe(cmd For Input As #fn) Then
Var e = Err : Print e ' just in case ...
Else
Line Input #fn, ret ' if first line is 'empty', try second (WIN 10 is empty!)
If Len(ret) = 0 Then Line Input #fn, ret ' get windows version string
If Len(ret) > 0 Then
Print ret : Print ' to screen
Print "'" + cmd + "' successful!"
Else
Print "Couldn't get Windows Version String!"
EndIf
End If
Close fn ' always close open devices/files etc.
Locate CsrLin + 1 : Print "Any key press --> EXIT! ";
Sleep : End
Re: detecting windows SMB feature + 1 more
Thanks MrSwiss that was educational! It even returns the pipe (/current line?) name as "ver" which I wasn't expecting. Except I just coded the environmental variable into my program. If I would have used your method I should ultimately have to also detect that the program is being run from a windows network drive.
Re: detecting windows SMB feature + 1 more
Nope, this is "hard coded", the value of string 'cmd' (see declarations).hooshnik wrote:It even returns the pipe (/current line?) name as "ver" which I wasn't expecting.
Well, you could use ExePath statement, to determine DRIVE:/<Path> ...hooshnik wrote:If I would have used your method I should ultimately have to also detect that the program is being run from a windows network drive.
Re: detecting windows SMB feature + 1 more
Woops I missed that it was hard-coded! I thought you were running the windows "cmd" command lol. It's a bog standard named pipe. I always wondered how to do it in freebasic now I know. :)
Well looking at drive letters is hackish. On my w7 computer drive e is local but on another computer it could be remote. Is that what you mean?
Well looking at drive letters is hackish. On my w7 computer drive e is local but on another computer it could be remote. Is that what you mean?
Re: detecting windows SMB feature + 1 more
Yes, it's one of those things in WIN, that doesn't make live too easy.hooshnik wrote:Well looking at drive letters is hackish. On my w7 computer drive e is local but on another computer it could be remote. Is that what you mean?
I'd check on MSDN, if there is a method to establish, if a drive is local or not.
-
- Posts: 564
- Joined: Sep 27, 2016 18:20
- Location: Valencia, Spain
Re: detecting windows SMB feature + 1 more
> I'd check on MSDN, if there is a method to establish, if a drive is local or not.
GetDriveType
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
GetDriveType
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Re: detecting windows SMB feature + 1 more
Crap. Now I can't use it I think.In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
Server Message Block (SMB) 3.0 protocol: No
Re: detecting windows SMB feature + 1 more
Nope, nothing to do with SMB, you can very well use it. In order to do so:hooshnik wrote:Crap. Now I can't use it I think.
Code: Select all
#Include "windows.bi"
Re: detecting windows SMB feature + 1 more
Are you sure? I think Microsoft is implying that if this is run on a network drive which is using SMB 3.0 with windows 8 it will surely report something like "unknown" making it useless to me.MrSwiss wrote:Nope, nothing to do with SMB
EDIT: I suppose I could trigger on "unknown" + windows 8. Not so fun however.
Re: detecting windows SMB feature + 1 more
hooshnik wrote:Are you sure? I think Microsoft is implying that if this is run on a network drive which is using SMB 3.0 with windows 8 it will surely report something like "unknown" making it useless to me.
This also is not of any interest, within the context.Microsoft wrote:SMB does not support volume management functions.
Since GetDriveType is a "kernel32" call (local DLL), it only makes Drive-Discovery, probably,
without even attempting any communication (SMB).
Even in case it does, it'll most likely, use another mechanism (named pipes or similar).
I don't like it, when people say "no", before they've even tried "something new" out.
-
- Posts: 56
- Joined: Dec 11, 2016 17:22
Re: detecting windows SMB feature + 1 more
The SMB version used will be determined by the lowest Windows OS Client versus Server version.
One way to find it could be by using NetWkstaGetInfo() to retreive those both Client and Server version and then deduct the SMB version that will be used.
SMB version by Jose Barreto
Yours to try :-)
Pierre
One way to find it could be by using NetWkstaGetInfo() to retreive those both Client and Server version and then deduct the SMB version that will be used.
SMB version by Jose Barreto
Yours to try :-)
Pierre
Code: Select all
#Define JumpCompiler "<D:\Free\64\fbc.exe>"
#Define JumpCompilerCmd "<-s gui >"
#Lang "fb"
#Define Unicode
#Include Once "windows.bi"
#Include Once "win\winbase.bi"
#Include Once "win\lmcons.bi"
#define NERR_SUCCESS 0
Type WKSTA_INFO_100
wki100_platform_id As DWORD
wki100_computername As WString Pointer
wki100_langroup As WString Pointer
wki100_ver_major As DWORD
wki100_ver_minor As DWORD
End Type
Declare Function NetWkstaGetInfo Lib "NETAPI32.DLL" Alias "NetWkstaGetInfo" _
(ByVal servername As WString Pointer, ByVal level As DWORD, ByRef bufptr As LPBYTE) As NET_API_STATUS
Declare Function NetApiBufferFree Lib "NetApi32.dll" Alias "NetApiBufferFree" _
(ByVal Buffer As LPVOID ) As NET_API_STATUS
'_____________________________________________________________________________
Dim pInfo100 As WKSTA_INFO_100 Pointer
Dim ComputerNameLen AS DWORD
Dim wsComputerName AS wSTRING * MAX_COMPUTERNAME_LENGTH + 1 '15
Dim wsServerName AS wSTRING * MAX_COMPUTERNAME_LENGTH + 1 '15
Dim ComputerWindowsVer As Double
Dim ServerWindowsVer As Double
Dim WindowLowerVersion As Double
'Get current Windows version
If NetWkstaGetInfo(ByVal NULL, 100, Cast(LPBYTE, pInfo100)) = NERR_Success Then 'Windows 2000 and newer
'MessageBox(HWND_DESKTOP, _
' !"platform_id: \t" & pInfo100->wki100_platform_id & !"\n" & _
' !"computername: \t" & pInfo100->*wki100_computername & !"\n" & _
' !"langroup: \t" & pInfo100->*wki100_langroup & !"\n" & _
' !"ver_major: \t" & pInfo100->wki100_ver_major & !"\n" & _
' !"ver_minor: \t" & pInfo100->wki100_ver_minor & !"\n", _
' !"NetWkstaGetInfo Computer", MB_OK Or MB_TOPMOST)
NetApiBufferFree(pInfo100)
ComputerWindowsVer = pInfo100->wki100_ver_major + pInfo100->wki100_ver_minor / 10
'Get current computer name
ComputerNameLen = MAX_COMPUTERNAME_LENGTH 'Size in characters
GetComputerName(@wsComputerName, Cast(LPDWORD, @ComputerNameLen))
'Set ServerName
wsServerName = "" '<<<<<< Set a valid server name here
IF LEN(wsServerName) = 0 THEN
MessageBox(HWND_DESKTOP, "Please set ""wsServerName"" to a valid server name!", "NetWkstaGetInfo", MB_OK Or MB_TOPMOST)
wsServerName = "MyServerName"
END IF
'wsServerName = wsComputerName 'Use this line for test witj local computer name if no server is available
'Get Windows Server version
If NetWkstaGetInfo(@wsServerName, 100, Cast(LPBYTE, pInfo100)) = NERR_Success Then 'Windows 2000 and newer
'MessageBox(HWND_DESKTOP, _
' !"platform_id: \t" & pInfo100->wki100_platform_id & !"\n" & _
' !"computername: \t" & pInfo100->*wki100_computername & !"\n" & _
' !"langroup: \t" & pInfo100->*wki100_langroup & !"\n" & _
' !"ver_major: \t" & pInfo100->wki100_ver_major & !"\n" & _
' !"ver_minor: \t" & pInfo100->wki100_ver_minor & !"\n", _
' !"NetWkstaGetInfo Server" _
' , MB_OK Or MB_TOPMOST)
NetApiBufferFree(pInfo100)
ServerWindowsVer = pInfo100->wki100_ver_major + pInfo100->wki100_ver_minor / 10
'Get negociation resulting from OS comparaison
IF ServerWindowsVer > ComputerWindowsVer THEN
WindowLowerVersion = ComputerWindowsVer
ELSE
WindowLowerVersion = ServerWindowsVer
End if
'Choose SMB version according to oldest Windows capabitlities
Dim SmbVer As wString * 10
SELECT CASE WindowLowerVersion
Case 10 : SmbVer = "3.1.1" 'Windows 10
Case 6.3 : SmbVer = "3.0.2" 'Windows 8.1
Case 6.2 : SmbVer = "3.0.0" 'Windows 8
Case 6.1 : SmbVer = "2.1.0" 'Windows 7
Case 6.0 : SmbVer = "2.1.0" 'Windows Vista
Case Else : SmbVer = "1.0.0" 'Windows pre-Vista
End Select
MessageBox(HWND_DESKTOP, _
!"WinServer: \t" & wsServerName & " ver. " & ComputerWindowsVer & !"\n" & _
!"Computer: \t" & wsComputerName & " ver. " & ServerWindowsVer & !"\n\n" & _
!"SMB negociated: \t" & SmbVer & !"\n", !"SmbVer", MB_OK Or MB_TOPMOST)
else
MessageBox(HWND_DESKTOP, !"Server: \t" & wsServerName & !" not found! \n", _
!"NetWkstaGetInfo Server", MB_OK Or MB_TOPMOST)
End If
Else
MessageBox(HWND_DESKTOP, "NetWkstaGetInfo failed!", "NetWkstaGetInfo", MB_OK Or MB_TOPMOST)
End If
'To follow Josep suggestion
Dim zDrive AS ZSTRING * 4
Dim sLog AS STRING
Dim lresult AS LONG
Dim Drv AS LONG
sLog = ""
FOR Drv = 65 TO 90 'A ro Z
zDrive = CHR$(Drv) & ":\"
lResult = GetDriveType(zDrive)
SELECT CASE lResult
CASE DRIVE_CDROM
sLog &= zDrive & !" is a cd-rom\n"
CASE DRIVE_FIXED
sLog &= zDrive & !" is a fixed disk\n"
CASE DRIVE_RAMDISK
sLog &= zDrive & !" is a ram disk\n"
CASE DRIVE_REMOTE
sLog &= zDrive & !" iis a remote drive\n"
CASE DRIVE_REMOVABLE
sLog &= zDrive & !" is a removable drive\n"
CASE 0
sLog &= zDrive & !" is an unknown drive type\n"
END SELECT
NEXT
MessageBox(HWND_DESKTOP, sLog, "Remote disk", MB_OK Or MB_TOPMOST)
'_____________________________________________________________________________
'
Re: detecting windows SMB feature + 1 more
I am sorry Pierre Bellisle and MrSwiss. I thank you all of the suggestions and help but I feel I have to discontinue for now. This thing blew up into much more work than I expected. I wish I could make it perfect but this world isn't.MrSwiss wrote: I don't like it, when people say "no", before they've even tried "something new" out.
-
- Posts: 56
- Joined: Dec 11, 2016 17:22
Re: detecting windows SMB feature + 1 more
Hey,
No need to be sorry. ;-)
Easy does it...
Pierre
No need to be sorry. ;-)
Easy does it...
Pierre