topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday December 4, 2024, 6:06 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [Win][Suggestions needed] Ensure network shares are connected reliably at login?  (Read 5267 times)

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Hey everyone! (for those who recognize the username, yes, I'm still here now and then)

I'm sure my situation is not unique, but I've tried different suggestions around the net and none have handed my delemma. I have a NAS set up for the better part of a year, have it hooked to my domain, outside access, all that good stuff. However, on the LAN if I don't wait for the network adapter to establish the connection before I enter my credentials, all my local shares appear as disconnected.

Now I've known for years that simply opening up the shares will force Windows to retry the connection - and up until recently, that was an acceptable quirk. However, I'm using the NAS as the storage medium for AMDs new(ish) ReLive. And because it runs at startup, if I don't wait for the network connection before logging in *or* very quickly opening up My PC and forcing Windows to try again, when the driver software launches it will see that the share is disconnected, and disable ReLive (at least, the Instant Replay functionality I'm using the most). And because it's not in my muscle memory, I often forget until something happens that I want to capture - and the ReLive software simply says "Instant Replay Off".

So... Is there a tool that can attempt to reconnect with disconnected shares every half-second or so, running on startup, thereby mitigating the driver software 'try-instantly fail' situation? Free solutions or otherwise (cost within reason), I am just tired of this being an issue that I have to handle myself.

