A client has a nas box (nas01) and a batch script to connect three drives to it at startup.
net use h: \\nas01\home\Foo /user:Foo bar
net use m: \\nas01\music /user:Foo bar
net use p: \\nas01\media /user:Foo bar
From windows Explorer clicking on M and H drive gets him into the folders. P drive fails with a cross through it.
I opened a command prompt (cmd) as administrator (right click run as administrator) and ran the batch.
It succeeded under CMD.
It failed to let the user in under Windows Explorer.
I used net use * /delete from the CMD prompt then ran the following line manually.
net use p: \\nas01\media /user:Foo bar
In cmd I can do a dir p: and see the files, I can change to p: drive, change folders and see sub folders and files. From Windows Explorer it get Nada.
A manual disconnect for each drive then re map of drives under windows explorer fixed the issue - all four drives accessible, but it leaves me with a batch file my client cant use when Windows drops the mapped drives again in the future.
Why is one side of windows (CMD) working but not useable under Windows Explorer? Any thoughts.
User has full admin rights on PC, local login, no UAC getting in the way.
Related
I need advice.
I run a script on my computer that copies the files to the network drive. Periodically, it turns on via the task scheduler.
But it happens that after a reboot the network drive does not connect - even though when I set it up I checked "reconnect at login". (Usually I just double-click on the drive and it reconnects). But if I don't do this, the script can't put it anywhere because the disk doesn't seem to be there.
I tried:
turning off fast booting,
put a batch file in the folder after boot:
#echo Create new Y: drive mapping
net use Y: \\server\folder
:exit
put another batch file in the "after boot" folder
#echo off
:Start
timeout /t 5 /nobreak >NUL
if exist Y:\NUL goto End
net use Y: \\server\folder /USER:domain\user password /PERSISTENT:YES
if ERRORLEVEL 1 goto Start
:End
But neither solved the problem.
I had exactly this problem some days ago.
The solution I used was nothing really professional, but it worked.
I just created a textfile via powershell within the networkfolder.
Everytime I now restart my PC it just writes the newest date in this txt.
I know its not perfect, but it works.
New-Item \\Server\Folder\RecentLogin.txt
$var_date = Get-Date
Set-Content \\Server\Folder\RecentLogin.txt "$var_date"
Ensure that fast boot is disabled.
Go to the Device Manager -> Network adapters -> Properties of your network adapter
Under "Power Management" disable "Allow the Computer to Turn Off This Device to Save Power"
Under "Advanced" set "Wait for Link" to "On"
Go to Group Policies (execute gpedit.msc) -> Computer Configuration -> Administrative Templates -> System -> Logon and enable "Always Wait for the Network at Computer Startup and Logon".
Add the following values to your registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLinkedConnections"=dword:00000001
"LocalAccountTokenFilterPolicy"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"GpNetworkStartTimeoutPolicyValue"=dword:0000003c
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider]
"RestoreConnection"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache]
"Start"=dword:00000002
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters]
"Autodisconnect"=dword:ffffffff
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer]
"LocalKnownFoldersMigrated"=dword:00000001
Remove the following registry entries, if they exist (where "X" is the letter of your connected network drive):
[HKEY_CURRENT_USER\Network\X]
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU]
"a"="\Server\Path"
"MRUList"="a"
Reboot
Map your network drive manually:
open the File Explorer, right click on "This PC" and select "Map network drive"
use the IP instead of the DNS name (e.g. \\192.168.0.10\MyShare) and activate "Reconnect at sign-in"
Add the following value to the corresponding registry key (where "X" is the letter of your connected network drive)
[HKEY_CURRENT_USER\Network\X]
"ProviderFlags"=dword:00000001
Optionally: Delay any existing tasks which access the network drive to about 10 seconds.
Reboot and check if everything works as expected. The status of net use (shell command) should say "OK".
I am running a Lua program on a Windows 10 machine. This Windows 10 computer is networked to another Windows 10 computer and this other computer is sharing its D: drive with my computer. The shared drive is called the O: drive by my computer.
When I open a cmd window on my computer and type:
type "O:\Data\config\file.xml"
I get the contents of file.xml in my cmd window. However, if I run this same command through Lua:
f = io.popen([["type O:\Data\config\file.xml"]])
output = f:read("*l")
Then output returns as nil.
This behavior is true of any command involving the shared O: drive, not just type. Similarly, I have some bat scripts that reference the O: drive, and I call these using os.execute, but they are not able to accomplish their task (I can see they are actually executing, just not correctly). However, if I run similar commands or scripts with the local D: or C: drives, I do not have this issue.
Any ideas as to what could be different between these two calls? Is there a different way I can call the O: drive?
My Lua application was running as a service, and I determined that when it was running as a service it was running as a 'guest' user, rather than my system user. Therefore, it did not have the appropriate permissions to run.
I modified my Windows service to run as my specific user, and this resolved the issue.
On Windows 10.
Steps to reproduce problem.
1) Use subst from command line to setup a drive letter. e.g.: subst v: c:\temp
2) Create a batch file c:\temp\hello.bat:
echo hello
pause
3) in windows explorer, go to v: drive.
Try to run hello.bat by right clicking, and selecting Run As Administrator.
The expected Windows security question "Do you want to allow this app to make changes to your device?" comes up. When you answer Yes, nothing seems to happen.
I know I can go to c:\temp in Windows Explorer, and this will work, but it's not ideal.
I gather it is something to do with Run As Administrator context not being able to see the subst drive?
Are there any workarounds, to be able to get this to work? So that batch files can be run in Windows Explorer on the subst drive as Administrator.
EDIT:
A workaround of sorts:
In Windows Explorer, go to c: drive. Then c:\temp. Create a shortcut to hello.bat. Also tick the Run as Administrator option.
In Windows Explorer, go back to v: drive. Double click the shortcut to run hello.bat as administrator. This seems to work.
Mods: feel free to move this question to Superuser, if it turns out there is nothing you can do in the batch file itself to make this work.
I am trying to map a drive with an elevated batch file but any attempt to use the Net Use command fails. The error is always: "The system cannot find the drive specified."
I am using the following code: Net Use w: "\Server\Folder"
It works fine with an elevated command prompt or with a non-elevated batch file.
I also tried simply: Net Use
Yet with an elevated batch file even that fails with the same error message.
net use DrvLetter: \\server\sharename[\foldername]
so
net use m: \\serenity\C$
Note UNC paths start \\
or for any computer this will work to the admin share called C$. $ means it's a hidden share. Every drive has one (ie D$, E$, ..., Z$) + there is Admin$ (C:\windows), IPC$, and Printer$ (your printer driver folder).
net use m: \\%computername%\C$
Now it's mapped to \\192.168.248.128,how to change it to \\192.168.66.2 instead?
If you want to use the command line have a look to the next answer below!
But you can also edit the settings in Windows Registry: 'HKEY_CURRENT_USER\Network\[Drive letter]'
When you now open a new 'My Computer' window - after changing the target in registry - you will likely see the old settings, but that is only a visual problem. Try to open the entry, and it should work!
Have a look to Chris Budys interesting comment below, that fixes obviously the visual problem.
net use can modify a drive in place without deleting and recreating. You simply execute the command as if you're mapping a new drive, and it replaces it instead. The command syntax is:
net use [Drive name] [UNC path]
Example:
C:\> net use U: \\192.168.66.2
U: has a remembered connection to \\192.168.248.128. Do you
want to overwrite the remembered connection? (Y/N) [Y]: y
The command completed successfully.
You can create another mapped network drive:
right-click the current drive and click "Disconnect"
right-click "Computer" and select Map Network Drive
configure the new drive
If you want Windows API you can use WNetAddConnection2.
If you want a BAT (command line) you can try net use command line option.