Thanks all (and if there is a separate section of the forum for stuff like this, sorry, I didn't see at a glance)!

-Brandon
« Last Edit: January 06, 2019, 01:18 PM by wreckedcarzz »

KynloStephen66515

  • Animated Giffer in Chief
  • Honorary Member
  • Joined in 2010
  • **
  • Posts: 3,759
    • View Profile
    • Donate to Member
Something like this may work:

https://www.thewindo...tup-programs-windows <----- this site will complain if you have AdBlock, but it's basically a "Startup Program Delay Timer" thing, so Google should help you find an alternative, if needed!

Delay the startup of ReLive by about...5 minutes? (Sufficient time to get other stuff sorted)

Once that is done, create something quick and dirty that will open up on of your shared folders before ReLive tries to establish its connection (set it as a startup task with no delay).

~Stephen

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Use the Task Scheduler to run a script at System Start.

A simple PowerShell or batch file that checks for the existence of the network share, looping every X seconds until it appears.

https://blogs.techne...by-using-powershell/

On my phone atm but something simple like:

Code: PowerShell [Select]
  1. for ($i = 0; $i -lt 100; $i++) {
  2.   if (Test-Path \\nas\folder) {Exit}
  3.   Start-Sleep -seconds 1
  4. }

It'll test for the share every second for 99 seconds, exiting if it exists.
« Last Edit: January 06, 2019, 04:23 PM by 4wd »

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
for ($i = 0; $i -lt 100; $i++) {
  if (Test-Path \\nas\folder) {Exit}
  Start-Sleep -seconds 1
}

It'll test for the share every second for 99 seconds, exiting if it exists.

I know nothing with regards to PS; however, this seems ideal from a simplicity standpoint... but it doesn't seem to do anything to trigger a change in Windows' state of the share. If I run the Test-Path command (with \\NAS\someFolder) manually in PS it does return True (and a bad/non-existent dir returns False, so I know it's actually querying the share)... but Explorer still shows the share as disconnected. :huh:

It's probably something I'm not seeing - some background: I have four shares, all with Windows drive letters (W X Y Z) and they are all on the same machine (so W: is \\NAS\folder, X: is \\NAS\anotherFolder, etc). Would that be handled differently, instead of a share that isn't being mapped..?

Interestingly, if I run Tast-Path on Y:\ (which houses my media collection and where I am pointing ReLive to), while Windows thinks it's disconnected, it returns False. Hmm...

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Sorry, don't know, I've never used mapped drives because the few times I did try them, (back with XP), they've never been as reliable as UNC addressing to the IP.

eg. \\192.168.0.200\folder

Haven't used any program that doesn't understand UNC so it's never been necessary to not use it.

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Maybe it is even smarter to extend the script from 4wd to include:
net use X: \\SERVER\Share

X:           =  drive letter
\\SERVER = computer name or it's IP address. With the IP address, which barely changes in a LAN, no extra subsystem is needed to translate to an IP address. Faster and more reliable.
\Share     = the name of the share

That recreates the share and if the connection already exist it should make Windows mark the connection as active.

You can also go on with it in a blunt matter and remove the connection (net remove X:) every time you turn your system off and as one of the first things in your startup procedure you simply recreate the connection again.

UNC is always preferable, just as 4wd suggested. Much less of a hassle.

Another tip that could make your situation better is the following:
Open Control panel, then open credential manager and add windows credentials for the NAS device (IP address, user name and password). Once such a credential is created Windows will use those immediately instead of trying to make a connection using the credentials of the user account you used to log into Windows itself. Normally this procedure doesn't take much time, but you can shave time off when you create such a credential.

Always remember that TCP/IP are old protocols and that they were designed for unreliable networks. That means a TCP connection can wait for a max of 30 seconds before it marks a connection/session as bad. While that is the extreme, all the times TCP waits does add up and might take you out of the connection window allowed to connect to your share.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
This thread was about a similar problem, there didn't seem to be any resolution regarding mapped drives then either.

But who knows, maybe something in there will work better on 10 than it did on 7.

EDIT: Also this old PoSh script I did might provide some inspiration.

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
So I searched a bit more and came across this, with the 'net use' command mentioned here. With modification, it seems to work, and is quick enough on login to work; again, I don't know much about much beyond single-line shell commands; is this the proper way of doing this? I also had saved the login credentials when I initially set the shares up (not sure if that's separate from the credential manager)..

I'm also still using the machine name over the IP here, and it doesn't *seem* to matter - I have almost 40 devices on my network, but the NAS has a static IP via the router.. (I was using the IP as posts about similar questions said that it was recommended as a solution for this initial issue, but it made no difference in the mapped shares, so I switched back).

@echo off

:Start
timeout /t 1 /nobreak >NUL
if exist W:\ X:\ Y:\ Z:\ NUL goto End
net use W: \\NAS\backups /PERSISTENT:YES
net use X: \\NAS\homes /PERSISTENT:YES
net use Y: \\NAS\media /PERSISTENT:YES
net use Z: \\NAS\temp /PERSISTENT:YES
if ERRORLEVEL 1 goto exit
:End

I imagine there are differences between cmd and ps, and so this doesn't have the retry function/I am in no way skilled with either tool to try and combine them, which is unfortunate, but initial tests seemed to work for me.

Thoughts?

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Something like that:

Code: PowerShell [Select]
  1. $w = $x = $y = $z = $true
  2.  
  3. do {
  4.   if (!(Test-Path W:\)) {
  5.     Start-Process -FilePath "net.exe" -ArgumentList "use W: \\NAS\backups /PERSISTENT:YES" -Wait -WindowStyle Hidden
  6.   } else {
  7.     $w = $false
  8.   }
  9.   if (!(Test-Path X:\)) {
  10.     Start-Process -FilePath "net.exe" -ArgumentList "use W: \\NAS\homes /PERSISTENT:YES" -Wait -WindowStyle Hidden
  11.   } else {
  12.     $x = $false
  13.   }
  14.   if (!(Test-Path Y:\)) {
  15.     Start-Process -FilePath "net.exe" -ArgumentList "use W: \\NAS\media /PERSISTENT:YES" -Wait -WindowStyle Hidden
  16.   } else {
  17.     $y = $false
  18.   }
  19.   if (!(Test-Path Z:\)) {
  20.     Start-Process -FilePath "net.exe" -ArgumentList "use W: \\NAS\temp /PERSISTENT:YES" -Wait -WindowStyle Hidden
  21.   } else {
  22.     $z = $false
  23.   }
  24. } while ($w -or $x -or $y -or $z)

Haven't tested it but the theory is sound  :)
« Last Edit: January 07, 2019, 01:27 AM by 4wd, Reason: for loop boo boo, did a Trump and fired it :) »